From 0ed099d8956ca2c9f790929725443612594afae6 Mon Sep 17 00:00:00 2001 From: Soloman J Date: Thu, 29 Feb 2024 15:28:39 -0700 Subject: [PATCH] ctypes.c_byte to ctypes.c_ubyte fix ctypes.c_byte is specified to be equivalent to a signed char (-128 to 127) but we were passing unsigned char values (0-255) so we should be using ctypes.c_ubyte. --- ChangeLog.txt | 2 ++ setup.py | 2 +- src/LabJackPython.py | 12 ++++++------ src/u12.py | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 03f0bc6..4532aef 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -345,3 +345,5 @@ Version History - 2.2.0 - Added an optional loadCalibration parameter to the device open functions. The open functions will now call getCalibrationData() by default. +- 2.2.1 + - Fixed issue where ctypes.c_byte was used instead of ctypes.c_ubyte. diff --git a/setup.py b/setup.py index 36b1780..86a3037 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ ] setup(name='LabJackPython', - version='2.2.0', + version='2.2.1', description='The LabJack Python modules for the LabJack U3, U6, UE9 and U12.', license='MIT X11', url='https://labjack.com/support/software/examples/ud/labjackpython', diff --git a/src/LabJackPython.py b/src/LabJackPython.py index c6f2d30..97d21c6 100644 --- a/src/LabJackPython.py +++ b/src/LabJackPython.py @@ -26,7 +26,7 @@ import Modbus -LABJACKPYTHON_VERSION = "2.2.0" +LABJACKPYTHON_VERSION = "2.2.1" __version__ = LABJACKPYTHON_VERSION SOCKET_TIMEOUT = 3 @@ -249,9 +249,9 @@ def _writeToExodriver(self, writeBuffer, modbus): if modbus is True and self.modbusPrependZeros: writeBuffer = [ 0, 0 ] + writeBuffer - newA = (ctypes.c_byte*len(writeBuffer))(0) + newA = (ctypes.c_ubyte*len(writeBuffer))(0) for i in range(len(writeBuffer)): - newA[i] = ctypes.c_byte(writeBuffer[i]) + newA[i] = ctypes.c_ubyte(writeBuffer[i]) writeBytes = staticLib.LJUSB_Write(self.handle, ctypes.byref(newA), len(writeBuffer)) @@ -371,7 +371,7 @@ def _readFromUE9TCPHandle(self, numBytes, stream, modbus): return list(rcvDataBuff) def _readFromExodriver(self, numBytes, stream, modbus): - newA = (ctypes.c_byte*numBytes)() + newA = (ctypes.c_ubyte*numBytes)() if stream: readBytes = staticLib.LJUSB_StreamTO(self.handle, ctypes.byref(newA), numBytes, 1500) @@ -1824,9 +1824,9 @@ def eGetRaw(Handle, IOType, Channel, pValue, x1): #Initialize newA newA = None if type(x1[0]) == int: - newA = (ctypes.c_byte*len(x1))() + newA = (ctypes.c_ubyte*len(x1))() for i in range(len(x1)): - newA[i] = ctypes.c_byte(x1[i]) + newA[i] = ctypes.c_ubyte(x1[i]) else: x1Type = "float" newA = (ctypes.c_double*len(x1))() diff --git a/src/u12.py b/src/u12.py index f8a5143..3afe4ed 100644 --- a/src/u12.py +++ b/src/u12.py @@ -552,9 +552,9 @@ def write(self, writeBuffer): raise U12Exception("The U12's handle is None. Please open a U12 with open().") self._debugprint("Writing: " + hexWithoutQuotes(writeBuffer)) - newA = (ctypes.c_byte*len(writeBuffer))(0) + newA = (ctypes.c_ubyte*len(writeBuffer))(0) for i in range(len(writeBuffer)): - newA[i] = ctypes.c_byte(writeBuffer[i]) + newA[i] = ctypes.c_ubyte(writeBuffer[i]) writeBytes = staticLib.LJUSB_Write(self.handle, ctypes.byref(newA), len(writeBuffer)) @@ -569,7 +569,7 @@ def read(self, numBytes=8, timeout=1000): else: if self.handle is None: raise U12Exception("The U12's handle is None. Please open a U12 with open().") - newA = (ctypes.c_byte*numBytes)() + newA = (ctypes.c_ubyte*numBytes)() readBytes = staticLib.LJUSB_ReadTO(self.handle, ctypes.byref(newA), numBytes, timeout) # Return a list of integers in command-response mode result = [(newA[i] & 0xff) for i in range(readBytes)]