In the Python opto MMP protocol code in the init.py the range function at line 254 expects an int, dividing my hex values length at the moment gives a float of 2.5 which causes an error. Also, the “hexvals” operation at line 256 requires an int but it is fed “i + (4 - len(value) / 2)” which may be a float. I am still trying to understand what this code needed to accomplish but if any knows what should be done to fix this code please share your knowledge. I am using python 3.
I am calling “self.grv_epic.SetScratchPadIntegerArea(<my_index>, <my_value>)” which works until I send a value greater than 255 which appears to cause the first if statement in the code above to execute.
Looks complicated. Without using a library, couldn’t this function be reduced to this:
def PackInteger(self, value):
hexvals = [0,0,0,0] #init a byte array
for i in range(3, -1, -1): #loop through 3, 2, 1, 0
hexvals[i] = value & 0x0FF; #bitand to get the least significant byte
value = value >> 8; #shift the value over by a byte