ArduCAM / Arducam_tof_camera

51 stars 20 forks source link

Unable to disconnect correctly in python #57

Open fabian57fabian opened 1 year ago

fabian57fabian commented 1 year ago

I've tried connecting, getting some frames and disconnecting multiple times and it does not work correctly. This issue can be reproduced like this:

import time
import ArducamDepthCamera as ac

MAX_DISTANCE = 4

cam = ac.ArducamCamera()

for i in range(5):
  print("Connection #{}".format(i+1))
  if cam.open(ac.TOFConnect.CSI,0) != 0 :
    print("initialization failed")
  if cam.start(ac.TOFOutput.DEPTH) != 0 :
    print("Failed to start camera")
  cam.setControl(ac.TOFControl.RANG,MAX_DISTANCE)

  time.sleep(1)

  cam.stop()
  cam.close()

  time.sleep(1)

When trying to connect the second time, i get following warning:

setVideoMode ***WARNING*** TOFCamera: Could not set current frame format

Total output of given code gets:

Connection #1
Connection #2
setVideoMode ***WARNING*** TOFCamera: Could not set current frame format
Failed to start camera
Connection #3
setVideoMode ***WARNING*** TOFCamera: Could not set current frame format
Failed to start camera
Connection #4
setVideoMode ***WARNING*** TOFCamera: Could not set current frame format
Failed to start camera
Connection #5
setVideoMode ***WARNING*** TOFCamera: Could not set current frame format
Failed to start camera

What is the right way to disconnect from cam?

dennis-ard commented 1 year ago

It looks like there are multiple cameras connected to the system and the program starts without setting the correct camera. If so, please specify the path to the camera at startup,

camIdx = 1 # If the path of the camera is /dev/video1
cam.open(ac.TOFConnect.CSI,camIdx )