alliedvision / VimbaPython

Old Allied Vision Vimba Python API. The successor to this API is VmbPy
BSD 2-Clause "Simplified" License
93 stars 40 forks source link

Accessed Camera 'Name' with invalid Mode 'AccessMode.Full'. Valid modes are: (AccessMode.None_: 0, ) #157

Closed angarsky closed 1 year ago

angarsky commented 1 year ago

Hi there,

Today is my first experience with Allied Vision camera - so maybe I missed something trivial. The issue is that I can't get a frame via Python script.

The error is:

Accessed Camera 'Name' with invalid Mode 'AccessMode.Full'. Valid modes are: (AccessMode.None_: 0, )

The code is pretty simple and is taken from examples and documentation:

import cv2
from vimba import *

with Vimba.get_instance() as vimba:
  cams = vimba.get_all_cameras()
  print(cams[0].get_permitted_access_modes())
    # Error is thrown on next line.
    with cams[0] as cam:
      frame = cam.get_frame()
      frame.convert_pixel_format(PixelFormat.Mono8)
      cv2.imwrite('frame.jpg', frame.as_opencv_image())

The full error is on the screenshot. 2023-04-17 22-40-47

There's a bit similar issue #47 - but it doesn't look as the same.

Thanks.

BernardoLuck commented 1 year ago

correct me if I am wrong, have you open the camera with the VimbaViewer and at the same time try to run your code? This is not possible. Only one instance can open the camera in full access mode.

angarsky commented 1 year ago

@BernardoLuck you are totally right. Thanks for the reply. Yesterday was really hard day if I missed this thing :)

pjmara commented 4 months ago

Similar error here- I know the cause, there was a process that was killed with SIGKILL that did not have a chance to relinquish its claim on a camera. I have in mind a couple of possible solutions here, but importantly, unlplugging and re-plugging is NOT a solution for my usecase, as I do not have physical access to the cabling.

  1. Restart the host device (Really would rather not, but I know it would work)
  2. Try and query the camera in question's interface to try and figure out which usb interface to bring down / back up
  3. Change my programming approach to only use accessmode.full when setting up the camera, then reverting to accessmode.read, so that subsequent runs could get into the camera context with accessmode.full and use read/write

Is there any holes in my thinking here? Seems like my only options.

Teresa-AlliedVision commented 4 months ago

To have only one process with write access (AccessModeFull) to the camera is part of the standard and will not be changed in subsequent versions. Both USB and GigE cameras will notice on their own, if the program was stopped (missing ack from the process) and close themselves. If that is not happening with your USB cameras, you might need a firmware update.

Via hardware, the camera can be forced into a reset, if the power supply is connected or disconnected. I.e. if the camera is powered through USB and 12V is supplied to the external power input, then the camera will do a device reset to change from USB power to external power.

Read Only mode can not execute commands on the cameras, so it can not start the acquisition to get frames. It can be used to check the function and settings of the camera, but not to change them.