canusb

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Filter mask settings
	ACCEPTANCE_CODE_ALL uint32 = 0x00000000
	ACCEPTANCE_MASK_ALL uint32 = 0xFFFFFFFF
)
View Source
const (
	// Status bits
	CANSTATUS_RECEIVE_FIFO_FULL  = 0x01
	CANSTATUS_TRANSMIT_FIFO_FULL = 0x02
	CANSTATUS_ERROR_WARNING      = 0x04
	CANSTATUS_DATA_OVERRUN       = 0x08
	CANSTATUS_ERROR_PASSIVE      = 0x20
	CANSTATUS_ARBITRATION_LOST   = 0x40
	CANSTATUS_BUS_ERROR          = 0x80
)
View Source
const MAX_DLC = 8

Variables

View Source
var (
	ErrOK               = &Error{ERROR_CANUSB_OK, "OK"}
	ErrGeneral          = &Error{ERROR_CANUSB_GENERAL, "general error"}
	ErrOpenSubsystem    = &Error{ERROR_CANUSB_OPEN_SUBSYSTEM, "open subsystem error"}
	ErrCommandSubsystem = &Error{ERROR_CANUSB_COMMAND_SUBSYSTEM, "command subsystem error"}
	ErrNotOpen          = &Error{ERROR_CANUSB_NOT_OPEN, "not open error"}
	ErrTxFifoFull       = &Error{ERROR_CANUSB_TX_FIFO_FULL, "transmit FIFO full"}
	ErrInvalidParam     = &Error{ERROR_CANUSB_INVALID_PARAM, "invalid parameter"}
	ErrNoMessage        = &Error{ERROR_CANUSB_NO_MESSAGE, "no message"}
	ErrMemoryError      = &Error{ERROR_CANUSB_MEMORY_ERROR, "memory error"}
	ErrNoDevice         = &Error{ERROR_CANUSB_NO_DEVICE, "no device"}
	ErrTimeout          = &Error{ERROR_CANUSB_TIMEOUT, "timeout"}
	ErrInvalidHardware  = &Error{ERROR_CANUSB_INVALID_HARDWARE, "invalid hardware"}

	ErrNoDeviceAvailable  = &Error{-100, "no device available"}
	ErrMessageDataToLarge = &Error{-101, "message data to large"}
	ErrMessageDataSize    = &Error{-102, "message data size missmatch"}
	ErrMessageDataToSmall = &Error{-103, "message data to small"}

	ErrReceiveFifoFull  = &Error{CANSTATUS_RECEIVE_FIFO_FULL, "receive FIFO full"}
	ErrTransmitFifoFull = &Error{CANSTATUS_TRANSMIT_FIFO_FULL, "transmit FIFO full"}
	ErrWarning          = &Error{CANSTATUS_ERROR_WARNING, "error warning (EI)"}
	ErrDataOverrun      = &Error{CANSTATUS_DATA_OVERRUN, "data overrun (DOI)"}
	ErrErrorPassive     = &Error{CANSTATUS_ERROR_PASSIVE, "error passive (EPI)"}
	ErrArbitrationLost  = &Error{CANSTATUS_ARBITRATION_LOST, "arbitration lost (ALI)"}
	ErrBussError        = &Error{CANSTATUS_BUS_ERROR, "bus error (BEI)"}
)

Functions

func IsNoMessage

func IsNoMessage(err error) bool

func NewError

func NewError[T ~int | ~int32 | int64](code T) error

Types

type CANHANDLE

type CANHANDLE struct {
	// contains filtered or unexported fields
}

CANHANDLE is a handle to a CANUSB device

type CANMsg

type CANMsg struct {
	ID        uint32        // Message id
	Timestamp uint32        // timestamp in milliseconds
	Flags     MessageFlag   // Message flags
	Len       uint8         // Frame size (0.8)
	Data      [MAX_DLC]byte // Databytes 0..7
}

CAN Frame

func (*CANMsg) Bytes

func (msg *CANMsg) Bytes() []byte

Returns the data bytes of the CANMsg

func (*CANMsg) String

func (msg *CANMsg) String() string

Returns a string representation of the CANMsg

type CANMsgEx

type CANMsgEx struct {
	ID        uint32      // Message id
	Timestamp uint32      // timestamp in milliseconds
	Flags     MessageFlag // Message flags
	Len       uint8       // Frame size (0.8)
}

func (*CANMsgEx) String

func (msg *CANMsgEx) String() string

Returns a string representation of the CANMsgEx

type CANUSBStatistics

type CANUSBStatistics struct {
	ReceiveFrames  uint32 // # of receive frames
	TransmitFrames uint32 // # of transmitted frames
	ReceiveData    uint32 // # of received data bytes
	TransmitData   uint32 // # of transmitted data bytes
	Overruns       uint32 // # of overruns
	BusWarnings    uint32 // # of bus warnings
	BusOff         uint32 // # of bus off's
}

func (*CANUSBStatistics) String

func (c *CANUSBStatistics) String() string

Returns a string representation of the CANUsbStatistics

  • RF - # of Received frames
  • TF - # of Transmitted frames
  • RB - # of Received data bytes
  • TB - # of Transmitted data bytes
  • Overruns - # of overruns
  • BusWarnings - # of bus warnings
  • BusOff - # of bus off's

type CallbackFunc

type CallbackFunc func(msg *CANMsg) uintptr

Callback function used with SetReceiveCallback

type Error

type Error struct {
	Code        ErrorCode
	Description string
}

func (*Error) Error

func (ke *Error) Error() string

type ErrorCode

type ErrorCode int32
const (
	ERROR_CANUSB_OK                ErrorCode = 1
	ERROR_CANUSB_GENERAL           ErrorCode = -1
	ERROR_CANUSB_OPEN_SUBSYSTEM    ErrorCode = -2
	ERROR_CANUSB_COMMAND_SUBSYSTEM ErrorCode = -3
	ERROR_CANUSB_NOT_OPEN          ErrorCode = -4
	ERROR_CANUSB_TX_FIFO_FULL      ErrorCode = -5
	ERROR_CANUSB_INVALID_PARAM     ErrorCode = -6
	ERROR_CANUSB_NO_MESSAGE        ErrorCode = -7
	ERROR_CANUSB_MEMORY_ERROR      ErrorCode = -8
	ERROR_CANUSB_NO_DEVICE         ErrorCode = -9
	ERROR_CANUSB_TIMEOUT           ErrorCode = -10
	ERROR_CANUSB_INVALID_HARDWARE  ErrorCode = -11
)

type FlushFlag

type FlushFlag uint8
const (
	FLUSH_WAIT          FlushFlag = 0x00
	FLUSH_DONTWAIT      FlushFlag = 0x01
	FLUSH_EMPTY_INQUEUE FlushFlag = 0x02
)

Flush flags

type MessageFlag

type MessageFlag uint8
const (
	CANMSG_STANDARD MessageFlag = 0x00 // Standard 11-bit CAN id
	CANMSG_EXTENDED MessageFlag = 0x80 // Extended 29-bit CAN id
	CANMSG_RTR      MessageFlag = 0x40 // Remote frame
)

Message flags

type OpenFlag

type OpenFlag uint32
const (
	FLAG_TIMESTAMP     OpenFlag = 0x0001 // Timestamp messages
	FLAG_QUEUE_REPLACE OpenFlag = 0x0002 // If input queue is full remove oldest message and insert new message.
	FLAG_BLOCK         OpenFlag = 0x0004 // Block receive/transmit
	FLAG_SLOW          OpenFlag = 0x0008 // Check ACK/NACK's
	FLAG_NO_LOCAL_SEND OpenFlag = 0x0010 // Don't send transmited frames on other local channels for the same interface
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL