Dear all,
In Psychopy (a Python-based software), we are trying to set the sate of a channel to high using the command:
lj.setFIOState(Channel,1)
(we imported u3 before using lj = u3.U3())
Here, "Chennel" is a variable that we read from some other files.
We got the error message:
lj.setFIOState(Channel,1)
File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\u3.py", line 488, in setFIOState
self.getFeedback(BitDirWrite(fioNum, 1), BitStateWrite(fioNum, state))
File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\u3.py", line 786, in getFeedback
self._checkCommandBytes(rcvBuffer, [0xF8])
File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\LabJackPython.py", line 539, in _checkCommandBytes
raise LabJackException("Got incorrect command bytes.\nExpected: %s\nGot: %s\nFull packet: %s" % (hexWithoutQuotes(commandBytes), hexWithoutQuotes(results[1:(size+1)]), hexWithoutQuotes(results)))
LabJackPython.LabJackException: Got incorrect command bytes.
Expected: [0xf8]
Got: [0x0]
Full packet: [0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x80, 0x1
When we use this command instead: lj.setFIOState(1,1)
where we specify the channel number directly, we don't get the error message and everything is normal.
Next, We used print(Channel) and print(type(Channel)) to see if it's a problem about the variable, but the variable "Channel" turns out to be a proper integer 1, which is basically the same thing as directly specifying it.
This problem feels very mysterious...Could someone help us?
In my simple tests I have not been able to reproduce your error when using a variable with setFIOState, and if the variable isn't an integer there should be other errors relating to data types before command-response communications are performed. Also, the response packet bytes from the error is an invalid U3 response.
For testing, do you get the error with something like this when Channel is set right before the call?
Channel = 1
lj.setFIOState(Channel, 1)
Also, you may want to power cycle your device before doing your variable test again considering the unknown packet response.
Thanks a lot for your help. I tried testing it this way, as you mentioned:
Channel = 1
lj.setFIOState(Channel, 1)
Where I specified the variable mannually right before using it. This way, we don't get the error message. The error message only occurs when the variable is read from an excel file through psychopy.
However, when I print the type and value of the variable, no matter it's read from excel or specified directly, it all shows "integer" and a value of "1".
Do you have any thoughts on what might be causing this?
I am unsure what is causing this so far. For troubleshooting this more:
1. In your code, try something like this for displaying Channel information:
print(type(Channel))
print(Channel)
lj.setFIOState(Channel, 1)
Provide the output of those prints. This is to see what Channel is immediately before your erroring setFIOState call, and if that differs from your other print information that may be in a different location in your code.
2. Does type casting Channel to an int before the setFIOState call prevent the error:
Channel = int(Channel)
lj.setFIOState(Channel, 1)
Thanks a lot for your help. The problem has been solved by forcing the variable to be int right before the setFIOState, as you mentioned:
Channel = int(Channel)
lj.setFIOState(Channel, 1)
Thanks again for the fantastic support.