I am relatively new to cvb so apologies if i’m asking an obvious question!
I’ve been moving our image-capturing code (C#) from the standard cvb library to using the cvb.NET library. This has been generally successful and capturing/saving images and configuring cameras works great. However, I can’t figure out how to do connection monitoring in cvb.net???
However, this doesn’t seem to be compatible with the cvb.net approach to connecting devices. I’ve seen the Device.ConnectionState property and the Device.ConnectionStateChanged event, but neither of these seem to work as expected.
I wrote a small test harness that manually monitored the Device.ConnetionState property of my camera as I disconnected and reconnected it and the ConnectionState was Connected throughout.
I tried subscribing to the ConnectionStateChanged event but my handler was never triggered.
I’m sure there must be something I’m missing, but I can’t see what. Any help would be greatly appreciated.
this is a good question, indeed. We simplified the connection monitoring interface quite a bit. You can use the Device.ConnectionState property and Device.ConnectionStateChanged event. Under the hood this still uses INotify, but makes handling this much more convenient.
Simply register to the Device.ConnectionStateChanged event. On the event data you have the .OldState and .NewState properties for you to evaluate the nature of the change.
The way you describe it what I attempted and thought would work, but I’ve noticed that the Device.ConnectionState property isn’t changing and Device.ConnectionStateChanged event isn’t being fired when I disconnect or reconnect my camera.
Do you have any idea why this might be?? Is there any further under-the-hood code I need? Or do I need to configure a node on the device somehow??
Thanks,
Rob
ps. for reference here is the code I am using:
bool success = DeviceFactory.TryOpenPort(driverString, channelNumber, out camera);
if (success) camera.ConnectionStateChanged += HandleConnectionStateChanged;
.
.
.
private void HandleConnectionStateChanged(object sender, ConnectionStateChangeEventArgs e)
{
logManager.Write($"Camera connection status has changed from {e.OldState} to {e.NewState}");
}
Not all Vins/transport layers support connection monitoring. You can check that by reading out the .ConnectionState property on the device: if that is ConnectionState.NotSupported the underlying technology doesn’t support it. If that states ConnectionState.Connected, then it still might be that the underlying transport layer does not communicate the connection change.
Thank you for your reply and apologies for the (quite considerable) delay in getting back to you!
So, i’ve run a small test and the ConnectionState is ConnectionState.Connected. So it will be down to the underlying transport layer I image.
As for underlying tech, we use GigE Vision cameras (specifically Jai Go 5101 and Dalsa M1280). Any further suggestions would be greatly appreciated, as we’ve tried a few work arounds that have proved ineffectual/unreliable.
Thanks again for your time in replying. Best wishes,
Rob
first of all, you seem to be using our old C-Style API, not the latest .NET wrappers.
Here is some code you can test to actually have some modern style C# code:
Also, which version of CVB are you using?
Best practice would be to update to the latest version and give my example code a try.
If it still does not work, let me know and I will try to reproduce the error here at my machine as well.
I just tested the code with a Genie Nano M2050, all I did was to add a while(true) in the main after the camera was loaded, to keep the programm running.
Disconnect and reconnect events worked like a charm.