Device.Net: When enable HID and Serial Port in windows, GetConnectedDeviceDefinitionsAsync return error
Your Code
// enable HidDevice and SerialPort here
var debugLogger = new DebugLogger();
var debugTracer = new DebugTracer();
WindowsHidDeviceFactory.Register(debugLogger, debugTracer);
WindowsSerialPortDeviceFactory.Register(debugLogger, debugTracer);
var hidFilterDeviceDefinition = new FilterDeviceDefinition
{DeviceType = DeviceType.Hid, VendorId = 0x0483, ProductId = 0x5750};
// here, hidDevices will include SerialPortDevice
var hidDevices = await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(hidFilterDeviceDefinition);
var serialPortFilterDeviceDefinition = new FilterDeviceDefinition {DeviceType = DeviceType.SerialPort};
// serialPortDevices' deviceType is null
var serialPortDevices = await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(serialPortFilterDeviceDefinition);
Info
- Platform: Windows,
- Device Type: Hid, SerialPort
- Version: 3.1.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (11 by maintainers)
I was thinking right now that i could install a service along with my app. The service will be running with privileges and can communicate with the device, my app will be running without privileges and can communicate with the service through a socket. That way, at installation time the elevated privileges will be needed, and after installation, any user without privileges running a non-elevated instance of my app can communicate with the device through the socket using the service that will be running with privileges… that could do the job right??
@carl-qva I get a lot of messages like this. I think Microsoft has started putting security around devices so that some calls don’t work. It makes sense. Users who are not admins shouldn’t really have access to devices. UWP has a better system where the user is forced to accept that the app is going to access the device. This problem has never really been solved at the Windows level but I think that Microsoft are working on it. Meantime, I think your app will have to specify that it needs those privileges.
Hi MelbourneDeveloper, im having an issue with Device.Net (and in general with all hid libraries that i’ve tested so far). The problem is that my app can communicate with my hid device only in administrator mode, when the app is not run in admin mode the device is not found. In admin mode i can read/write data without any problem. See this log from Device.Net and please help
region: WindowsHidDeviceFactory - GetConnectedDeviceDefinitionsAsync, message: About to call SetupDiGetClassDevs for class Guid 4d1e55b2-f16f-11cf-88cb-001111000030. Flags: 18, LogLevel: Information region: ApiService, message: Calling CreateFile for DeviceId: ?\hid#vid_0483&pid_a2ca&mi_00#7&1a31e08c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}. Desired Access: None. Share mode: 3. Creation Disposition: 3, LogLevel: Information Exception thrown: ‘Device.Net.Exceptions.DeviceException’ in Hid.Net.dll region: WindowsHidDeviceFactory, message: GetDeviceDefinition error. Device Id: ?\hid#vid_0483&pid_a2ca&mi_00#7&1a31e08c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}, LogLevel: Error, exception: CreateReadConnection call with Id of ?\hid#vid_0483&pid_a2ca&mi_00#7&1a31e08c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} failed. region: WindowsHidDeviceFactory, message: Device with path ?\hid#vid_0483&pid_a2ca&mi_00#7&1a31e08c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} was skipped. See previous logs., LogLevel: Warning
@fengqiangboy
Please try this code https://github.com/MelbourneDeveloper/Device.Net/blob/740659228fece1a0d17b2ebf2541e0c697b0df5e/src/Device.Net.UnitTests/IntegrationTests.cs#L109
It’s ok when only use Hid device.