• DepthAI
  • I GOT depthai DEMO TO RUN IN WSL!!!!!!!

The clue came from reading about the trickery required to run it in VirtualBox...the camera disappears and re-appears as a different device after it is rebooted by the program...

I opened a PowerShell window as admin and another PowerShell as admin and started WSL in the second window (may not require admin for the WSL window, but MUST be admin for the PowerShell window to attach the USB device or you will get an error).

Both windows must be left open.

Before starting the demo (and causing camera reboot), the camera showed up with ID 2-4 using usbipd wsl list , so before running the depthai demo in PowerShell, I attached the device to Ubuntu:

usbipd wsl attach --busid 2-4
I started the demo in the WSL window and then switched quickly to the PowerShell (without WSL) and used usbipd wsl list repeatedly...after the camera rebooted it changed to:

2-20 03e7:f63b Luxonis Device
So immediately after starting the demo program, I quickly switched to the non WSL PowerShell and repeatedly executed:

usbipd wsl attach --busid 2-20
This failed several times while the camera was rebooting, and then succeeded when the camera reappeared as a different device.

Note that the BUSID numbers 2-4 and 2-20 will change from time to time, but seem to be consistent during any single PowerShell / WSL session.

This requires a bit of fast switching between windows. I already had usbipd wsl attach --busid 2-20 typed into the PowerShell window and ready to execute repeatedly.

Now to write a batch script that somehow automates this entire process in the PowerShell side...

I did a little testing with Python...looks like it can run in PowerShell and call the necessary commands to automate this...I will finish it out tomorrow...

#!/usr/bin/python3.8 -u

import os

stream = os.popen('usbipd wsl list')
output = stream.read()
print(output)

print("")

~ todo mks ~ replace 1-4 with busid retrieved above for the Luxonis device

stream = os.popen('usbipd wsl attach --busid 1-4')
output = stream.read()
print(output)

~ todo mks ~ loop here watching for new unattached Luxonis device and attaching it when it appears

  • erik replied to this.
    a month later

    SpudTheBot I got it to work with script below. Note that you need to run it in terminal that was run as Admin

    #!/usr/bin/python3.8 -u
    
    import time
    import os
    
    while True:
        output = os.popen('usbipd wsl list').read()
        rows = output.split('\n')
        for row in rows:
            if ('Movidius MyriadX' in row or 'Luxonis Device' in row) and 'Not attached' in row:
                busid = row.split(' ')[0]
                out = os.popen(f'usbipd wsl attach --busid {busid}').read()
                print(out)
                print(f'Usbipd attached Myriad X on bus {busid}')
        time.sleep(.5)
      2 years later

      erik I have been greatly helped by the script.
      I'm Japanese, and after making some modifications to the script to accommodate the slightly different environment, the program ran successfully.

      The errors that occurred before the modifications were made were...
      ・'cp932' codec can't decode byte 0x86 in position 215: illegal multibyte sequence
      ・RuntimeError: Failed to find device after booting, error message: X_LINK_DEVICE_NOT_FOUND

      The script after the modifications is...

      import time
      import subprocess
      while True:
          output = subprocess.run('usbipd list',capture_output=True,encoding="UTF-8")
          rows = output.stdout.split('\n')    for row in rows:
              if ('Movidius MyriadX' in row or 'Luxonis Device' in row) and 'Not shared' in row:
                  busid = row.split(' ')[0]
                  out = subprocess.run(f'usbipd bind -b {busid}',capture_output=True,encoding="UTF-8")
                  print(out.stdout)
                  print(f'Usbipd bind Myriad X')
              if ('Movidius MyriadX' in row or 'Luxonis Device' in row) and 'Shared' in row:
                  busid = row.split(' ')[0]
                  out = subprocess.run(f'usbipd attach -w -b {busid}',capture_output=True,encoding="UTF-8")
                  print(out.stdout)
                  print(f'Usbipd attached Myriad X on bus {busid}')
          time.sleep(.5)

      While this response is from an earlier discussion, I hope it can still be helpful to someone.

        a month later

        LaurenzB
        I think the initial connection is USB2 (just getting the device recognized). When you run a script, the device will reconnect with USB3.

        Thanks,
        Jaka

        2 months later

        erik

        Hi, I was able to my oak-1 to work on wsl. However, when I try to connect multiple cameras, I've found that it will only recognize one camera at a time. As in, if cameras 1 and 2 are connected, it will only recognize camera 1. As soon as I disconnect camera 1, it immediately recognizes camera 2. Do you have any suggestions/fixes for this so that I can work with multiple cameras simultaneously in WSL?

        Hi @veerpreetgulsingh ,
        Do you attach both cameras to wsl (as mentioned above)?

        usbipd wsl attach --busid {busid}

        Can you do lsusb -v inside the WSL?

        Yes, so I think it is a separate but related issue. When I try some of the provided examples for running multiple cameras at the same time, it fails to boot. When that happens, the camera is detached.

        So in this case, both cameras were found but failed to boot, so I had to reattach them. Haven't been able to solve this issue yet.

        4 days later