check device connection

Post Reply
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

check device connection

Post by matteolucarelli »

Hi,
I'm working with a Scarlet and libvisiontransfer
I connect the camera using DeviceEnumeration discoverDevices and store deviceinfo as from your examples.

How can I check if the camera is still connected?

For example if I create the device, then detach the network cable some operation freezes.
How can I check it before and eventually, in case of network problem, redo the discoverDevices operation?

Thank you
k.schauwecker
Posts: 122
Joined: Mon Mar 25, 2019 1:12 pm

Re: check device connection

Post by k.schauwecker »

In UDP mode, when the connection is interrupted, libvisiontransfer should automatically re-connect as soon as the device becomes reachable again. No additional steps need to be performed here. To check if a device is still reachable you can use the device enumeration or check the time since the last frame.

If you are using TCP mode, then a disconnection will be performed when the network cable is unplugged. In this case the AsyncTransfer::isConnected() or ImageTransfer::isConnected() will return false, and you will have to initiate a new connection when the device becomes reachable again. In this case I would recommend to use the device enumeration and wait for Scarlet to be detected again.
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

Re: check device connection

Post by matteolucarelli »

To check if a device is still reachable you can use the device enumeration

You mean call DeviceEnumeration::DeviceList devices = deviceEnum.discoverDevices();
and check the size?

"or check the time since the last frame."

ok, but this works only during acquisition. What to do for to check the connection before any other operation? I mean:
-discover camera
- detach cable
- call, for example, map<string,ParameterInfo> params = pt.getAllParameters();

In the above case the operation freezes with no timeout.
A simple "bool device->checkConnection()" would be very handy in this case
k.schauwecker
Posts: 122
Joined: Mon Mar 25, 2019 1:12 pm

Re: check device connection

Post by k.schauwecker »

getAllParameters() should throw a TransferException if a network connection cannot be established.

Can you check if this exception is thrown in your case? Is it possible that the freeze you observe is caused by some exception handler in your application?
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

Re: check device connection

Post by matteolucarelli »

I've tried

Code: Select all

	// Search for Nerian stereo devices
	DeviceEnumeration deviceEnum;
	DeviceEnumeration::DeviceList devices = deviceEnum.discoverDevices();

	if (devices.size() <= devnum) return setError("No device %u connected",devnum);

	mDevice = devices[devnum];
then detach the nework and

Code: Select all

	try{
		internal::ParameterTransfer pt(mDevice.getIpAddress().c_str());
	}catch(...){
		return setError("No IP address");
	}
The execution remains stuck in internal::ParameterTransfer, no exception raise
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

Re: check device connection

Post by matteolucarelli »

To be precise remains stuck in "connect" ar line 67 of Networking::connectTcpSocket
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

Re: check device connection

Post by matteolucarelli »

Any news?
k.schauwecker
Posts: 122
Joined: Mon Mar 25, 2019 1:12 pm

Re: check device connection

Post by k.schauwecker »

Sorry for the late reply.

We could use a timeout for the connection. I have patched our current API and you can download the patched version here:
https://nerian.com/exchange/?d=5ac5e3b5fcae79c04c64501bd2c6fc02

If this solution works for you then we can integrate this into our official release. Please not that this API requires our brand new firmware which was just released yesterday (official announcement will still be mailed out).
matteolucarelli
Posts: 20
Joined: Fri Feb 04, 2022 3:32 pm

Re: check device connection

Post by matteolucarelli »

I've downloaded the beta version but is unclear how to check connection
k.schauwecker
Posts: 122
Joined: Mon Mar 25, 2019 1:12 pm

Re: check device connection

Post by k.schauwecker »

It doesn't have a connection check but it will timeout after 500ms when establishing a connection.
Post Reply