Connecting to Device/using Vendor Command
I am trying to invoke a vendor defined command called PulseOutput from a custom event handler. The command provides a single pulse on the specified output port of the reader for the specified time interval. I used a format similar to what was posted in the thread "Using Vendor Defined Commands."
VendorSpecificInformation inputParams = new VendorSpecificInformation(); inputParams.Add("Port", "o1"); inputParams.Add("timeInterval", 500); VendorDefinedParameters vendorParameters = new VendorDefinedParameters(); vendorParameters.InputParameters = inputParams; using (DeviceConnection dc = new DeviceConnection("mydevice")) { dc.ExecuteVendorDefinedCommand( tagReadEvent.DeviceName, //source name "Alien", //vendor name "PulseOutput", //the name of the vendor extension "PulseOutput", //command null, //passcode vendorParameters ); } The device on which I need to invoke would be the device bound to the same process as the event handler. When using the above script, I receive errors "DeviceConnection must first be open before ExecutingVendorDefinedCommand", and, when I use dc.Open(), "Device "myDevice" already connected" (already connected to by the process; myDevice being the name of my reader).
How do I invoke a vendor command from a custom event handler on the device bound to the event handler's process?
Since your device is bound to a process, so a connection to the device will definitely remain open, as long as the process is running.
To get the DeviceConnection object associated with the device, you can use the following code ...
Collection
<Guid> connections = GeneralUtil.DeviceManagerProxy.GetCurrentDeviceStatus(deviceName).ConnectedClients; This will return the array of all open connections to the device. As per your description, your device supports only one connection to be opened to it, at a given time. So, in your case, the size of above collection will be 1, and hence the desired DeviceConnection object will be connections[0].
Another way is
DeviceConnection dc = new DeviceConnection(deviceName);
dc.OpenAdministrationConnection();
This will open a connection to the device in admin mode, even if another device connection to the same device is already open.
How to get a DeviceConnection from Guid, as described above ?
**************************************** Collection<Guid> connections = GeneralUtil.DeviceManagerProxy.GetCurrentDeviceStatus(deviceName).ConnectedClients;
**************************************