Skip to content

Commit e7a5c38

Browse files
johnlauerfacchinm
authored andcommitted
Got related ports working for windows
Former-commit-id: 75ceb7c27963d5fbf9b77a65947e51eb85d9e13a
1 parent f87f90f commit e7a5c38

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

seriallist_windows.go

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,48 @@ func getListViaWmiPnpEntity() ([]OsSerialPort, os.SyscallError) {
116116
list := make([]OsSerialPort, count)
117117

118118
for i := 0; i < count; i++ {
119+
120+
// items we're looping thru look like below and
121+
// thus we can query for any of these names
122+
/*
123+
__GENUS : 2
124+
__CLASS : Win32_PnPEntity
125+
__SUPERCLASS : CIM_LogicalDevice
126+
__DYNASTY : CIM_ManagedSystemElement
127+
__RELPATH : Win32_PnPEntity.DeviceID="USB\\VID_1D50&PID_606D&MI_02\\6&2F09EA14&0&0002"
128+
__PROPERTY_COUNT : 24
129+
__DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
130+
__SERVER : JOHN-ATIV
131+
__NAMESPACE : root\cimv2
132+
__PATH : \\JOHN-ATIV\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_1D50&PID_606D&MI_02\\6&2F09EA14
133+
&0&0002"
134+
Availability :
135+
Caption : TinyG v2 (Data Channel) (COM12)
136+
ClassGuid : {4d36e978-e325-11ce-bfc1-08002be10318}
137+
CompatibleID : {USB\Class_02&SubClass_02&Prot_01, USB\Class_02&SubClass_02, USB\Class_02}
138+
ConfigManagerErrorCode : 0
139+
ConfigManagerUserConfig : False
140+
CreationClassName : Win32_PnPEntity
141+
Description : TinyG v2 (Data Channel)
142+
DeviceID : USB\VID_1D50&PID_606D&MI_02\6&2F09EA14&0&0002
143+
ErrorCleared :
144+
ErrorDescription :
145+
HardwareID : {USB\VID_1D50&PID_606D&REV_0097&MI_02, USB\VID_1D50&PID_606D&MI_02}
146+
InstallDate :
147+
LastErrorCode :
148+
Manufacturer : Synthetos (www.synthetos.com)
149+
Name : TinyG v2 (Data Channel) (COM12)
150+
PNPDeviceID : USB\VID_1D50&PID_606D&MI_02\6&2F09EA14&0&0002
151+
PowerManagementCapabilities :
152+
PowerManagementSupported :
153+
Service : usbser
154+
Status : OK
155+
StatusInfo :
156+
SystemCreationClassName : Win32_ComputerSystem
157+
SystemName : JOHN-ATIV
158+
PSComputerName : JOHN-ATIV
159+
*/
160+
119161
// item is a SWbemObject, but really a Win32_Process
120162
itemRaw, _ := oleutil.CallMethod(result, "ItemIndex", i)
121163
item := itemRaw.ToIDispatch()
@@ -133,14 +175,41 @@ func getListViaWmiPnpEntity() ([]OsSerialPort, os.SyscallError) {
133175
list[i].Name = s
134176
list[i].FriendlyName = asString.ToString()
135177
//}
178+
179+
// get the deviceid so we can figure out related ports
180+
// it will look similar to
181+
// USB\VID_1D50&PID_606D&MI_00\6&2F09EA14&0&0000
182+
deviceIdStr, _ := oleutil.GetProperty(item, "DeviceID")
183+
devIdItems := strings.Split(deviceIdStr.ToString(), "&")
184+
log.Printf("DeviceId elements:%v", devIdItems)
185+
list[i].SerialNumber = devIdItems[3]
186+
list[i].IdProduct = strings.Replace(devIdItems[1], "PID_", "", 1)
187+
list[i].IdVendor = strings.Replace(devIdItems[0], "USB\\VID_", "", 1)
188+
189+
manufStr, _ := oleutil.GetProperty(item, "Manufacturer")
190+
list[i].Manufacturer = manufStr.ToString()
191+
descStr, _ := oleutil.GetProperty(item, "Description")
192+
list[i].Product = descStr.ToString()
193+
//classStr, _ := oleutil.GetProperty(item, "CreationClassName")
194+
//list[i].DeviceClass = classStr.ToString()
195+
136196
}
137197

138-
/*
139-
for index, element := range list {
140-
log.Println("index ", index, " element ", element.Name+
141-
" friendly ", element.FriendlyName)
198+
for index, element := range list {
199+
200+
log.Printf("index:%v, name:%v, friendly:%v ", index, element.Name, element.FriendlyName)
201+
202+
for index2, element2 := range list {
203+
if index == index2 {
204+
continue
205+
}
206+
if element.SerialNumber == element2.SerialNumber {
207+
log.Printf("Found related element1:%v, element2:%v", element, element2)
208+
list[index].RelatedNames = append(list[index].RelatedNames, element2.Name)
209+
}
142210
}
143-
*/
211+
212+
}
144213

145214
return list, err
146215
}

0 commit comments

Comments
 (0)