@@ -19,9 +19,39 @@ type IosDevice struct {
1919 UsbInfo string
2020}
2121
22+ //OpenDevice finds a gousb.Device by using the provided iosDevice.SerialNumber. It returns an open device handle.
23+ //Opening using VID and PID is not specific enough, as different iOS devices can have identical VID/PID combinations.
24+ func OpenDevice (ctx * gousb.Context , iosDevice IosDevice ) (* gousb.Device , error ) {
25+ deviceList , err := ctx .OpenDevices (func (desc * gousb.DeviceDesc ) bool {
26+ return true
27+ })
28+
29+ if err != nil {
30+ log .Warn ("Error opening usb devices" , err )
31+ }
32+ var usbDevice * gousb.Device = nil
33+ for _ , device := range deviceList {
34+ sn , err := device .SerialNumber ()
35+ if err != nil {
36+ log .Warn ("Error retrieving Serialnumber" , err )
37+ }
38+ if sn == iosDevice .SerialNumber {
39+ usbDevice = device
40+ } else {
41+ device .Close ()
42+ }
43+ }
44+
45+ if usbDevice == nil {
46+ return nil , fmt .Errorf ("Unable to find device:%+v" , iosDevice )
47+ }
48+ return usbDevice , nil
49+ }
50+
2251//ReOpen creates a new Ios device, opening it using VID and PID, using the given context
23- func (d * IosDevice ) ReOpen (ctx * gousb.Context ) (IosDevice , error ) {
24- dev , err := ctx .OpenDeviceWithVIDPID (d .VID , d .PID )
52+ func (d IosDevice ) ReOpen (ctx * gousb.Context ) (IosDevice , error ) {
53+
54+ dev , err := OpenDevice (ctx , d )
2555 if err != nil {
2656 return IosDevice {}, err
2757 }
@@ -71,7 +101,7 @@ func FindIosDevice(udid string) (IosDevice, error) {
71101 return IosDevice {}, errors .New ("no iOS devices are connected to this host" )
72102 }
73103 if udid == "" {
74- log .Debugf ("no udid specified, using '%s'" , list [0 ].SerialNumber )
104+ log .Infof ("no udid specified, using '%s'" , list [0 ].SerialNumber )
75105 return list [0 ], nil
76106 }
77107 for _ , device := range list {
0 commit comments