• DepthAI
  • Sometimes reconnection fails with OAK-D camera with autofocus

I have a small program which tries to connect to the camera, then takes a frame, then disconnects and then does it again. In 10-30 connections, it crashes, because dai.Device.getAllAvailableDevices() returns empty array. Here is the program:

Here is the output:

open 1

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 2

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 3

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 4

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 5

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 6

Opened Luxonis camera device

got frame (2160, 3840, 3)

Deleted device

open 7

[2024-09-01 03:40:11.610] [depthai] [warning] skipping X_LINK_BOOTED device having name "2.1"

AssertionError: No connected Luxonis cameras, or all of them are in use

Why does it fail to reconnect? Is that hardware bug? How can it be fixed?

    camuser
    Might be a usb issue. What about checking in code if the device is connectable and only then trying to establish the connection?

    What is the dmesg output when the crash happens? Does it differ from other times when the reconnection works as expected?

    Thanks,
    Jaka

    I'm on windows. How do i check if device is connectable? My camera is new, cable is new and it happens on different computers.

      Hi camuser,

      you can try this code to see if the device is available:

      import depthai as dai
      from typing import List
      
      print('Searching for all available devices...\n')
      # Query all available devices (USB and POE OAK cameras)
      infos: List[dai.DeviceInfo] = dai.DeviceBootloader.getAllAvailableDevices()
      
      if len(infos) == 0:
          raise Exception("DepthAI couldn't find any available OAK device!")
      
      
      for info in infos:
          # Converts enum eg. 'XLinkDeviceState.X_LINK_UNBOOTED' to 'UNBOOTED'
          state = str(info.state).split('X_LINK_')[1]
      
          print(f"Found device '{info.name}', MxId: '{info.mxid}', State: '{state}'")
      
      
      # Connect to a specific device. We will just take the first one
      print(f"\nBooting the first available camera ({infos[0].name})...")
      with dai.Device(dai.Pipeline(), infos[0], usb2Mode=False) as device:
          print("Available camera sensors: ", device.getCameraSensorNames())
          calib = device.readCalibration()
          eeprom = calib.getEepromData()
          print(f"Product name: {eeprom.productName}, board name {eeprom.boardName}")

      Thanks,
      Filip