Skip to content

Commit

Permalink
Merge pull request #127 from GullinBustin/master
Browse files Browse the repository at this point in the history
Raise WkcError in sdo_write and sdo_read when working counter is not …
  • Loading branch information
bnjmnp authored Feb 3, 2024
2 parents 23ef331 + c7829fd commit b37e2bd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pysoem/pysoem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,12 @@ class WkcError(Exception):
Attributes:
message (str): error message
wkc (int): Working counter
"""

def __init__(self, message=None):
def __init__(self, message=None, wkc=None):
self.message = message
self.wkc = wkc


cdef class _CallbackData:
Expand Down Expand Up @@ -655,6 +657,7 @@ cdef class CdefSlave:
SdoError: if write fails, the exception includes the SDO abort code
MailboxError: on errors in the mailbox protocol
PacketError: on packet level error
WkcError: if working counter is not higher than 0, the exception includes the working counter
"""
if self._ecx_contextt == NULL:
raise UnboundLocalError()
Expand Down Expand Up @@ -682,6 +685,11 @@ cdef class CdefSlave:
assert err.Slave == self._pos
self._raise_exception(&err)

if not result > 0:
if pbuf != std_buffer:
PyMem_Free(pbuf)
raise WkcError(wkc=result)

try:
return PyBytes_FromStringAndSize(<char*>pbuf, size_inout)
finally:
Expand All @@ -701,6 +709,7 @@ cdef class CdefSlave:
SdoError: if write fails, the exception includes the SDO abort code
MailboxError: on errors in the mailbox protocol
PacketError: on packet level error
WkcError: if working counter is not higher than 0, the exception includes the working counter
"""
cdef int size = len(data)
cdef int result = cpysoem.ecx_SDOwrite(self._ecx_contextt, self._pos, index, subindex, ca,
Expand All @@ -710,6 +719,9 @@ cdef class CdefSlave:
if cpysoem.ecx_poperror(self._ecx_contextt, &err):
self._raise_exception(&err)

if not result > 0:
raise WkcError(wkc=result)

def mbx_receive(self):
"""Read out the slaves out mailbox - to check for emergency messages.
Expand Down

0 comments on commit b37e2bd

Please sign in to comment.