Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Latest commit

 

History

History
48 lines (37 loc) · 1.01 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.01 KB

GoDoc

go-cantact

A package for communicating on Controller Area Network buses using the CANtact hardawre.

Details

This package makes use of the serial library for providing access to CANtact's serial port. It provides functions for sending and receiving frames in the correct format for the device.

Usage

package main

import (
	"log"
	"os"
	"github.com/linklayer/go-cantact"
)

func main() {
	d, err := cantact.NewDevice(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	
	// set bitrate mode to 6, 500 kbps
	d.SetBitrate(6)

	// open connection to CAN bus
	d.Open()

	// send a frame
	data := []byte{0xDE, 0xAD, 0xBE, 0xEF}
	txFrame := cantact.Frame{ID: 0x123, Dlc: len(data), Data: data}
	d.WriteFrame(txFrame)

	// read a frame (blocking call)
	rxFrame, err := d.ReadFrame()
	if err != nil {
		log.Panic(err)
	}
	log.Println(rxFrame)
}