Grabbing 2 cameras with same Program

I made Python program from with parameter 0 or 1 for a system with 2 cameras at port 0 and 1:
with, "Drivers", ""), port=CAM_PORT) as device:

I call it from 2 scripts parallel

python 0

python 1

This works only if I start first grab0.cmd and then grab1.cmd

If I start grab1.cmd first then in grab0.cmd an error occure:
with, “Drivers”, “”), port=CAM_PORT) as device:
RuntimeError: {C-API call failed} ({LoadImageFileW})

A similar problem is with the .Net example Cvb.Net\GenICam.
I appended a parameter for the port in program.cs

   public static int port = 0;
    static void Main(string[] args)
        if (args.Length != 0)
            int.TryParse(args[0], out port);

and in Mainform.cs:

  public MainForm()         {
    this.Text += "  Port:"+Program.port;
    var device = FileDialogs.LoadByDialog(path => DeviceFactory.Open(path,board:0, port:Program.port), "Video Interface Drivers (*.vin)|*.vin");

But in this case I get an Error by opening driver for port 1 if the driver of camera on Port 0 was opened in the other instance of the program:

Error loading driver:

Loading the Device from file C:\Program Files\STEMMER IMAGING\Common Vision Blox\Drivers\ failed.

How can a make a program which can start twice to grab on port 0 and port 1 independent?



I found OpenPort with vin-driver and order of ports:

The solution is enable the following flag in GenICam.ini


which is located in “c:\ProgramData\STEMMER IMAGING\Common Vision Blox\Drivers”

Now I can start the python and .net program independently.



with this function I check the GenICam.ini for AutoSwitchEnable=0 and change it if necessary:

import cvb
import os
import shutil
import re

def check_autoswitchenable():
    ini = os.path.join(cvb.data_path(), "Drivers", "GenICam.ini")
    with open(ini, 'r+') as f:
        text =
        replaced = re.sub(r'^\s*AutoSwitchEnable\s*=\s*0\s*$', 'AutoSwitchEnable=1', text, 1, re.M | re.IGNORECASE)
        if text != replaced:
            bak = ini + '.bak'
            if not os.path.exists(bak):  # check if the file doesn't exist
                shutil.copy(ini, bak)
            # write replaced in GenICam.ini at pos 0

The python module configparser does not support comments, which are gone after read, change, update.

1 Like