completed retrievePortDetailsFromDevInfo
in retrievePortDetailsFromDevInfo: - updated call to setupDiGetDeviceRegistryProperty with the same style used elsewhere (first get the reqSize, then call) - use of generic variable names, in case the function is extended to fetch other values than spdrpFriendlyName (or spdrpDeviceDesc) - re-enabled the assignment of details.Product
This commit is contained in:
committed by
Cristian Maglie
parent
900c828b75
commit
4df0da8377
@@ -60,7 +60,7 @@ func parseDeviceID(deviceID string, details *PortDetails) {
|
|||||||
//sys setupDiEnumDeviceInfo(set devicesSet, index uint32, info *devInfoData) (err error) = setupapi.SetupDiEnumDeviceInfo
|
//sys setupDiEnumDeviceInfo(set devicesSet, index uint32, info *devInfoData) (err error) = setupapi.SetupDiEnumDeviceInfo
|
||||||
//sys setupDiGetDeviceInstanceId(set devicesSet, devInfo *devInfoData, devInstanceId unsafe.Pointer, devInstanceIdSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDeviceInstanceIdW
|
//sys setupDiGetDeviceInstanceId(set devicesSet, devInfo *devInfoData, devInstanceId unsafe.Pointer, devInstanceIdSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDeviceInstanceIdW
|
||||||
//sys setupDiOpenDevRegKey(set devicesSet, devInfo *devInfoData, scope dicsScope, hwProfile uint32, keyType uint32, samDesired regsam) (hkey syscall.Handle, err error) = setupapi.SetupDiOpenDevRegKey
|
//sys setupDiOpenDevRegKey(set devicesSet, devInfo *devInfoData, scope dicsScope, hwProfile uint32, keyType uint32, samDesired regsam) (hkey syscall.Handle, err error) = setupapi.SetupDiOpenDevRegKey
|
||||||
//sys setupDiGetDeviceRegistryProperty(set devicesSet, devInfo *devInfoData, property deviceProperty, propertyType *uint32, outValue *byte, outSize *uint32, reqSize *uint32) (res bool) = setupapi.SetupDiGetDeviceRegistryPropertyW
|
//sys setupDiGetDeviceRegistryProperty(set devicesSet, devInfo *devInfoData, property deviceProperty, propertyType *uint32, outValue *byte, bufSize uint32, reqSize *uint32) (res bool) = setupapi.SetupDiGetDeviceRegistryPropertyW
|
||||||
|
|
||||||
// Device registry property codes
|
// Device registry property codes
|
||||||
// (Codes marked as read-only (R) may only be used for
|
// (Codes marked as read-only (R) may only be used for
|
||||||
@@ -291,11 +291,15 @@ func retrievePortDetailsFromDevInfo(device *deviceInfo, details *PortDetails) er
|
|||||||
}
|
}
|
||||||
parseDeviceID(deviceID, details)
|
parseDeviceID(deviceID, details)
|
||||||
|
|
||||||
var friendlyName [1024]uint16
|
/* spdrpDeviceDesc returns a generic name, e.g.: "CDC-ACM", which will be the same for 2 identical devices attached
|
||||||
friendlyNameP := (*byte)(unsafe.Pointer(&friendlyName[0]))
|
while spdrpFriendlyName returns a specific name, e.g.: "CDC-ACM (COM44)",
|
||||||
friendlyNameSize := uint32(len(friendlyName) * 2)
|
the result of spdrpFriendlyName is therefore unique and suitable as an alternative string to for a port choice */
|
||||||
if setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpDeviceDesc /* spdrpFriendlyName */, nil, friendlyNameP, &friendlyNameSize, nil) {
|
n := uint32(0)
|
||||||
//details.Product = syscall.UTF16ToString(friendlyName[:])
|
setupDiGetDeviceRegistryProperty(device.set, &device.data, /* spdrpDeviceDesc */ spdrpFriendlyName, nil, nil, 0, &n)
|
||||||
|
buff := make([]uint16, n*2)
|
||||||
|
buffP := (*byte)(unsafe.Pointer(&buff[0]))
|
||||||
|
if setupDiGetDeviceRegistryProperty(device.set, &device.data, /* spdrpDeviceDesc */ spdrpFriendlyName, nil, buffP, n, &n) {
|
||||||
|
details.Product = syscall.UTF16ToString(buff[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user