I am trying to set up a car pc that reads canbus data output. I want the computer to automatically set up usb2serial device.
My problem is the command that comes from SocketCAN:
sudo ip link set up can0 type can bitrate 125000
I can't get the connection to work properly.
when the command is executed in a terminal it shud say link successful but when the go code runs it only return can't find script fork/exec
func Can_connect() error {
var err error
if helpers.Can_bitrate == 0 {
log.Println("can bitrate = 0")
err = errors.New("can bitrate = 0")
return err
}
//sudo ip link set up can0 type can bitrate 125000
obd_connect := exec.Command("bash", "-c", "sudo ip link set up can0 type can bitrate "+string(helpers.Can_bitrate))
obd_connect.Run()
obd_output, err := obd_connect.Output()
if err != nil {
log.Println("Error reading output from connecting to obd", err)
return err
}
i, err := strconv.Atoi(string(obd_output[:len(obd_output)-1]))
if err != nil {
log.Println(err)
}
if i == 0 {
log.Println("successful confection to obd")
} else {
log.Println("unable to setup obd")
}
return nil
}