示例#1
0
文件: main.go 项目: ARolek/mxio
func main() {
	init_interface()
	flag.Parse()
	var dmap = make(map[string]interface{})

	dt, err := deviceTypeByName(*dtype)
	ifn, err := net.InterfaceByName(nif)
	errout(err, 2)
	m := mxio.Mxio{
		IF:         ifn,
		DeviceType: dt,
		Retry:      uint8(*retry),
		Timeout:    time.Duration(*timeout),
	}
	d, err := m.AutoSearch()
	errout(err, 3)
	dmap["count"] = len(d)
	dl := make([]jsonDevice, 0, len(d))
	for _, dd := range d {
		dl = append(dl, newJsonDevice(dd))
	}
	dmap["devices"] = dl

	enc := json.NewEncoder(os.Stdout)
	errout(enc.Encode(dmap), 5)
}
示例#2
0
func ExampleAutoSearch_Interface() {
	// Search on the first Interface, for only the E1200_SERIES of devices
	m := mxio.Mxio{
		IF:         net.Interfaces()[0],
		DeviceType: mxio.E1200_SERIES,
	}
	devices, err := m.AutoSearch()
	if err != nil {
		// Handle error correctly.
		fmt.Printf("Could not find devices because of %v\n", err)
		return
	}
	fmt.Printf("Found %v devices:\n", len(devices))
	for i, d := range devices {
		fmt.Printf("Device %v :\n%v\n", i, d)
	}
}