JnyJny / busylight

Control USB connected presence lights from multiple vendors via the command-line or web API.
Apache License 2.0
214 stars 25 forks source link

[BUG] fit-statUSB unexpectedly stops working after executing 144 commands #200

Closed leungmanhin closed 1 year ago

leungmanhin commented 1 year ago

Software Versions:

General Type of Problem

Describe the Problem When using the Python API with a fit-statUSB, it consistently stops working after executing 144 on/off commands, and can be reproduced by using the below script. I'll need to unplug & plug it back in order to get it to work again. And this doesn't happen if I use the command-line API.

import time
from busylight.lights.compulab import Fit_StatUSB

light = Fit_StatUSB.first_light()
print(light, 'is ready!')

cnt = 1
while True:
  if cnt % 2 == 1:
    light.on((255, 255, 255))
    print(cnt, '- on')
  else:
    light.off()
    print(cnt, '- off')
  cnt += 1
  time.sleep(0.1)

Expected Behavior It should continue to work regardless.

Error Output It consistently stops after 144 commands, an example output by using the script above (showing only the last few lines of it):

2022-10-25 13:41:04.758 | INFO     | busylight.lights.light:exclusive_access:529 - Entering exclusive access for fit-statUSB
2022-10-25 13:41:04.758 | INFO     | busylight.lights.light:update:557 - data:9 = b'B#000000\n' wrote 9
2022-10-25 13:41:04.758 | INFO     | busylight.lights.light:exclusive_access:543 - Exiting exclusive access for fit-statUSB
142 - off
2022-10-25 13:41:04.858 | INFO     | busylight.lights.light:exclusive_access:529 - Entering exclusive access for fit-statUSB
2022-10-25 13:41:04.858 | INFO     | busylight.lights.light:update:557 - data:9 = b'B#ffffff\n' wrote 9
2022-10-25 13:41:04.859 | INFO     | busylight.lights.light:exclusive_access:543 - Exiting exclusive access for fit-statUSB
143 - on
2022-10-25 13:41:04.959 | INFO     | busylight.lights.light:exclusive_access:529 - Entering exclusive access for fit-statUSB
2022-10-25 13:41:04.959 | INFO     | busylight.lights.light:update:557 - data:9 = b'B#000000\n' wrote 9
2022-10-25 13:41:04.959 | INFO     | busylight.lights.light:exclusive_access:543 - Exiting exclusive access for fit-statUSB
144 - off
2022-10-25 13:41:05.060 | INFO     | busylight.lights.light:exclusive_access:529 - Entering exclusive access for fit-statUSB

and it just get stuck here.

JnyJny commented 1 year ago

I could not replicate the behavior on MacOS. Using the supplied test case, I finally stopped the test after 30k command. I don't have an Ubuntu installation to test on. Given the debugging output, my guess is the write never returns which could indicate an OS bug, a serial driver bug, or a PySerial bug.