Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation on Windows with Kuando #56

Open
Klauz123 opened this issue Jun 12, 2021 · 12 comments
Open

Installation on Windows with Kuando #56

Klauz123 opened this issue Jun 12, 2021 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@Klauz123
Copy link

Hi there,

i am new to python and i am having a tough time working with the kuando light on windows. On mac everything was fine.
I tried to test with following code:
from busylight.lights.kuando import BusyLight
light = BusyLight.first_light()
light.on((255, 0, 0))
I get the following result:
Traceback (most recent call last): File "C:\Users\MyPC\Desktop\Python\test.py", line 4, in <module> light.on((255, 0, 0)) File "C:\Users\MyPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\busylight\lights\kuando\busylight.py", line 49, in on self.state.line0 = instruction.value File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 124, in __exit__ next(self.gen) File "C:\Users\MyPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\busylight\lights\usblight.py", line 412, in batch_update self.update() File "C:\Users\MyPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\busylight\lights\usblight.py", line 507, in update raise USBLightIOError(f"write returned {nbytes}") busylight.lights.exceptions.USBLightIOError: write returned 65

Does anyone have any idea what I am doing wrong?``

@JnyJny JnyJny self-assigned this Jun 12, 2021
@JnyJny JnyJny added the bug Something isn't working label Jun 12, 2021
@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

As you might guess, I develop on Mac and test on Linux but have never actually tested on Windows. The Kuando Busylight control packet is 64 bytes long and 65 bytes were written. This could be a one-off bug in my code or some sort of Windows-specific interaction that I hadn't anticipated. I don't think this is a problem caused by you doing something wrong. I'll investigate and see what I can figured out.

@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

If you could describe to me how you installed busylight-for-humans on Windows that would be an enormous help to me.

@Klauz123
Copy link
Author

Ofcourse!
I had almost a fresh installation of Windows 10. I installed python via the windows store and installed the busylight-for-humans package via
python -m pip install busylight-for-humans

after that i created a test.py file with the above code.

@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

Awesome. I have been able to replicate the error you reported. I suspect that it's because libusb isn't installed ( it's not installed on my Windows either ). Investigating further. If anything, busylight should have failed sooner than that with a better message.

@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

Poking around some more, missing libusb doesn't seem to be the problem. Which is great because debugging this is frustrating enough :) It looks like Windows may be a little more picky about the control packet written to the device, but may be an easy fix. Stand by.

@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

And no, I was not so lucky. It appears that the Kuando Busylight keepalive_thread is dying and restarting in an epically bad way. Possibly a permissions problem, possibly a bad assumption with respect to threads, or something else. Could you reply back with the output of:

$ busylight -D list

You'll probably need to kill the script, dependent on what Windows shell technology you're using (Control-C in cmd worked for me).

@Klauz123
Copy link
Author

Uhm, could you explain to me how I can set up the cmd.exe commands in windows for busylight? I haven't figured it out... If i type busylight the response show that the command is unknown.

Like i said - I'm new :-D

@JnyJny
Copy link
Owner

JnyJny commented Jun 12, 2021

Likely your PATH variable doesn't include the filesystem path to your python executable. I was bit by exactly the same thing which led to a frustrating several hours of futzing with Windows. My solution to the problem was:

  1. In Settings, uninstall the Python package from the Microsoft Store
  2. Go to https://python.org, hover over the Download tab and click the Download button.
  3. After it downloads, click "Open file" in the Downloads drop down menu.
  4. Install Python and click the option to add the python executable to the system PATH environment variable.

After I did this, I was able to start a cmd terminal and run python:

C:\Users\ejo\local\busylight> python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 

After getting python to run from a prompt, you will likely need to re-install busylight:

C:\Users\ejo\local\busylight> python -m pip install busylight-for-humans
...

Assuming that completes successfully, you can then run the busylight command-line tool using:

C:\Users\ejo\local\busylight> busylight --help
...

I was hoping to see if your debug output matches mine for:

c:\Users\ejo\local\busylight> busylight -D list
...

@JnyJny
Copy link
Owner

JnyJny commented Jun 13, 2021

So I’ve root caused the problem; I assumed that a HID USB device could only be opened successfully one time (exclusive open). This is true for macOS and Linux but not true for Windows. The entire light discovery mechanism depends on this assumption unfortunately. I’ll need to re-think how I manage devices to make things work on Windows. Sorry if this doesn’t make sense, I’m hoping to have a solution for this pretty quick now that I understand the problem.

@Klauz123
Copy link
Author

You are awesome! Thank you!

@henryruhs
Copy link
Contributor

henryruhs commented Jun 27, 2021

@JnyJny Hey Erik,

I experienced a problem with ALL busylight powered devices in my project. Even a busylight list does not seem to be possible and hangs the command line totally.

See verbose log: verbose-log.txt

@JnyJny
Copy link
Owner

JnyJny commented Jun 29, 2021

Fixing this problem on Windows will require some re-architecting of the USBLight class which I do not have time for right now, but will do at some point in the future. In the meantime, the README will be updated to indicate that BusyLight does not work on Windows right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants