This program opens a serial port, configurable by changing portname below and configures it for 57600 baud, 8 data bits, no parity bit, 1 stop bit, no handshaking. It then reads up to 128 bytes from the serial port, with a timeout of 1 second and prints the received bytes to stdout.
()
| 14 | // port, with a timeout of 1 second and prints the received |
| 15 | // bytes to stdout. |
| 16 | func Example() { |
| 17 | portname := "/dev/ttyUSB0" |
| 18 | rb, err := readFirstBytesFromPort(portname) |
| 19 | if err != nil { |
| 20 | log.Fatal(err) |
| 21 | } |
| 22 | |
| 23 | fmt.Printf("got %d bytes from %s:\n%s", len(rb), portname, |
| 24 | hex.Dump(rb)) |
| 25 | } |
| 26 | |
| 27 | func readFirstBytesFromPort(fn string) ([]byte, error) { |
| 28 | sp, err := sers.Open(fn) |
nothing calls this directly
no test coverage detected