Пример #1
0
func main() {

	// rxBuf size should not exceed the capacity of int32
	rxBuf := make([]byte, 256)

	s := lsport.Conf{}
	lsport.Init(&s, "/dev/ttyUSB0")
	lsport.SetParams(&s, 115200, 8, 1)

	go PollingRead(s.Port, rxBuf, 100, 100)
	// Allow some settling time, tweak as required.
	time.Sleep(time.Duration(2000) * time.Millisecond)

	lsport.Write(s.Port, []byte("Hello "))
	time.Sleep(time.Duration(200) * time.Millisecond)

	lsport.Write(s.Port, []byte("World "))
	time.Sleep(time.Duration(200) * time.Millisecond)

	lsport.Close(&s)

	fmt.Println("\nList ports:")
	ports, err := lsport.PortsSlice()
	if err == nil {
		for _, port := range ports {
			fmt.Printf("%s\n", port)
		}
	} else {
		fmt.Printf("%s\n", err.Error())
	}
}
Пример #2
0
func main() {

	fmt.Println("List ports:")
	ports, err := lsport.PortsSlice()
	if err == nil {
		for _, port := range ports {
			fmt.Printf("%s\n", port)
		}
	} else {
		fmt.Printf("%s\n", err.Error())
	}
}