Skip to content

Commit

Permalink
fix: Don't hardcode /dev into serial port name
Browse files Browse the repository at this point in the history
  • Loading branch information
deregtd committed Jun 15, 2024
1 parent d521568 commit 878db32
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cmd/usbcantest/usbcantest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

func main() {
ctx := context.Background()

options := canbus.USBCANChannelOptions{
SerialInterfaceName: "tty.usbserial-210",
SerialBaudRate: 2000000,
BitRate: 250000,
SerialPortName: "/dev/tty.usbserial-210",
SerialBaudRate: 2000000,
BitRate: 250000,
FrameHandler: func(frame can.Frame) {
fmt.Printf("handled frame: %+v\n", frame)
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/canbus/usbcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const (

// USBCANChannelOptions is a type that contains required options on a SocketCANChannel.
type USBCANChannelOptions struct {
SerialInterfaceName string
SerialBaudRate int
BitRate int
FrameHandler can.HandlerFunc
SerialPortName string
SerialBaudRate int
BitRate int
FrameHandler can.HandlerFunc
}

// USBCANChannel represents a single USB-CAN-based canbus channel for sending/receiving CAN frames
Expand All @@ -65,7 +65,7 @@ func (c *USBCANChannel) Run(ctx context.Context) error {
mode := &serial.Mode{
BaudRate: c.options.SerialBaudRate,
}
port, err := serial.Open("/dev/"+c.options.SerialInterfaceName, mode)
port, err := serial.Open(c.options.SerialPortName, mode)
if err != nil {
return err
}
Expand All @@ -76,7 +76,7 @@ func (c *USBCANChannel) Run(ctx context.Context) error {
return err
}

c.log.WithField("interfaceName", c.options.SerialInterfaceName).
c.log.WithField("portName", c.options.SerialPortName).
Info("Opened USBCAN and listening")

pending := []byte{}
Expand Down

0 comments on commit 878db32

Please sign in to comment.