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

linklayer/go-cantact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

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)
}

About

Support for the CANtact device in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages