MCPcopy Create free account
hub / github.com/distributed/sers / Example

Function Example

sers_test.go:16–25  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

14// port, with a timeout of 1 second and prints the received
15// bytes to stdout.
16func 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
27func readFirstBytesFromPort(fn string) ([]byte, error) {
28 sp, err := sers.Open(fn)

Callers

nothing calls this directly

Calls 1

readFirstBytesFromPortFunction · 0.85

Tested by

no test coverage detected