# Connection monitoring in cvb.net

**URL:** <https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338>\
**Category:** .Net API\
**Created:** [February 9, 2021, 4:22pm UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338 "2021-02-09T16:22:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rob](https://forum.commonvisionblox.com/u/Rob)\
**Post date:** [February 9, 2021, 4:22pm UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/1 "2021-02-09T16:22:46Z")

</div>

Hi all,

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](http://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](http://cvb.net)???

I’ve seen this link already:  
[CVB User Guide for the GenICam Driver (commonvisionblox.com)](https://help.commonvisionblox.com/NextGen/14.0/md_theory_of_operation_hardware __gen_i_cam__ c_v_b__user_guide.html#gcug_chmtopic59)

However, this doesn’t seem to be compatible with the [cvb.net](http://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.

Thanks,

Rob

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [February 9, 2021, 6:02pm UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/2 "2021-02-09T18:02:33Z")

</div>

Hi Rob,

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.

---

<div class="post-metadata">

**Author:** ![Rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rob](https://forum.commonvisionblox.com/u/Rob)\
**Post date:** [February 10, 2021, 8:52am UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/3 "2021-02-10T08:52:35Z")

</div>

Hi parsd,

Thank you for taking the time to answer my query.

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:

```auto
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}");
}

```

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [February 10, 2021, 12:53pm UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/4 "2021-02-10T12:53:51Z")

</div>

What kind of underlying technology do you use?

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.

---

<div class="post-metadata">

**Author:** ![Rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rob](https://forum.commonvisionblox.com/u/Rob)\
**Post date:** [July 14, 2021, 9:28am UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/5 "2021-07-14T09:28:04Z")

</div>

Hi parsd,

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

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [July 15, 2021, 7:24am UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/6 "2021-07-15T07:24:08Z")

</div>

Hi @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:

```cs

var device = DeviceFactory.Open("GenICam.vin"); 
device.Notify[NotifyDictionary.DeviceDisconnected].Event += Disconnect; 
device.Notify[NotifyDictionary.DeviceReconnect].Event += Reconnect;  

private static void Disconnect(object sender, NotifyEventArgs e) 
{ 
Console.WriteLine("Device disconnected"); 
// do stuff 
}  

private static void Reconnect(object sender, NotifyEventArgs e) 
{ 
Console.WriteLine("Device reconnected"); 
// do stuff 
}

```

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.

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/chris/32/1154_2.png) [@Chris](https://forum.commonvisionblox.com/u/Chris)\
**Post date:** [July 15, 2021, 12:25pm UTC](https://forum.commonvisionblox.com/t/connection-monitoring-in-cvb-net/1338/7 "2021-07-15T12:25:52Z")

</div>

Hi @Rob ,

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.

Cheers  
Chris
