• Community
  • RuntimeError: Communication exception - possible device error/misconfiguration.

Hello guys,

I am trying to write a simple code which can iterate trough the frames on the host.
I am getting this error:
“RuntimeError: Communication exception - possible device error/misconfiguration. Original message 'Couldn't read data from stream: 'input' (X_LINK_ERROR)’”

I have simplified the class that I wrote. Here is the code:

class OakReader:

def __init__(self,
             source,
             fps=40):
             
    self.source = str(source)
    
    self.fps = fps
    
    print('start pipeline')
    pipeline = dai.Pipeline()

    if source == 'left':
        cam = pipeline.create(dai.node.MonoCamera)
        cam.setBoardSocket(dai.CameraBoardSocket.LEFT)
        # reslution
        cam.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)

    elif source == 'right':
        cam = pipeline.create(dai.node.MonoCamera)
        cam.setBoardSocket(dai.CameraBoardSocket.RIGHT)
        cam.setResolution(dai.MonoCameraProperties.SensorResolution.THE_40_P)

    # set camera fps
    cam.setFps(self.fps)
    print(cam.getFps())

    xout = pipeline.create(dai.node.XLinkOut)
    xout.setStreamName('input')

    # attach camera to output xlink
    cam.out.link(xout.input)

    device = dai.Device(pipeline,usb2Mode=True)
    # get output queues
    self.queue = device.getOutputQueue(name='input',maxSize=1)
    self.read_frame = self._read_frame

def __iter__(self):
    """Iterator for reading frames

    Returns:
    OakReader: can be used in next function or loops directly
    """
    return self

def __next__(self):
    """Returns next  frame read from stream
    Returns:
    the latest frame read from the stream
    """
    frame = self.read_frame()
    self._count += 1

    return frame

def _read_frame(self):
    """Read frame from stream and return frame
    Returns:
    the latest frame read from the stream if flag is True else None.
    """
    frame = self.queue.get()
    return  frame.getCvFrame()

if name == "main":

source = "left"
fps = 40
oak_reader = OakReader(source=source, fps=fps)

for frame in oak_reader:

    height, width = frame.shape
    print(height)
    print(width)

I have been struggling with this for a day now.
I cannot iterate through the frames. I get the error when I execute the for loop.
I really appreciate if anyone can help me...

Thank you very much.

  • erik replied to this.

    Hello Sima_Azizi ,
    This is a general issue when something went wrong on the camera. Many times it has to do with the USB cable, eiter a faulty USB3 cable or USB2 cable. Could you run this example and copy the output? It will print the USB speed to the log. If it's HIGH, it means it's USB2 and that you should replace your cable with an USB3 one.
    Thanks, Erik

      erik
      Thank you very much for your response.

      I finally could solve this problem by replacing "device = dai.Device(pipeline,usb2Mode=True)" by self.device = dai.Device(pipeline,usb2Mode=True)" and also replacing "self.queue = device.getOutputQueue(name='input',maxSize=1)" by "self.queue = self.device.getOutputQueue(name='input',maxSize=1)"

      The camera was just working fine for all of the demos and depthai examples. But when I wrote it as an structure based code to iterate through the frames, I was getting the "RunetimeError".

      I was not using device object in any of the methods of the class, so I did not think I should use self.device. But it seemed that the camera was not working in the method functions and was just working fine in the init of the class. So when I changed device to self.device, everything worked fine.

      Thanks again for your help Erik!

      2 years later

      i ve got the same error using good USB3. found out it caused by default rgbcamera's ftp=40 in my case. i fixed the issue by changing the value to 25.

      a year later

      “what(): Communication exception - possible device error/misconfiguration. Original message 'Couldn't read data from stream: 'out' (X_LINK_ERROR)'”

      Yes i have also solved common error with usbMode2 is true

      我也遇到相同的问题了,我设置usb2mode 为true解决了

      //结构推送相机
      auto deviceInfo = dai:😃eviceInfo();
      *// deviceInfo.name= "192.168.110.226";
      // deviceInfo.protocol=X_LINK_TCP_IP;
      // deviceInfo.state=X_LINK_BOOTLOADER;
      // Connect to device and start pipeline
      dai:😃evice device(pipeline, deviceInfo,true);//电流不稳定的时候 使用true
      // device.setIrLaserDotProjectorBrightness(1000);

      //取帧显示
      auto outqueue = device.getOutputQueue("out", cam->getFps(), false);//maxsize 代表缓冲数据*
      auto depthQueue = device.getOutputQueue("depth", 4, false);
      auto spatialCalcQueue = device.getOutputQueue("spatialData", 8, false);
      auto spatialCalcConfigInQueue = device.getInputQueue("spatialCalcConfig");

      std::string videoPath = "/home/ubuntu/Downloads/fish_project_v3/demo.mp4";
      const int thread_num = 5;
      std::array<thread, thread_num> threads;
      threads = {