Documentation
¶
Index ¶
- Constants
- Variables
- func GetAdapters() (adapters []string, err error)
- func IsNoMessage(err error) bool
- func NewError[T ~int | ~int32 | int64](code T) error
- type CANDATA
- type CANHANDLE
- func (ch *CANHANDLE) Close() error
- func (ch *CANHANDLE) Flush(flags FlushFlag) error
- func (ch *CANHANDLE) GetStatistics() (CANUsbStatistics, error)
- func (ch *CANHANDLE) Read() (*CANMsg, error)
- func (ch *CANHANDLE) ReadFirst(id uint32, flags MessageFlag) (*CANMsg, error)
- func (ch CANHANDLE) SetReceiveCallBack(cc chan *CANMsg) error
- func (ch *CANHANDLE) SetTimeout(receiveTimeout, sendTimeout uint32) error
- func (ch *CANHANDLE) Status() (err error)
- func (ch *CANHANDLE) VersionInfo() (string, error)
- func (ch *CANHANDLE) Write(msg *CANMsg) error
- type CANMsg
- type CANUsbStatistics
- type Error
- type ErrorCode
- type FlushFlag
- type MessageFlag
- type OpenFlag
- type ReceiveCallBack
Constants ¶
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 ¶
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 IsNoMessage ¶
Types ¶
type CANHANDLE ¶
type CANHANDLE struct {
// contains filtered or unexported fields
}
func Open ¶
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) Flush ¶
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) 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 ¶
Set a receive call back function. Set the callback to NULL to reset it.
func (*CANHANDLE) SetTimeout ¶
Set timeouts used for blocking calls for channel with handle h.
func (*CANHANDLE) VersionInfo ¶
Get hardware/firmware and driver version for channel with handle h.
type CANMsg ¶
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 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 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)