Documentation
¶
Index ¶
- Variables
- func GetChannelDataBytes(channel int, item ChannelData) ([]byte, error)
- func GetChannelDataString(channel int, item ChannelData) (string, error)
- func GetErrorText(status int) (string, error)
- func GetNumberOfChannels() (int, error)
- func GetVersion() string
- func Init() error
- func InitializeLibrary() error
- func NewError[T ~int | ~int32 | int64](code T) error
- func SetBusOutputControl(h Handle, drivertype DriverType) error
- func UnloadLibrary() error
- type AcceptFlag
- type BusParamsFreq
- type CANMessage
- type CANStatus
- type ChannelData
- type DriverType
- type Error
- type Handle
- func (h Handle) Accept(envelope int, flag AcceptFlag) error
- func (h Handle) BusOff() error
- func (h Handle) BusOn() error
- func (h Handle) Close() error
- func (h Handle) FlushReceiveQueue() error
- func (h Handle) FlushTransmitQueue() error
- func (h Handle) ObjBufAllocate(typ int) (int, error)
- func (h Handle) ObjBufWrite(idx, id int, message []byte, flags MsgFlag) error
- func (h Handle) Read(msg *CANMessage) error
- func (h Handle) ReadErrorCounters() (uint32, uint32, uint32, error)
- func (h Handle) ReadWait(msg *CANMessage, timeout uint32) error
- func (h Handle) ResetBus() error
- func (h Handle) SetAcceptanceFilter(code, mask uint, extended bool) error
- func (h Handle) SetBitrate(bitrate int) error
- func (h Handle) SetBusParams(freq BusParamsFreq, tseg1, tseg2, sjw, noSamp, syncmode uint32) error
- func (h Handle) SetBusParamsC200(btr0, btr1 uint8) error
- func (h Handle) Write(identifier uint32, data []byte, flags MsgFlag) error
- func (h Handle) WriteSync(timeoutMS uint32) error
- func (h Handle) WriteWait(identifier uint32, data []byte, flags MsgFlag, timeoutMS uint32) error
- type MsgFlag
- type OpenFlag
Constants ¶
This section is empty.
Variables ¶
var ( ErrOK = &Error{Code: 0, Description: "No error"} ErrParam = &Error{Code: -1, Description: "Error in parameter"} ErrNoMsg = &Error{Code: -2, Description: "No messages available"} ErrNotFound = &Error{Code: -3, Description: "Specified device not found"} ErrNoMem = &Error{Code: -4, Description: "Out of memory"} ErrNoChannels = &Error{Code: -5, Description: "No channels available"} ErrInterrupted = &Error{Code: -6, Description: "Interrupted by signals"} ErrTimeout = &Error{Code: -7, Description: "Timeout occurred"} ErrNotInitialized = &Error{Code: -8, Description: "Library not initialized"} ErrNoHandles = &Error{Code: -9, Description: "No more handles"} ErrInvHandle = &Error{Code: -10, Description: "Handle is invalid"} ErrIniFile = &Error{Code: -11, Description: "Error in the ini-file"} ErrDriver = &Error{Code: -12, Description: "CAN driver type not supported"} ErrTxBufOfl = &Error{Code: -13, Description: "Transmit buffer overflow"} ErrReserved1 = &Error{Code: -14, Description: "Unknown error (-14)"} ErrHardware = &Error{Code: -15, Description: "A hardware error was detected"} ErrDynaLoad = &Error{Code: -16, Description: "Can not find requested DLL"} ErrDynaLib = &Error{Code: -17, Description: "DLL seems to be wrong version"} ErrDynaInit = &Error{Code: -18, Description: "Error initializing DLL or driver"} ErrNotSupported = &Error{Code: -19, Description: "Operation not supported by hardware or firmware"} ErrReserved5 = &Error{Code: -20, Description: "Unknown error (-20)"} ErrReserved6 = &Error{Code: -21, Description: "Unknown error (-21)"} ErrReserved2 = &Error{Code: -22, Description: "Unknown error (-22)"} ErrDriverLoad = &Error{Code: -23, Description: "Can not load or open the device driver"} ErrDriverFailed = &Error{Code: -24, Description: "The I/O request failed, probably due to resource shortage"} ErrNoConfigMgr = &Error{Code: -25, Description: "Can't find required configuration software"} ErrNoCard = &Error{Code: -26, Description: "The card was removed or not inserted"} ErrReserved7 = &Error{Code: -27, Description: "Unknown error (-27)"} ErrRegistry = &Error{Code: -28, Description: "The Registry information is incorrect"} ErrLicense = &Error{Code: -29, Description: "The license is not valid"} ErrInternal = &Error{Code: -30, Description: "Internal error in the driver"} ErrNoAccess = &Error{Code: -31, Description: "Access denied"} ErrNotImplemented = &Error{Code: -32, Description: "Not implemented"} ErrDeviceFile = &Error{Code: -33, Description: "Device File error"} ErrHostFile = &Error{Code: -34, Description: "Host File error"} ErrDisk = &Error{Code: -35, Description: "Disk error"} ErrCrc = &Error{Code: -36, Description: "CRC error"} ErrConfig = &Error{Code: -37, Description: "Config error"} ErrMemoFail = &Error{Code: -38, Description: "Memo failure"} ErrScriptFail = &Error{Code: -39, Description: "Script error"} ErrScriptWrongVersion = &Error{Code: -40, Description: "Script version mismatch"} ErrScriptTxeContainerVersion = &Error{Code: -41, Description: "Script container version mismatch"} ErrScriptTxeContainerFormat = &Error{Code: -42, Description: "Script container format error"} ErrBufferTooSmall = &Error{Code: -43, Description: "Buffer provided too small to hold data"} ErrIoWrongPinType = &Error{Code: -44, Description: "I/O pin doesn't exist or I/O pin type mismatch"} ErrIoNotConfirmed = &Error{Code: -45, Description: "I/O pin configuration is not confirmed"} ErrIoConfigChanged = &Error{Code: -46, Description: "Configuration changed after last call to kvIoConfirmConfig"} ErrIoPending = &Error{Code: -47, Description: "The previous I/O pin value has not yet changed the output and i"} ErrIoNoValidConfig = &Error{Code: -48, Description: "There is no valid I/O pin configuration"} ErrReserved = &Error{Code: -49, Description: "Unknown error (-49)"} )
var (
InitErr error
)
libcanlib is loaded through purego, so no cgo or Kvaser headers are needed at build time. C long / unsigned long map to Go int / uint, which match their width on every Linux ABI Go supports.
The per-frame calls are raw symbol addresses called through SyscallN: a RegisterFunc'd func goes through reflect on every call, which costs allocations per frame. The rest stay typed for readability.
Functions ¶
func GetChannelDataBytes ¶
func GetChannelDataBytes(channel int, item ChannelData) ([]byte, error)
func GetChannelDataString ¶
func GetChannelDataString(channel int, item ChannelData) (string, error)
func GetErrorText ¶
func GetNumberOfChannels ¶
func GetVersion ¶
func GetVersion() string
func InitializeLibrary ¶
func InitializeLibrary() error
func SetBusOutputControl ¶
func SetBusOutputControl(h Handle, drivertype DriverType) error
func UnloadLibrary ¶
func UnloadLibrary() error
Types ¶
type AcceptFlag ¶
type AcceptFlag uint32
const ( FILTER_ACCEPT AcceptFlag = 0x01 FILTER_REJECT AcceptFlag = 0x02 FILTER_SET_CODE_STD AcceptFlag = 0x03 FILTER_SET_MASK_STD AcceptFlag = 0x04 FILTER_SET_CODE_EXT AcceptFlag = 0x05 FILTER_SET_MASK_EXT AcceptFlag = 0x06 FILTER_NULL_MASK AcceptFlag = 0x00 )
type BusParamsFreq ¶
type BusParamsFreq int32
const ( BITRATE_1M BusParamsFreq = -0x01 BITRATE_500K BusParamsFreq = -0x02 BITRATE_250K BusParamsFreq = -0x03 BITRATE_125K BusParamsFreq = -0x04 BITRATE_100K BusParamsFreq = -0x05 BITRATE_62K BusParamsFreq = -0x06 BITRATE_50K BusParamsFreq = -0x07 BITRATE_83K BusParamsFreq = -0x08 BITRATE_10K BusParamsFreq = -0x09 )
type CANMessage ¶
CANMessage is filled in place by Read/ReadWait; Identifier and Timestamp have the width of the C longs the driver writes into them.
type CANStatus ¶
type CANStatus int32
const ( ERR_OK CANStatus = 0 ERR_PARAM CANStatus = -1 ERR_NOMSG CANStatus = -2 ERR_NOTFOUND CANStatus = -3 ERR_NOMEM CANStatus = -4 ERR_NOCHANNELS CANStatus = -5 ERR_INTERRUPTED CANStatus = -6 ERR_TIMEOUT CANStatus = -7 ERR_NOTINITIALIZED CANStatus = -8 ERR_NOHANDLES CANStatus = -9 ERR_INVHANDLE CANStatus = -10 ERR_INIFILE CANStatus = -11 ERR_DRIVER CANStatus = -12 ERR_TXBUFOFL CANStatus = -13 ERR_RESERVED_1 CANStatus = -14 ERR_HARDWARE CANStatus = -15 ERR_DYNALOAD CANStatus = -16 ERR_DYNALIB CANStatus = -17 ERR_DYNAINIT CANStatus = -18 ERR_NOT_SUPPORTED CANStatus = -19 ERR_RESERVED_5 CANStatus = -20 ERR_RESERVED_6 CANStatus = -21 ERR_RESERVED_2 CANStatus = -22 ERR_DRIVERLOAD CANStatus = -23 ERR_DRIVERFAILED CANStatus = -24 ERR_NOCONFIGMGR CANStatus = -25 ERR_NOCARD CANStatus = -26 ERR_RESERVED_7 CANStatus = -27 ERR_REGISTRY CANStatus = -28 ERR_LICENSE CANStatus = -29 ERR_INTERNAL CANStatus = -30 ERR_NO_ACCESS CANStatus = -31 ERR_NOT_IMPLEMENTED CANStatus = -32 ERR_DEVICE_FILE CANStatus = -33 ERR_HOST_FILE CANStatus = -34 ERR_DISK CANStatus = -35 ERR_CRC CANStatus = -36 ERR_CONFIG CANStatus = -37 ERR_MEMO_FAIL CANStatus = -38 ERR_SCRIPT_FAIL CANStatus = -39 ERR_SCRIPT_WRONG_VERSION CANStatus = -40 ERR_SCRIPT_TXE_CONTAINER_VERSION CANStatus = -41 ERR_SCRIPT_TXE_CONTAINER_FORMAT CANStatus = -42 ERR_BUFFER_TOO_SMALL CANStatus = -43 ERR_IO_WRONG_PIN_TYPE CANStatus = -44 ERR_IO_NOT_CONFIRMED CANStatus = -45 ERR_IO_CONFIG_CHANGED CANStatus = -46 ERR_IO_PENDING CANStatus = -47 ERR_IO_NO_VALID_CONFIG CANStatus = -48 ERR__RESERVED CANStatus = -49 )
type ChannelData ¶
type ChannelData int32
const ( CHANNELDATA_CHANNEL_CAP ChannelData = 0x01 CHANNELDATA_TRANS_CAP ChannelData = 0x02 CHANNELDATA_CHANNEL_FLAGS ChannelData = 0x03 CHANNELDATA_CARD_TYPE ChannelData = 0x04 CHANNELDATA_CARD_NUMBER ChannelData = 0x05 CHANNELDATA_CHAN_NO_ON_CARD ChannelData = 0x06 CHANNELDATA_CARD_SERIAL_NO ChannelData = 0x07 CHANNELDATA_TRANS_SERIAL_NO ChannelData = 0x08 CHANNELDATA_CARD_FIRMWARE_REV ChannelData = 0x09 CHANNELDATA_CARD_HARDWARE_REV ChannelData = 0x0A CHANNELDATA_CARD_UPC_NO ChannelData = 0x0B CHANNELDATA_TRANS_UPC_NO ChannelData = 0x0C CHANNELDATA_CHANNEL_NAME ChannelData = 0x0D CHANNELDATA_DLL_FILE_VERSION ChannelData = 0x0E CHANNELDATA_DLL_PRODUCT_VERSION ChannelData = 0x0F CHANNELDATA_DLL_FILETYPE ChannelData = 0x10 CHANNELDATA_TRANS_TYPE ChannelData = 0x11 CHANNELDATA_DEVICE_PHYSICAL_POSITION ChannelData = 0x12 CHANNELDATA_UI_NUMBER ChannelData = 0x13 CHANNELDATA_TIMESYNC_ENABLED ChannelData = 0x14 CHANNELDATA_DRIVER_FILE_VERSION ChannelData = 0x15 CHANNELDATA_DRIVER_PRODUCT_VERSION ChannelData = 0x16 CHANNELDATA_MFGNAME_UNICODE ChannelData = 0x17 CHANNELDATA_MFGNAME_ASCII ChannelData = 0x18 CHANNELDATA_DEVDESCR_UNICODE ChannelData = 0x19 CHANNELDATA_DEVDESCR_ASCII ChannelData = 0x1A CHANNELDATA_DRIVER_NAME ChannelData = 0x1B CHANNELDATA_CHANNEL_QUALITY ChannelData = 0x1C CHANNELDATA_ROUNDTRIP_TIME ChannelData = 0x1D CHANNELDATA_BUS_TYPE ChannelData = 0x1E CHANNELDATA_DEVNAME_ASCII ChannelData = 0x1F CHANNELDATA_TIME_SINCE_LAST_SEEN ChannelData = 0x20 CHANNELDATA_REMOTE_OPERATIONAL_MODE ChannelData = 0x21 CHANNELDATA_REMOTE_PROFILE_NAME ChannelData = 0x22 CHANNELDATA_REMOTE_HOST_NAME ChannelData = 0x23 CHANNELDATA_REMOTE_MAC ChannelData = 0x24 CHANNELDATA_MAX_BITRATE ChannelData = 0x25 CHANNELDATA_CHANNEL_CAP_MASK ChannelData = 0x26 CHANNELDATA_CUST_CHANNEL_NAME ChannelData = 0x27 CHANNELDATA_IS_REMOTE ChannelData = 0x28 CHANNELDATA_REMOTE_TYPE ChannelData = 0x29 CHANNELDATA_LOGGER_TYPE ChannelData = 0x2A CHANNELDATA_HW_STATUS ChannelData = 0x2B CHANNELDATA_FEATURE_EAN ChannelData = 0x2C CHANNELDATA_BUS_PARAM_LIMITS ChannelData = 0x2D CHANNELDATA_CLOCK_INFO ChannelData = 0x2E CHANNELDATA_CHANNEL_CAP_EX ChannelData = 0x2F )
type DriverType ¶
type DriverType uint32
const ( DRIVER_OFF DriverType = 0x00 DRIVER_SILENT DriverType = 0x01 DRIVER_NORMAL DriverType = 0x04 DRIVER_SELFRECEPTION DriverType = 0x08 )
type Handle ¶
type Handle int32
Handle is a handle to a CAN channel (circuit).
func (Handle) FlushReceiveQueue ¶
func (Handle) FlushTransmitQueue ¶
func (Handle) ObjBufWrite ¶
func (Handle) Read ¶
func (h Handle) Read(msg *CANMessage) error
Read fetches the next queued frame into msg. msg must outlive the call on the heap (e.g. a struct field) or every call allocates it there.
func (Handle) ReadErrorCounters ¶
func (Handle) ReadWait ¶
func (h Handle) ReadWait(msg *CANMessage, timeout uint32) error
ReadWait is Read, waiting up to timeout ms for a frame.
func (Handle) SetAcceptanceFilter ¶
func (Handle) SetBitrate ¶
SetBitrate sets a custom bit rate. Linux canlib does not export canSetBitrate, so we fall back to canSetBusParams with conservative default bit-timing values that work for most standard rates. For non-standard rates that require precise timing, call SetBusParams directly with the desired tseg1/tseg2/sjw/noSamp values.
func (Handle) SetBusParams ¶
func (h Handle) SetBusParams(freq BusParamsFreq, tseg1, tseg2, sjw, noSamp, syncmode uint32) error
func (Handle) SetBusParamsC200 ¶
type MsgFlag ¶
type MsgFlag uint32
const ( MSG_MASK MsgFlag = 0xFF MSG_RTR MsgFlag = 0x01 MSG_STD MsgFlag = 0x02 MSG_EXT MsgFlag = 0x04 MSG_WAKEUP MsgFlag = 0x08 MSG_NERR MsgFlag = 0x10 MSG_ERROR_FRAME MsgFlag = 0x20 MSG_TXACK MsgFlag = 0x40 MSG_TXRQ MsgFlag = 0x80 MSG_DELAY_MSG MsgFlag = 0x100 MSG_LOCAL_TXACK MsgFlag = 0x10000000 MSG_SINGLE_SHOT MsgFlag = 0x1000000 MSG_TXNACK MsgFlag = 0x2000000 MSG_ABL MsgFlag = 0x4000000 FDMSG_MASK MsgFlag = 0xff0000 FDMSG_EDL MsgFlag = 0x10000 FDMSG_FDF MsgFlag = 0x10000 FDMSG_BRS MsgFlag = 0x20000 FDMSG_ESI MsgFlag = 0x40000 )
type OpenFlag ¶
type OpenFlag int32
const ( OPEN_EXCLUSIVE OpenFlag = 0x8 OPEN_REQUIRE_EXTENDED OpenFlag = 0x10 OPEN_ACCEPT_VIRTUAL OpenFlag = 0x20 OPEN_OVERRIDE_EXCLUSIVE OpenFlag = 0x40 OPEN_REQUIRE_INIT_ACCESS OpenFlag = 0x80 OPEN_NO_INIT_ACCESS OpenFlag = 0x100 OPEN_ACCEPT_LARGE_DLC OpenFlag = 0x200 OPEN_CAN_FD OpenFlag = 0x400 OPEN_CAN_FD_NONISO OpenFlag = 0x800 OPEN_INTERNAL_L OpenFlag = 0x1000 )