Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple way to check if camera is connected #817

Open
YacobBY opened this issue Feb 3, 2025 · 1 comment
Open

Simple way to check if camera is connected #817

YacobBY opened this issue Feb 3, 2025 · 1 comment

Comments

@YacobBY
Copy link

YacobBY commented Feb 3, 2025

Describe what you want to implement and what the issue & the steps to reproduce it are:

Hello I am looking for a simple way to check whether the camera is still connected.
Using camera.GetDeviceInfo() methods does not appear to return errors when the camera is disconnected.

Is your camera operational in Basler pylon viewer on your platform

Yes

Hardware setup used

X86 pc

Camera(s) used

This code does not run because imports miss.
But 'acA1920-25gm'

Runtime information:

python: 3.11.11 (main, Dec  4 2024, 08:55:07) [GCC 11.4.0]
platform: linux/x86_64/5.19.8-xanmod1
pypylon: 4.0.0 / 8.0.0.10
@HighImp
Copy link
Contributor

HighImp commented Feb 3, 2025

Hi @YacobBY, if your camera should be "open", you can use:

camera.IsCameraDeviceRemoved()

Will be True if your camera is not connected anymore.

Or you access a node that reads a camera feature, the device info are static information on the host after discovering the camera.

So a script can look like:

import pypylon.pylon as py
import time

camera = py.InstantCamera(py.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()

# approach 1 - using native function to check the connection
while not camera.IsCameraDeviceRemoved():
    time.sleep(1)

#-------------------------------------------------------------------

# approach 2 - access any feature that requires a connection
while True:
    try:
        camera.ExposureTime.Value
        time.sleep(1)
    except py.RuntimeException:
        # camera probably disconnected,
        # but definitely not accessible anymore
        break

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants