Accessing 2 identical scanners from c#

59 Views Asked by At

I have a USB scanner which I connect and use through a DLL provided by the manufacturer.

these are the functions I use to access it:

    [DllImport(".\\lib\\HsId600s.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern byte HsIDCis_DeviceOpen(IntPtr APPHwnd);

    [DllImport(".\\lib\\HsId600s.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern bool HsIDCis_DeviceClose();

    [DllImport(".\\lib\\HsId600s.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
    public static extern byte HsIDCis_IDScan(string pImageFileName, bool bhorizontal);

So in C# I would access the scanner like this:

IntPtr h = this.Handle;
byte rslt = ID600.HsIDCis_DeviceOpen(h);
ID600.HsIDCis_IDScan(Path.Combine(Path.GetTempPath(), @"test"), false);

I start by passing the current form's handle to the scanner, and open a connection. Then proceed with IDScan to start scanning. Finally I control the the form's WndProc looking for a scan finished code, and finally close the communication with the scanner using

ID600.HsIDCis_DeviceClose();

It all works fine, but I am trying to connect a second scanner to the computer. I can't seem to find a way to select one to communicate with.

If both are connected, the communication just goes to the last one used. and if I turn that one off, the program communicates with the other.

Any ideas?

0

There are 0 best solutions below