I have the following code that looks for MSR devices using POS for .NET, and returns an instance that matches my device name. Then I open and claim the instance that is found successfully even though the MSR device is not attached to the computer. How come this is possible? Is there a way to know if the device is trully attached before opening and claiming it? I don't get an exception or anything upon calling Open() or Claim() when the device is not attached. Any guidance is greatly appreciated.
PosExplorer explorer = new PosExplorer();
var devices = explorer.GetDevices(DeviceType.Msr);
foreach (DeviceInfo deviceInfo in devices)
{
if (deviceInfo.ServiceObjectName.ToLower() == deviceName.ToLower())
{
PosDevice posDevice = explorer.CreateInstance(deviceInfo);
if (posDevice is PosCommon)
{
posCommon = posDevice as PosCommon;
_log.Debug(string.Format("Instance of device {0} created.", deviceName));
break;
}
}
}
If the device supports power reporting, you can check
StatusPowerOff
to see if the device is powered off or attached to the terminal (see Microsoft Docs)You would also need to check
CapPowerReporting
first to see if the device supports power reporting or not.There is also the following that may help (from the MSR Docs)
StatusPowerOffline
: Indicates that the device is powered on but is either not ready or unable to respond to requestsStatusPowerOffOffline
: Indicates that either the device’s power is off or it is offlineStatusPowerOnline
: Indicates that the device’s power is turned on and it is ready for use.