canusbcgo

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 7 Imported by: 0 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 (
	// 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

	// Filter mask settings
	ACCEPTANCE_CODE_ALL = 0x00000000
	ACCEPTANCE_MASK_ALL = 0xFFFFFFFF
)

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

Functions

func GetAdapters

func GetAdapters() (adapters []string, err error)

func IsNoMessage

func IsNoMessage(err error) bool

func NewError

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

Types

type CANDATA

type CANDATA byte

type CANHANDLE

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

func Open

func Open(szAdapter, bitrate string, code, mask uint32, flags OpenFlag) (*CANHANDLE, error)

Open CAN interface to device

Returs handle to device if open was successfull or zero or negative error code on falure.

szID ==== Serial number for adapter or NULL to open the first found.

szBitrate ========= "10" for 10kbps "20" for 20kbps "50" for 50kbps "100" for 100kbps "250" for 250kbps "500" for 500kbps "800" for 800kbps "1000" for 1Mbps

or

btr0:btr1 pair ex. "0x03:0x1c" or 3:28

acceptance_code =============== Set to CANUSB_ACCEPTANCE_CODE_ALL to get all messages.

acceptance_mask =============== Set to CANUSB_ACCEPTANCE_MASk_ALL to get all messages.

flags ===== CANUSB_FLAG_TIMESTAMP - Timestamp will be set by adapter.

func (*CANHANDLE) Close

func (ch *CANHANDLE) Close() error

Close channel with handle h.

func (*CANHANDLE) Flush

func (ch *CANHANDLE) Flush(flags FlushFlag) error

Flush output buffer on channel with handle h.

If flushflags is set to FLUSH_DONTWAIT the queue is just emptied and there will be no wait for any frames in it to be sent

func (*CANHANDLE) GetStatistics

func (ch *CANHANDLE) GetStatistics() (CANUsbStatistics, error)

Get transmission statistics for channel with handle h.

func (*CANHANDLE) Read

func (ch *CANHANDLE) Read() (*CANMsg, error)

Read message from channel with handle h.

func (*CANHANDLE) ReadFirst

func (ch *CANHANDLE) ReadFirst(id uint32, flags MessageFlag) (*CANMsg, error)

Read message from channel with handle h and id "id" which satisfy flags.

func (CANHANDLE) SetReceiveCallBack

func (ch CANHANDLE) SetReceiveCallBack(cc chan *CANMsg) error

Set a receive call back function. Set the callback to NULL to reset it.

func (*CANHANDLE) SetTimeout

func (ch *CANHANDLE) SetTimeout(receiveTimeout, sendTimeout uint32) error

Set timeouts used for blocking calls for channel with handle h.

func (*CANHANDLE) Status

func (ch *CANHANDLE) Status() (err error)

Get Adaper status for channel with handle h.

func (*CANHANDLE) VersionInfo

func (ch *CANHANDLE) VersionInfo() (string, error)

Get hardware/firmware and driver version for channel with handle h.

func (*CANHANDLE) Write

func (ch *CANHANDLE) Write(msg *CANMsg) error

Write message to channel with handle h.

type CANMsg

type CANMsg struct {
	Id        uint32  // Message id
	Timestamp uint32  // timestamp in milliseconds
	Flags     uint8   // [extended_id|1][RTR:1][reserver:6]
	Len       uint8   // Frame size (0.8)
	Data      [8]byte // Databytes 0..7
}

func (*CANMsg) String

func (msg *CANMsg) String() string

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 bys warnings
	BusOff         uint32 // # of bus off's
}

func (*CANUsbStatistics) String

func (c *CANUsbStatistics) String() string

type Error

type Error struct {
	Code        ErrorCode
	Description string
}

func (*Error) Error

func (ke *Error) Error() string

type ErrorCode

type ErrorCode int
const (
	ERROR_CANUSB_OK                ErrorCode = 0x01
	ERROR_CANUSB_GENERAL           ErrorCode = -0x01
	ERROR_CANUSB_OPEN_SUBSYSTEM    ErrorCode = -0x02
	ERROR_CANUSB_COMMAND_SUBSYSTEM ErrorCode = -0x03
	ERROR_CANUSB_NOT_OPEN          ErrorCode = -0x04
	ERROR_CANUSB_TX_FIFO_FULL      ErrorCode = -0x05
	ERROR_CANUSB_INVALID_PARAM     ErrorCode = -0x06
	ERROR_CANUSB_NO_MESSAGE        ErrorCode = -0x07
	ERROR_CANUSB_MEMORY_ERROR      ErrorCode = -0x08
	ERROR_CANUSB_NO_DEVICE         ErrorCode = -0x09
	ERROR_CANUSB_TIMEOUT           ErrorCode = -0x10
	ERROR_CANUSB_INVALID_HARDWARE  ErrorCode = -0x11
)

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 uint32
const (
	CANMSG_EXTENDED MessageFlag = 0x80 // Extended 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
)

type ReceiveCallBack

type ReceiveCallBack func(msg *CANMsg)

Jump to

Keyboard shortcuts

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