Hi,
this error appears very seldom (2-3 times per month) but still causes some problems. We have to reboot whole system to get rid of that. Is there a way to recover from this kind of situation? Is reset, hard or soft, a way to go? If we run same code again, the problem persists, so it won't recover by itself. Below is problematic piece of code, previously those pins were set to LOW so it just wants to set them again to LOW.
from labjack import u3
d = u3.U3()
for pin in (18, 19):
d.getFeedback(u3.BitStateWrite(pin, False))
Output from the logs:
Got incorrect command bytes
Expected: [0xf8]
Got: [0x0]
Full packet: [0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x29, 0xf8, 0xd, 0x77]
Got incorrect command bytes
Expected: [0xf8]
Got: [0x0]
Full packet: [0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
--
Best regards,
Luke
A U3 power cycle (device reset or USB disconnect/reconnect) should help if for some reason the U3 can no longer communicate over USB. Afterwards the device will need to be reopened in your code if on Mac or Linux. If USB communications are lost, you cannot send the U3 command to reset.
The U3 has a Watchdog feature for cases like this. You configure a timeout period for USB communications. If there are no communications within that timeout period, the device will reset if configured to do so.
In Python, use the watchdog method to configure it. For Python doc, use the help function:
import u3
help(u3.U3.watchdog)
The User's Guide (Datasheet) section mentioned in the Python doc. is here:
https://labjack.com/support/datasheets/u3/low-level-function-reference/w...
Note that the timeout period is in seconds. Watchdog settings are stored on the U3's flash memory and only needs to be set once.
It's possible to send commands but after first error we're always receiving:
Got incorrect command bytes
exception. Is this indication that U3 can no longer communicate over USB or will I get different exception if USB communication is lost?
Looking at your first post again, those response bytes are not valid causing that error. There could be USB packet corruption or missing bytes going on here as I would expect a different error about writing/receiving 0 bytes after an initial error of invalid bytes error if communications were lost, or on Windows a device was disconnected error.
Make sure you are running the latest U3 firmware, currently release version 1.46:
https://labjack.com/support/firmware
https://labjack.com/support/firmware/u3
USB connection wise, try a different USB cable and USB port in case they are not stable.
Codewise, you will want to detect when you are in the "Got incorrect command bytes" state (it repeatedly happening), stop U3 commands and close the device, wait and let the Watchdog perform the U3 reset, reconnect to the U3 and continue operations again. So say the Watchdog is 10 seconds, stop communications and close the device, and then try reconnecting in about 18 seconds or so.