github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/examples/endpoint-serial/main.go (about) 1 package main 2 3 import ( 4 "log" 5 6 "github.com/bluenviron/gomavlib/v2" 7 "github.com/bluenviron/gomavlib/v2/pkg/dialects/ardupilotmega" 8 ) 9 10 // this example shows how to: 11 // 1) create a node which communicates with a serial endpoint 12 // 2) print incoming messages 13 14 func main() { 15 // create a node which communicates with a serial endpoint 16 node, err := gomavlib.NewNode(gomavlib.NodeConf{ 17 Endpoints: []gomavlib.EndpointConf{ 18 gomavlib.EndpointSerial{ 19 Device: "/dev/ttyUSB0", 20 Baud: 57600, 21 }, 22 }, 23 Dialect: ardupilotmega.Dialect, 24 OutVersion: gomavlib.V2, // change to V1 if you're unable to communicate with the target 25 OutSystemID: 10, 26 }) 27 if err != nil { 28 panic(err) 29 } 30 defer node.Close() 31 32 // print incoming messages 33 for evt := range node.Events() { 34 if frm, ok := evt.(*gomavlib.EventFrame); ok { 35 log.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message()) 36 } 37 } 38 }