closing transport layer without init
sagregrevc opened this issue · comments
sagregrevc commented
Describe what you want to implement and what the issue & the steps to reproduce it are:
I try to find all sn of all connected devices. than I would like to close it.
tlFactory = pylon.TlFactory.GetInstance()
# Get all attached devices and exit application if no device is found.
devices = tlFactory.EnumerateDevices()
camera_names_set = set()
# Iterate through the list of devices
for device in devices:
camera_names_set.add(device.GetFriendlyName())
pylon.TlFactory.ReleaseTl() # TODO: not worked
after I would like make class with some of this cameras. but camera cannot be reached
info = pylon.DeviceInfo()
info.SetSerialNumber(self.id)
try:
self.camera_obj = pylon.InstantCamera(
pylon.TlFactory.GetInstance().CreateFirstDevice(info)
)
except Exception as ex:
logger.critical(ex)
st.error(
"camera probably open by different software. "
)
st.status.update(label="", expanded=True, state="error")
st.stop()
self.camera_obj.Open()
Is your camera operational in Basler pylon viewer on your platform
Yes
Hardware setup & camera model(s) used
x64, win10, 8Gb, USB3, 1m
Runtime information:
how I can close transport layer if I dont have object ?
Thies Möller commented
Standard way to solve your use-case is like this:
import pypylon.pylon as py
tlFactory = py.TlFactory.GetInstance()
# Get all attached devices and exit application if no device is found.
devices = tlFactory.EnumerateDevices()
class CamWrapper:
def __init__(self, device : py.DeviceInfo):
self.camera_obj = py.InstantCamera(
tlFactory.CreateDevice(device)
)
self.camera_obj.Open()
def __del__(self):
self.camera_obj.Close()
def __str__(self):
return f"CamWrapper <{self.camera_obj.DeviceInfo.GetFriendlyName()}>"
Select one of the cameras from the list of devices:
cam = CamWrapper(devices[0])
print(cam)
CamWrapper <Basler a2A4508-6gcPRO (40271242)>
del(cam)
sagregrevc commented
seems reason was in my code. cameras sn was processed by different way in different parts of code