Exemplo n.º 1
0
func Enum() []Info {
	fmt.Printf("")

	bus := C.usb_get_busses()
	n := 0
	for ; bus != nil; bus = bus.next {
		for dev := bus.devices; dev != nil; dev = dev.next {
			n += 1
		}
	}
	infos := make([]Info, n)

	bus = C.usb_get_busses()
	n = 0

	for ; bus != nil; bus = bus.next {
		busname := C.GoString(&bus.dirname[0])

		for dev := bus.devices; dev != nil; dev = dev.next {
			devname := C.GoString(&dev.filename[0])

			var info Info
			info.Bus = busname
			info.Device = devname
			info.Vid = int(dev.descriptor.idVendor)
			info.Pid = int(dev.descriptor.idProduct)

			infos[n] = info
			n += 1
		}
	}
	return infos
}
Exemplo n.º 2
0
/// open usb device with info
//func Open(info Info) (*Device)
//{
//    var rdev *Device = nil;
//
//    for bus := C.usb_get_busses() ; bus != nil ; bus=bus.next
//    {
//        for dev := bus.devices ; dev!=nil ; dev = dev.next
//        {
//            if int(dev.descriptor.idVendor)  == info.Vid &&
//               int(dev.descriptor.idProduct) == info.Pid
//            {
//                h := C.usb_open(dev);
//                rdev = &Device{&info,h,dev.descriptor,10000};
//                return rdev;
//            }
//        }
//    }
//    return rdev;
//}
/// open usb device with info
func Open(vid, pid int) *Device {
	for bus := C.usb_get_busses(); bus != nil; bus = bus.next {
		for dev := bus.devices; dev != nil; dev = dev.next {
			if int(dev.descriptor.idVendor) == vid && int(dev.descriptor.idProduct) == pid {
				h := C.usb_open(dev)
				rdev := &Device{
					&Info{
						C.GoString(&bus.dirname[0]),
						C.GoString(&dev.filename[0]), vid, pid},
					h, dev.descriptor, 10000}
				return rdev
			}
		}
	}
	return nil
}