Fix ads integration after 0.113 (#38402)
This commit is contained in:
parent
79055487ed
commit
0136c565eb
3 changed files with 15 additions and 9 deletions
|
@ -230,7 +230,13 @@ class AdsHub:
|
|||
|
||||
hnotify = int(contents.hNotification)
|
||||
_LOGGER.debug("Received notification %d", hnotify)
|
||||
data = contents.data
|
||||
|
||||
# get dynamically sized data array
|
||||
data_size = contents.cbSampleSize
|
||||
data = (ctypes.c_ubyte * data_size).from_address(
|
||||
ctypes.addressof(contents)
|
||||
+ pyads.structs.SAdsNotificationHeader.data.offset
|
||||
)
|
||||
|
||||
try:
|
||||
with self._lock:
|
||||
|
@ -241,17 +247,17 @@ class AdsHub:
|
|||
|
||||
# Parse data to desired datatype
|
||||
if notification_item.plc_datatype == self.PLCTYPE_BOOL:
|
||||
value = bool(struct.unpack("<?", bytearray(data)[:1])[0])
|
||||
value = bool(struct.unpack("<?", bytearray(data))[0])
|
||||
elif notification_item.plc_datatype == self.PLCTYPE_INT:
|
||||
value = struct.unpack("<h", bytearray(data)[:2])[0]
|
||||
value = struct.unpack("<h", bytearray(data))[0]
|
||||
elif notification_item.plc_datatype == self.PLCTYPE_BYTE:
|
||||
value = struct.unpack("<B", bytearray(data)[:1])[0]
|
||||
value = struct.unpack("<B", bytearray(data))[0]
|
||||
elif notification_item.plc_datatype == self.PLCTYPE_UINT:
|
||||
value = struct.unpack("<H", bytearray(data)[:2])[0]
|
||||
value = struct.unpack("<H", bytearray(data))[0]
|
||||
elif notification_item.plc_datatype == self.PLCTYPE_DINT:
|
||||
value = struct.unpack("<i", bytearray(data)[:4])[0]
|
||||
value = struct.unpack("<i", bytearray(data))[0]
|
||||
elif notification_item.plc_datatype == self.PLCTYPE_UDINT:
|
||||
value = struct.unpack("<I", bytearray(data)[:4])[0]
|
||||
value = struct.unpack("<I", bytearray(data))[0]
|
||||
else:
|
||||
value = bytearray(data)
|
||||
_LOGGER.warning("No callback available for this datatype")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue