# AutoSwitchEnable stopped working !?

**URL:** <https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186>\
**Category:** C-style API\
**Tags:** cpp, genicam, autoswitch\
**Created:** [August 2, 2017, 10:53pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186 "2017-08-02T22:53:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 2, 2017, 10:53pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/1 "2017-08-02T22:53:59Z")

</div>

I am working on a system with dual cameras. To detect them, I am setting the AutoSwitchEnable to 1 in GenICam.ini before calling LoadImageFile, and this works.

On another machine where there is only one camera, this worked as well… until today. Without changing the code nor the configuration, the flag doesn’t work anymore and the second detection returns the same (and only) camera.

How is this magic possible ?

---

<div class="post-metadata">

**Author:** ![Sebastian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/sebastian/32/1267_2.png) [@Sebastian](https://forum.commonvisionblox.com/u/Sebastian)\
**Post date:** [August 3, 2017, 11:20am UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/2 "2017-08-03T11:20:23Z")

</div>

The AutoSwitchEnable can only work with two or more devices. It changes the camera port to the first available device.

On your machine with one camera the AutoSwitchEnable has no effect at all.  
It is meant to be used with two or more cameras.

I assume that with the “second detection” you mean loading the camera with `LoadImageFile/LoadImage`.  
A second call of LoadImage with the GenICam driver within the same process indeed loads the camera without a problem.  
Then you have two instances to the same camera and the same image data. This behavior is intended to be used in situations with more than one camera that you can load the camera and then change to the camera you want with `CSSetCamPort` or the CamPort Property of the Grabber Control.

If you try to load the same camera the second time on another process the call to `LoadImageFile/LoadImage` will fail.

Regards  
Sebastian

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 3, 2017, 11:46am UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/3 "2017-08-03T11:46:51Z")

</div>

No, I mean that previously, on the single camera machine, I was performing two calls to LoadImageFile; the first succeeded and the second failed as is the expected behavior with AutoSwitchEnable set.

But now, for no reason, the two calls succeed and the same camera is indeed loaded twice.

I understand this functionality correctly and it used to work. What can cause the behavior to change ?

---

<div class="post-metadata">

**Author:** ![Sebastian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/sebastian/32/1267_2.png) [@Sebastian](https://forum.commonvisionblox.com/u/Sebastian)\
**Post date:** [August 3, 2017, 12:14pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/4 "2017-08-03T12:14:29Z")

</div>

AutoSwitchEnable has no effect in a one camera setup and if we use LoadImageFile within the same process.

**Two Cameras and LoadImage file from two separate processes**

- AutoSwitchEnable=1  
First LoadImageFile succeeds  
Second LoadImageFile succeeds.

- AutoSwitchEnable=0  
First LoadImageFile succeeds (Process 1)  
Second LoadImageFile fails. (Process 2)

**One Camera and LoadImageFile within one process**

- First LoadImageFile succeeds
- Second LoadImagefile succeeds

**One Camera and LoadImageFile from two separate processes**

- First LoadImageFile succeeds (Process 1)
- Second LoadImageFile fails (Process 2)

The only explanation I can think off is that previously you called the second LoadImageFile from another process or between the time of the first and the second LoadImageFile the camera disconnected somehow because of an error.

The current behaviour of your application is correct. If you face the previous behaviour again please contact our Technical Support(📞 +49 89 80902-200 | 📧 [support@stemmer-imaging.de](mailto:support@stemmer-imaging.de)) and we can investigate what causes this issue.

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 3, 2017, 12:16pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/5 "2017-08-03T12:16:34Z")

</div>

If it is like this, then it is impossible to determine how many cameras there are by this method.

How can I know the number of available cameras ?

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 3, 2017, 12:18pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/6 "2017-08-03T12:18:05Z")

</div>

Also notice that I am performing the LoadImageFile from a single thread and the camera does not disconnect.

---

<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:** [August 3, 2017, 1:52pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/7 "2017-08-03T13:52:31Z")

</div>

For automatic device detection you can use

```auto
[SYSTEM]
CreateAutoIni=1

```

After loading the driver you can query the number of devices via `CS2GetNumPorts`. But for this you need to be able to load the GenICam.vin. But be careful if you are automatically discovering devices: the _GenICam.vin_ will detect GigE Vision cameras twice on _Windows_ operating systems:

1. Filter Driver
2. Socket Driver

You would need to filter the GenICam.ini manually.

For opening GenICam-devices you can use the function I proposed here:  
[https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/5?u=parsd](https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/5)

---

<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:** [August 3, 2017, 3:15pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/8 "2017-08-03T15:15:56Z")

</div>

`LoadImageFile(const char *, IMG &)` creates a new device image object with the `IMG` parameter being an _“out”_ parameter. This means that the referenced `IMG` variable will simply be overwritten. If you reuse the `IMG` handle variable for the second `LoadImageFile` call, the old device object the `IMG` handle points to, is **not** released, but leaked. And the device is kept open. Treat the :cvb: handles (`IMG`, `NODE`,…) like raw pointers.

I personally use a smart handle for life-time management:  
[https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/6?u=parsd](https://forum.commonvisionblox.com/t/old-image-broken-after-setting-new-camport/66/6)

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 3, 2017, 3:42pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/9 "2017-08-03T15:42:50Z")

</div>

I obviously don’t overwrite the handle as I want to work with all the cameras I detect !

---

<div class="post-metadata">

**Author:** ![Sebastian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/sebastian/32/1267_2.png) [@Sebastian](https://forum.commonvisionblox.com/u/Sebastian)\
**Post date:** [August 9, 2017, 2:02pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/10 "2017-08-09T14:02:12Z")

</div>

Dear @YvesDaoust,  
were you able to solve your issue with the information we gave you?

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 9, 2017, 2:38pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/11 "2017-08-09T14:38:21Z")

</div>

Sebastian,

it turns out that the behavior has reverted to how it was before, overnight, and theproblem is gone. Possibly a combination of camera reboot and PC reboot unlocked things.

I confirm the the AutoSwitchEnable flag does have an effect on a singel camera machine, contrary to what you said.

Thanks for the care,

```
    Yves
```

---

<div class="post-metadata">

**Author:** ![Sebastian](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/sebastian/32/1267_2.png) [@Sebastian](https://forum.commonvisionblox.com/u/Sebastian)\
**Post date:** [August 10, 2017, 12:37pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/12 "2017-08-10T12:37:40Z")

</div>

Hi @YvesDaoust,

Now I tested the influence of the AutoSwitchEnable flag when loading the driver within the same process. I was surprised to see that the driver could´t load if auto switch is enabled. This is not how I thought it should work and i am sorry that I gave you wrong information.

I will create a bug report for the driver developer.

---

<div class="post-metadata">

**Author:** ![YvesDaoust](https://avatars.discourse-cdn.com/v4/letter/y/c57346/32.png) [@YvesDaoust](https://forum.commonvisionblox.com/u/YvesDaoust)\
**Post date:** [August 10, 2017, 12:58pm UTC](https://forum.commonvisionblox.com/t/autoswitchenable-stopped-working/186/13 "2017-08-10T12:58:13Z")

</div>

PLEASE DON’T.

This is a desirable behavior. Without it, discovering the cameras would become a pain.
