CAN related functions. More...

Data Structures

struct  kvBusParamsTq
 

Typedefs

typedef struct kvBusParamsTq kvBusParamsTq
 

Functions

canStatus canClose (const int hnd)
 
canStatus canBusOn (const int hnd)
 
canStatus canBusOff (const int hnd)
 
canStatus canSetBusParams (const int hnd, long freq, unsigned int tseg1, unsigned int tseg2, unsigned int sjw, unsigned int noSamp, unsigned int syncmode)
 
canStatus canSetBusParamsTq (const int hnd, const kvBusParamsTq nominal)
 
canStatus canSetBusParamsFd (const int hnd, long freq_brs, unsigned int tseg1_brs, unsigned int tseg2_brs, unsigned int sjw_brs)
 
canStatus canSetBusParamsFdTq (const int hnd, const kvBusParamsTq arbitration, const kvBusParamsTq data)
 
canStatus canGetBusParams (const int hnd, long *freq, unsigned int *tseg1, unsigned int *tseg2, unsigned int *sjw, unsigned int *noSamp, unsigned int *syncmode)
 
canStatus canGetBusParamsTq (const int hnd, kvBusParamsTq *nominal)
 
canStatus canGetBusParamsFd (const int hnd, long *freq_brs, unsigned int *tseg1_brs, unsigned int *tseg2_brs, unsigned int *sjw_brs)
 
canStatus canGetBusParamsFdTq (const int hnd, kvBusParamsTq *nominal, kvBusParamsTq *data)
 
canStatus canSetBusOutputControl (const int hnd, const unsigned int drivertype)
 
canStatus canGetBusOutputControl (const int hnd, unsigned int *drivertype)
 
canStatus canAccept (const int hnd, const long envelope, const unsigned int flag)
 
canStatus canReadStatus (const int hnd, unsigned long *const flags)
 
canStatus canReadErrorCounters (const int hnd, unsigned int *txErr, unsigned int *rxErr, unsigned int *ovErr)
 
canStatus canWrite (const int hnd, long id, void *msg, unsigned int dlc, unsigned int flag)
 
canStatus canWriteSync (const int hnd, unsigned long timeout)
 
canStatus canRead (const int hnd, long *id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time)
 
canStatus canReadWait (const int hnd, long *id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time, unsigned long timeout)
 
canStatus canReadSpecific (const int hnd, long id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time)
 
canStatus canReadSync (const int hnd, unsigned long timeout)
 
canStatus canReadSyncSpecific (const int hnd, long id, unsigned long timeout)
 
canStatus canReadSpecificSkip (const int hnd, long id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time)
 
canStatus canSetNotify (const int hnd, HWND aHWnd, unsigned int aNotifyFlags)
 
canStatus canTranslateBaud (long *const freq, unsigned int *const tseg1, unsigned int *const tseg2, unsigned int *const sjw, unsigned int *const nosamp, unsigned int *const syncMode)
 
canStatus kvBitrateToBusParamsTq (const canHandle hnd, int freq, kvBusParamsTq *nominal)
 
canStatus kvBitrateToBusParamsFdTq (const canHandle hnd, int freqA, int freqD, kvBusParamsTq *arbitration, kvBusParamsTq *data)
 
int canOpenChannel (int channel, int flags)
 
canStatus canSetBusParamsC200 (const int hnd, unsigned char btr0, unsigned char btr1)
 
canStatus canSetDriverMode (const int hnd, int lineMode, int resNet)
 
canStatus canGetDriverMode (const int hnd, int *lineMode, int *resNet)
 
canStatus canResetBus (const int hnd)
 
canStatus canWriteWait (const int hnd, long id, void *msg, unsigned int dlc, unsigned int flag, unsigned long timeout)
 
canStatus canSetAcceptanceFilter (const int hnd, unsigned int code, unsigned int mask, int is_extended)
 
canStatus canFlushReceiveQueue (const int hnd)
 
canStatus canFlushTransmitQueue (const int hnd)
 
canStatus canRequestChipStatus (const int hnd)
 
canStatus canRequestBusStatistics (const int hnd)
 
canStatus canGetBusStatistics (const int hnd, canBusStatistics *stat, size_t bufsiz)
 
canStatus canSetBitrate (const int hnd, int bitrate)
 
canStatus canGetHandleData (const int hnd, int item, void *buffer, size_t bufsize)
 

Detailed Description

CAN related functions.

Typedef Documentation

◆ kvBusParamsTq

typedef struct kvBusParamsTq kvBusParamsTq

Constraints

Constraints that must be fulfilled when opening channel in classic CAN Mode:

  tq         = 1 + prop + phase1 + phase2
  tq        >= 3
  sjw       <= min(phase1, phase2)
  prescaler >= 1
  Constraints that must be fulfilled when opening channel in CAN FD Mode:

  arbitration.tq         = 1 + arbitration.prop + arbitration.phase1 + arbitration.phase2
  arbitration.tq        >= 3
  arbitration.sjw       <= min(arbitration.phase1, arbitration.phase2)
  arbitration.prescaler >= 1  (<=2 will enable Transmitter Delay Compensation Mechanism)

  data.tq         = 1 + data.phase1 + data.phase2
  data.tq        >= 3
  data.sjw       <= min(data.phase1, data.phase2)
  data.prop       = 0
  data.prescaler  = arbitration.prescaler

Used in canSetBusParamsTq, canSetBusParamsFdTq, canGetBusParamsTq and canGetBusParamsTq

Function Documentation

◆ canAccept()

canStatus canAccept ( const int  hnd,
const long  envelope,
const unsigned int  flag 
)
C#
static Canlib.canStatus canAccept(CanHandle handle, Int32 envelope, Int32 flag);
Delphi
function canAccept(handle: canHandle; envelope: Longint; flag: Cardinal): canStatus;

This routine sets the message acceptance filters on a CAN channel.

On some boards the acceptance filtering is done by the CAN hardware; on other boards (typically those with an embedded CPU,) the acceptance filtering is done by software. canAccept() behaves in the same way for all boards, however.

canSetAcceptanceFilter() and canAccept() both serve the same purpose but the former can set the code and mask in just one call.

If you want to remove a filter, call canAccept() with the mask set to 0.

Note
You can set the extended code and mask only on CAN boards that support extended identifiers.
Acceptance filters for 11-bit and 29-bit (ext) are independent, meaning 11-bit filters will not affect 29-bit can frames and vice versa.
Not all CAN boards support different masks for standard and extended CAN identifiers.
Parameters
[in]hndAn open handle to a CAN circuit.
[in]envelopeThe mask or code to set.
[in]flagAny of canFILTER_SET_CODE_STD, canFILTER_SET_MASK_STD, canFILTER_SET_CODE_EXT or canFILTER_SET_MASK_EXT
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Acceptance Filters
canSetAcceptanceFilter()

◆ canBusOff()

canStatus canBusOff ( const int  hnd)
C#
static Canlib.canStatus canBusOff(CanHandle handle);
Delphi
function canBusOff(handle: canHandle): canStatus;

Takes the specified handle off-bus. If no other handle is active on the same channel, the channel will also be taken off-bus

Parameters
[in]hndAn open handle to a CAN channel.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Bus On / Bus Off
canBusOn(), canResetBus()
Examples:
example/c/candump.c, example/c/canecho.c, example/c/gensig/gensig.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, tutorial/c/MonitorCanChannel.c, and tutorial/c/SendMessage.c.

◆ canBusOn()

canStatus canBusOn ( const int  hnd)
C#
static Canlib.canStatus canBusOn(CanHandle handle);
Delphi
function canBusOn(handle: canHandle): canStatus;

Takes the specified channel on-bus.

If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call canBusOn() once for each handle. The same applies to canBusOff() - the physical channel will not go off bus until the last handle to the channel goes off bus.

Parameters
[in]hndAn open handle to a CAN channel.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Bus On / Bus Off
canBusOff(), canResetBus()
Examples:
example/c/candump.c, example/c/canecho.c, example/c/gensig/gensig.c, example/c/thread.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, tutorial/c/MonitorCanChannel.c, and tutorial/c/SendMessage.c.

◆ canClose()

canStatus canClose ( const int  hnd)
C#
static Canlib.canStatus canClose(CanHandle handle);
Delphi
function canClose(handle: canHandle): canStatus;

Closes the channel associated with the handle. If no other threads are using the CAN circuit, it is taken off bus. The handle can not be used for further references to the channel, so any variable containing it should be zeroed.

canClose() will almost always return canOK; the specified handle is closed on an best-effort basis.

Parameters
[in]hndAn open handle to a CAN channel.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Close Channel
canOpenChannel(), canBusOn(), canBusOff()
Examples:
example/c/busparams_tq.c, example/c/candump.c, example/c/canecho.c, example/c/channeldata.c, example/c/gensig/gensig.c, example/c/kvdiag/autobaud.c, example/c/kvdiag/normal.c, example/c/kvrConfig.c, example/c/read_customer_data.c, example/c/tscript/envvar/envvar.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, tutorial/c/MonitorCanChannel.c, and tutorial/c/SendMessage.c.

◆ canFlushReceiveQueue()

canStatus canFlushReceiveQueue ( const int  hnd)
C#
static Canlib.canStatus canFlushReceiveQueue(CanHandle hnd);
Delphi
function canFlushReceiveQueue(handle: canHandle): canStatus;

This function removes all received messages from the handle's receive queue. Other handles open to the same channel are not affected by this operation. That is, only the messages belonging to the handle you are passing to canFlushReceiveQueue are discarded.

Note
This call has the same effect as calling canIoCtl() with a function code of canIOCTL_FLUSH_RX_BUFFER.
Parameters
[in]hndA handle to an open circuit.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canFlushTransmitQueue()

◆ canFlushTransmitQueue()

canStatus canFlushTransmitQueue ( const int  hnd)
C#
static Canlib.canStatus canFlushTransmitQueue(CanHandle hnd);
Delphi
function canFlushTransmitQueue(handle: canHandle): canStatus;

This function removes all messages pending transmission from the transmit queue of the circuit.

Note
If there are other handles open to the same circuit, they are also flushed.
This call has the same effect as calling canIoCtl() with a function code of canIOCTL_FLUSH_TX_BUFFER.
Parameters
[in]hndA handle to an open circuit.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canFlushReceiveQueue()

◆ canGetBusOutputControl()

canStatus canGetBusOutputControl ( const int  hnd,
unsigned int *  drivertype 
)
C#
static Canlib.canStatus canGetBusOutputControl(CanHandle handle, out Int32 drivertype);
Delphi
function canGetBusOutputControl(handle: canHandle; var drivertype: Cardinal): canStatus;

This function retrieves the current CAN controller driver type. This corresponds loosely to the bus output control register in the CAN controller, hence the name of this function. CANlib does not allow for direct manipulation of the bus output control register; instead, symbolic constants are used to select the desired driver type.

Note
Don't confuse the CAN controller driver type with the bus driver type. The CAN controller is not connected directly to the CAN bus; instead, it is connected to a bus transceiver circuit which interfaces directly to the bus. The "CAN controller driver type" we are talking about here refers to the mode which the CAN controller uses to drive the bus transceiver circuit.
Silent Mode is not supported by all CAN controllers.
Parameters
[in]hndAn open handle to a CAN circuit.
[out]drivertypeA pointer to an unsigned int which receives the current driver type. The driver type can be either canDRIVER_NORMAL or canDRIVER_SILENT.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canSetBusOutputControl()
Examples:
example/c/channeldata.c.

◆ canGetBusParams()

canStatus canGetBusParams ( const int  hnd,
long *  freq,
unsigned int *  tseg1,
unsigned int *  tseg2,
unsigned int *  sjw,
unsigned int *  noSamp,
unsigned int *  syncmode 
)
C#
static Canlib.canStatus canGetBusParams(CanHandle handle, out Int64 freq, out Int32 tseg1, out Int32 tseg2, out Int32 sjw, out Int32 noSamp);
Delphi
function canGetBusParams(handle: canHandle; var freq: Longint; var tseg1, tseg2, sjw, noSamp, syncmode: Cardinal): canStatus;

This function retrieves the current nominal bus parameters for the specified channel.

The anatomy of a CAN bit is discussed in detail at Kvaser's web site at www.kvaser.com.

Parameters
[in]hndAn open handle to a CAN controller.
[out]freqBit rate (bits per second).
[out]tseg1Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point.
[out]tseg2Time segment 2, that is, the number of quanta from the sampling point to the end of the bit.
[out]sjwThe Synchronization Jump Width.
[out]noSampThe number of sampling points; can be 1 or 3.
[out]syncmodeUnsupported, always read as one.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Set CAN Bitrate, Set CAN Bitrate
canSetBusParams(), canSetBusParamsC200()

◆ canGetBusParamsFd()

canStatus canGetBusParamsFd ( const int  hnd,
long *  freq_brs,
unsigned int *  tseg1_brs,
unsigned int *  tseg2_brs,
unsigned int *  sjw_brs 
)
C#
static Canlib.canStatus canGetBusParamsFd(CanHandle handle, out Int64 freq_brs, out Int32 tseg1_brs, out Int32 tseg2_brs, out Int32 sjw_brs);
Delphi
function canGetBusParamsFd(hnd: canHandle; var freq_brs: Longint; var tseg1_brs, tseg2_brs, sjw_brs: Cardinal): canStatus;

This function retrieves the current data bus parameters for the specified CAN FD channel.

Parameters
[in]hndAn open handle to a CAN FD controller.
[out]freq_brsBit rate (bits per second).
[out]tseg1_brsTime segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point.
[out]tseg2_brsTime segment 2, that is, the number of quanta from the sampling point to the end of the bit.
[out]sjw_brsThe Synchronization Jump Width.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure

◆ canGetBusParamsFdTq()

canStatus canGetBusParamsFdTq ( const int  hnd,
kvBusParamsTq nominal,
kvBusParamsTq data 
)
C#
static Canlib.canStatus canGetBusParamsFdTq(CanHandle handle, out kvBusParamsTq nominal, out kvBusParamsTq data);
Delphi
function canGetBusParamsFdTq(handle: canHandle; var nominal: kvBusParamsTq; var data: kvBusParamsTq): canStatus;

Get bus parameters for the specified CAN controller.

If the channel is NOT opened (see canOpenChannel()) with flags canOPEN_CAN_FD or canOPEN_CAN_FD_NONISO, use canGetBusParamsTq() instead.

Parameters
[in]hndA handle to an open CAN circuit.
[out]nominalSee kvBusParamsTq.
[out]dataSee kvBusParamsTq.

return canOK (zero) if success return canERR_xxx (negative) if failure

Examples:
example/c/busparams_tq.c.

◆ canGetBusParamsTq()

canStatus canGetBusParamsTq ( const int  hnd,
kvBusParamsTq nominal 
)
C#
static Canlib.canStatus canGetBusParamsTq(CanHandle handle, out kvBusParamsTq nominal);
Delphi
function canGetBusParamsTq(handle: canHandle; var nominal: kvBusParamsTq): canStatus;

Get bus parameters for the specified CAN controller.

If the channel is opened (see canOpenChannel()) with flags canOPEN_CAN_FD or canOPEN_CAN_FD_NONISO, use canGetBusParamsFdTq() instead.

Parameters
[in]hndA handle to an open CAN circuit.
[out]nominalSee kvBusParamsTq.

return canOK (zero) if success return canERR_xxx (negative) if failure

Examples:
example/c/busparams_tq.c.

◆ canGetBusStatistics()

canStatus canGetBusStatistics ( const int  hnd,
canBusStatistics stat,
size_t  bufsiz 
)
C#
static Canlib.canStatus canGetBusStatistics(CanHandle hnd, out Canlib.canBusStatistics stat);
Delphi
function canGetBusStatistics(handle: canHandle; var stat: canBusStatistics; bufsiz: size_t): canStatus;

The canGetBusStatistics() function retrieves the latest bus statistics figures reported by the driver. You request the bus statistics from the driver by calling the canRequestBusStatistics() function.

Parameters
[in]hndAn open handle to a CAN channel.
[out]statA pointer to a canBusStatistics struct that will receive the bus statistics figures.
[in]bufsizThe size, in bytes, of the stat buffer.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canRequestBusStatistics()

◆ canGetDriverMode()

canStatus canGetDriverMode ( const int  hnd,
int *  lineMode,
int *  resNet 
)
C#
static Canlib.canStatus canGetDriverMode(CanHandle hnd, out Int32 lineMode, out Int32 resNet);
Delphi
function canGetDriverMode(hnd: canHandle; var lineMode: Integer; var resNet: Integer): canStatus;

This function retrieves the current CAN bus driver mode. This is typically a mode like sleep, wakeup, standby, fast mode, etc. The different modes are almost always hardware dependent and requires special DRVcan cables. As an example, the DRVcan S implements J2411 compliant single-wire CAN and supports four line modes, namely Normal, Sleep, Fast and Wakeup.

Standard ISO 11898 CAN do not support any of these bus driver modes.

Note
The bus driver mode is typically used to control things like one- or two-wire mode, sleep mode, and so on. It requires special support in the CAN driver circuit.
Parameters
[in]hndAn open handle to a CAN circuit.
[out]lineModeA pointer to an int which receives the current line mode (canTRANSCEIVER_LINEMODE_xxx).
[out]resNetA pointer to an int which receives the current resnet mode. This value is usually canTRANSCEIVER_RESNET_NA except for special DRVcan cables.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canSetDriverMode()
Note
Not implemented in linux.

◆ canGetHandleData()

canStatus canGetHandleData ( const int  hnd,
int  item,
void *  buffer,
size_t  bufsize 
)
C#
static Canlib.canStatus canGetHandleData(CanHandle hnd, Int32 item, out object buffer);
Delphi
function canGetHandleData(handle: canHandle; item: Integer; var Buffer; bufsize: size_t): canStatus;
Note
This function can be used to retrieve certain pieces of information about an open handle to a CANlib channel.
Parameters
[in]hndAn open handle to a CAN channel.
[in]itemThis parameter specifies what data to obtain for the specified handle. The value is one of the constants canCHANNELDATA_xxx
[out]bufferThe address of a buffer which is to receive the data.
[in]bufsizeThe size of the buffer to which the buffer parameter points.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Channel Information
canGetChannelData()

◆ canOpenChannel()

int canOpenChannel ( int  channel,
int  flags 
)
C#
static CanHandle canOpenChannel(Int32 channel, Int32 flags);
Delphi
function canOpenChannel(channel: Integer; flags: Integer): canHandle;

Opens a CAN channel (circuit) and returns a handle which is used in subsequent calls to CANlib.

Channel numbering is dependent on the installed hardware. The first channel always has number 0.

For example,

  • If you have a single LAPcan, the channels are numbered 0 and 1.
  • If you have a USBcan Professional, the channels are numbered 0-1 according to the labels on the cables.
  • The virtual channels come after all physical channels.

If you are using multiple threads, note that the returned handle is usable only in the context of the thread that created it. That is, you must call canOpenChannel() in each of the threads in your application that uses the CAN bus. You can open the same channel from multiple threads, but you must call canOpenChannel() once per thread.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

Note
The handle returned may be zero which is perfectly valid.
Parameters
[in]channelThe number of the channel. Channel numbering is hardware dependent.
[in]flagsA combination of canOPEN_xxx flags
Returns
Returns a handle to the opened circuit, or canERR_xxx (negative) if the call failed.
See also
Open Channel, Virtual Channels
canClose(), canGetNumberOfChannels(), canGetChannelData(), canIoCtl()
Examples:
example/c/busparams_tq.c, example/c/candump.c, example/c/canecho.c, example/c/channeldata.c, example/c/gensig/gensig.c, example/c/kvdiag/autobaud.c, example/c/kvdiag/normal.c, example/c/kvrConfig.c, example/c/read_customer_data.c, example/c/thread.c, example/c/tscript/envvar/envvar.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, how-to/c/openChannels.c, tutorial/c/MonitorCanChannel.c, and tutorial/c/SendMessage.c.

◆ canRead()

canStatus canRead ( const int  hnd,
long *  id,
void *  msg,
unsigned int *  dlc,
unsigned int *  flag,
unsigned long *  time 
)
C#
static Canlib.canStatus canRead(CanHandle handle, out Int32 id, Byte[] msg, out Int32 dlc, out Int32 flag, out Int64 time);
Delphi
function canRead(handle: canHandle; var id: Longint; msg: Pointer; var dlc: Cardinal; var flag: Cardinal; var time: Cardinal): canStatus;

Reads a message from the receive buffer. If no message is available, the function returns immediately with return code canERR_NOMSG.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

It is allowed to pass NULL as the value of id, msg, dlc, flag, and time.

Parameters
[in]hndA handle to an open circuit.
[out]idPointer to a buffer which receives the CAN identifier. This buffer will only get the identifier. To determine whether this identifier was standard (11-bit) or extended (29-bit), and/or whether it was remote or not, or if it was an error frame, examine the contents of the flag argument.
[out]msgPointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes for classic CAN and up to 64 bytes for CAN FD).
[out]dlcPointer to a buffer which receives the message length.
[out]flagPointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx (including canFDMSG_xxx if the CAN FD protocol is enabled) and canMSGERR_xxx values.
[out]timePointer to a buffer which receives the message time stamp.
Returns
canOK (zero) if a message was read.
canERR_NOMSG (negative) if there was no message available.
canERR_xxx (negative) if failure
See also
Reading Messages, Message Mailboxes, Reading Messages page_user_guide_time Time Measurement
canReadSpecific(), canReadSpecificSkip(), canReadSync(), canReadSyncSpecific(), canReadWait()
Examples:
example/c/candump.c, example/c/thread.c, and example/cpp/candemo/candemo.cpp.

◆ canReadErrorCounters()

canStatus canReadErrorCounters ( const int  hnd,
unsigned int *  txErr,
unsigned int *  rxErr,
unsigned int *  ovErr 
)
C#
static Canlib.canStatus canReadErrorCounters(CanHandle handle, out Int32 txErr, out Int32 rxErr, out Int32 ovErr);
Delphi
function canReadErrorCounters(handle: canHandle; var txErr, rxErr, ovErr: Cardinal): canStatus;

Reads the error counters of the CAN controller.

canReadErrorCounters() returns the latest known values of the error counters in the specified circuit. If the error counters change values precisely when canReadErrorCounters() is called, it may not be reflected in the returned result.

It is allowed to pass NULL as the value of the txErr, rxErr, and ovErr parameters.

Use canIoCtl() to clear the counters.

Note
Not all CAN controllers provide access to the error counters; in this case, an educated guess is returned.
Parameters
[in]hndA handle to an open circuit.
[out]txErrA pointer to a DWORD which receives the transmit error counter.
[out]rxErrA pointer to a DWORD which receives the receive error counter.
[out]ovErrA pointer to a DWORD which receives the number of overrun errors.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canIoCtl()

◆ canReadSpecific()

canStatus canReadSpecific ( const int  hnd,
long  id,
void *  msg,
unsigned int *  dlc,
unsigned int *  flag,
unsigned long *  time 
)
C#
static Canlib.canStatus canReadSpecific(CanHandle handle, Int32 id, Byte[] msg, out Int32 dlc, out Int32 flag, out Int64 time);
Delphi
function canReadSpecific(handle: canHandle; id: Longint; msg: Pointer; var dlc: Cardinal; var flag: Cardinal; var time: Cardinal): canStatus;

Reads a message with a specified identifier from the receive buffer. Any preceding message not matching the specified identifier will be kept in the receive buffer. If no message with the specified identifier is available, the function returns immediately with an error code.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

It is allowed to pass NULL as the value of msg, dlc, flag, and time.

Note
Use canReadSpecific only if you for some reason must keep the unread messages in the queue. If this is not the case, consider using canReadSpecificSkip() or canRead() for better performance.
Parameters
[in]hndA handle to an open circuit.
[in]idThe desired CAN identifier.
[out]msgPointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes for classic CAN and up to 64 bytes for CAN FD).
[out]dlcPointer to a buffer which receives the message length.
[out]flagPointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx (including canFDMSG_xxx if the CAN FD protocol is enabled) and canMSGERR_xxx values.
[out]timePointer to a buffer which receives the message time stamp.
Returns
canOK (zero) if a message was read.
canERR_NOMSG (negative) if a matching message was not found. There might be other messages in the queue, though.
canERR_xxx (negative) if failure
See also
Message Mailboxes, Reading Messages, Time Measurement Time Measurement
canRead(), canReadSpecificSkip(), canReadSync(), canReadSyncSpecific(), canReadWait()

◆ canReadSpecificSkip()

canStatus canReadSpecificSkip ( const int  hnd,
long  id,
void *  msg,
unsigned int *  dlc,
unsigned int *  flag,
unsigned long *  time 
)
C#
static Canlib.canStatus canReadSpecificSkip(CanHandle hnd, Int32 id, Byte[] msg, out Int32 dlc, out Int32 flag, out Int64 time);
Delphi
function canReadSpecificSkip(handle: canHandle; id: Longint; msg: Pointer; var dlc: Cardinal; var flag: Cardinal; var time: Cardinal): canStatus;

Reads a message with a specified identifier from the receive buffer. Any preceding message not matching the specified identifier will be removed in the receive buffer. If no message with the specified identifier is available, the function returns immediately with an error code.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

It is allowed to pass NULL as the value of msg, dlc, flag, and time.

Parameters
[in]hndA handle to an open circuit.
[in]idThe desired CAN identifier.
[out]msgPointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes for classic CAN and up to 64 bytes for CAN FD).
[out]dlcPointer to a buffer which receives the message length.
[out]flagPointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx (including canFDMSG_xxx if the CAN FD protocol is enabled) and canMSGERR_xxx values.
[out]timePointer to a buffer which receives the message time stamp.
Returns
canOK (zero) if a matching message was found.
canERR_NOMSG if there was no matching message available. All other messages (if any!) were discarded.
canERR_xxx (negative) if failure
See also
Reading Messages, Time Measurement Time Measurement
canRead(), canReadSpecific(), canReadSync(), canReadSyncSpecific(), canReadWait()

◆ canReadStatus()

canStatus canReadStatus ( const int  hnd,
unsigned long *const  flags 
)
C#
static Canlib.canStatus canReadStatus(CanHandle handle, out Int64 flags);
Delphi
function canReadStatus(handle: canHandle; var flags: Cardinal): canStatus;

Returns the status for the specified circuit. flags points to a longword which receives a combination of the canSTAT_xxx flags.

Note
canReadStatus() returns the latest known status of the specified circuit. If a status change happens precisely when canReadStatus() is called, it may not be reflected in the returned result.
Parameters
[in]hndA handle to an open circuit.
[out]flagsPointer to a DWORD which receives the status flags; this is a combination of any of the canSTAT_xxx.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
Examples:
example/c/channeldata.c, and example/cpp/candemo/candemo.cpp.

◆ canReadSync()

canStatus canReadSync ( const int  hnd,
unsigned long  timeout 
)
C#
static Canlib.canStatus canReadSync(CanHandle handle, Int64 timeout);
Delphi
function canReadSync(handle: canHandle; timeout: Cardinal): canStatus;

Waits until the receive buffer contains at least one message or a timeout occurs.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

Parameters
[in]hndA handle to an open circuit.
[in]timeoutThe timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout.
Returns
canOK (zero) if the queue contains the desired message.
canERR_TIMEOUT (negative) if a timeout occurs before a message arrived.
canERR_xxx (negative) if the call fails.
See also
canRead(), canReadSpecific(), canReadSpecificSkip(), canReadSyncSpecific(), canReadWait()

◆ canReadSyncSpecific()

canStatus canReadSyncSpecific ( const int  hnd,
long  id,
unsigned long  timeout 
)
C#
static Canlib.canStatus canReadSyncSpecific(CanHandle handle, Int32 id, Int64 timeout);
Delphi
function canReadSyncSpecific(handle: canHandle; id: Longint; timeout: Cardinal): canStatus;

Waits until the receive queue contains a message with the specified id, or a timeout occurs..

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

Parameters
[in]hndA handle to an open circuit.
[in]idThe desired message identifier.
[in]timeoutThe timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout.
Returns
canOK (zero) if the queue contains the desired message.
canERR_TIMEOUT (negative) if a timeout occurs before the specified message arrived.
canERR_xxx (negative) if the call fails.
See also
canRead(), canReadSpecific(), canReadSpecificSkip(), canReadSync(), canReadWait()
Examples:
example/c/thread.c.

◆ canReadWait()

canStatus canReadWait ( const int  hnd,
long *  id,
void *  msg,
unsigned int *  dlc,
unsigned int *  flag,
unsigned long *  time,
unsigned long  timeout 
)
C#
static Canlib.canStatus canReadWait(CanHandle handle, out Int32 id, Byte[] msg, out Int32 dlc, out Int32 flag, out Int64 time, Int64 timeout);
Delphi
function canReadWait(handle: canHandle; var id: Longint; msg: Pointer; var dlc: Cardinal; var flag: Cardinal; var time: Cardinal; timeout: Cardinal): canStatus;

Reads a message from the receive buffer. If no message is available, the function waits until a message arrives or a timeout occurs.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

It is allowed to pass NULL as the value of id, msg, dlc, flag, and time.

Parameters
[in]hndA handle to an open circuit.
[out]idPointer to a buffer which receives the CAN identifier. This buffer will only get the identifier. To determine whether this identifier was standard (11-bit) or extended (29-bit), and/or whether it was remote or not, or if it was an error frame, examine the contents of the flag argument.
[out]msgPointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes for classic CAN and up to 64 bytes for CAN FD).
[out]dlcPointer to a buffer which receives the message length.
[out]flagPointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx (including canFDMSG_xxx if the CAN FD protocol is enabled) and canMSGERR_xxx values.
[out]timePointer to a buffer which receives the message time stamp.
[in]timeoutIf no message is immediately available, this parameter gives the number of milliseconds to wait for a message before returning. 0xFFFFFFFF gives an infinite timeout.
Returns
canOK (zero) if a message was read.
canERR_NOMSG (negative) if there was no message available.
canERR_xxx (negative) if failure
See also
canRead(), canReadSpecific(), canReadSpecificSkip(), canReadSyncSpecific(), canReadSync()
Time Measurement Time Measurement
Examples:
example/c/canecho.c, and tutorial/c/MonitorCanChannel.c.

◆ canRequestBusStatistics()

canStatus canRequestBusStatistics ( const int  hnd)
C#
static Canlib.canStatus canRequestBusStatistics(CanHandle hnd);
Delphi
function canRequestBusStatistics(handle: canHandle): canStatus;

The canRequestBusStatistics function requests bus statistics from the hardware. The bus statistics figures can be retrieved later by a call to the canGetBusStatistics function.

Note
The time between a call to canRequestBusStatistics() and the point in time where the bus statistics is actually available via a call to canGetBusStatistics() is not defined. Typically, you would call canRequestBusStatistics() from your application periodically (for example, once per second) to request the data from the driver and then call canGetBusStatistics() with the same rate to obtain the latest reported data.
Parameters
[in]hndAn open handle to a CAN channel.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canGetBusStatistics()

◆ canRequestChipStatus()

canStatus canRequestChipStatus ( const int  hnd)
C#
static Canlib.canStatus canRequestChipStatus(CanHandle hnd);
Delphi
function canRequestChipStatus(handle: canHandle): canStatus;

The canRequestChipStatus function requests that the hardware report the chip status (bus on/error passive status etc.) to the driver. The chip status can later be retrieved using the canReadStatus() function.

Note
The canRequestChipStatus() function is asynchronous, that is, it completes before the answer is returned from the hardware. The time between a call to canRequestChipStatus() and the point in time where the chip status is actually available via a call to canReadStatus() is not defined. canReadStatus() always returns the latest data reported by the hardware.
Parameters
[in]hndAn open handle to a CAN channel.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canReadStatus()
Examples:
example/cpp/candemo/candemo.cpp.

◆ canResetBus()

canStatus canResetBus ( const int  hnd)
C#
static Canlib.canStatus canResetBus(CanHandle handle);
Delphi
function canResetBus(handle: canHandle): canStatus;

This function tries to reset a CAN bus controller by taking the channel off bus and then on bus again (if it was on bus before the call to canResetBus().)

This function will affect the hardware (and cause a real reset of the CAN chip) only if hnd is the only handle open on the channel. If there are other open handles, this operation will not affect the hardware.

Parameters
[in]hndA handle to an open circuit.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canBusOn(), canBusOff()

◆ canSetAcceptanceFilter()

canStatus canSetAcceptanceFilter ( const int  hnd,
unsigned int  code,
unsigned int  mask,
int  is_extended 
)
C#
static Canlib.canStatus canSetAcceptanceFilter(CanHandle hnd, Int32 code, Int32 mask, Int32 is_extended);
Delphi
function canSetAcceptanceFilter(handle: canHandle; code, mask: Cardinal; is_extended: Integer): canStatus;

This routine sets the message acceptance filters on a CAN channel.

Format of code and mask:

  • A binary 1 in a mask means "the corresponding bit in the code is relevant"
  • A binary 0 in a mask means "the corresponding bit in the code is not relevant"
  • A relevant binary 1 in a code means "the corresponding bit in the identifier must be 1"
  • A relevant binary 0 in a code means "the corresponding bit in the identifier must be 0"

In other words, the message is accepted if ((code XOR id) AND mask) == 0.

extended should be set to:

  • 0 (FALSE): if the code and mask shall apply to 11-bit CAN identifiers.
  • 1 (TRUE): if the code and mask shall apply to 29-bit CAN identifiers.

If you want to remove a filter, call canSetAcceptanceFilter() with the mask set to 0.

On some boards the acceptance filtering is done by the CAN hardware; on other boards (typically those with an embedded CPU,) the acceptance filtering is done by software. canSetAcceptanceFilter() behaves in the same way for all boards, however.

canSetAcceptanceFilter() and canAccept() both serve the same purpose but the former can set the code and mask in just one call.

Note
You can set the extended code and mask only on CAN boards that support extended identifiers.
Acceptance filters for 11-bit and 29-bit (ext) are independent, meaning 11-bit filters will not affect 29-bit can frames and vice versa.
Not all CAN boards support different masks for standard and extended CAN identifiers.
Not implemented in linux.
Parameters
[in]hndAn open handle to a CAN circuit.
[in]codeThe acceptance code to set.
[in]maskThe acceptance mask to set.
[in]is_extendedSelect 29-bit CAN identifiers.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Acceptance Filters
canAccept()

◆ canSetBitrate()

canStatus canSetBitrate ( const int  hnd,
int  bitrate 
)
C#
static Canlib.canStatus canSetBitrate(CanHandle hnd, Int32 bitrate);
Delphi
function canSetBitrate(handle: canHandle; bitrate: Integer): canStatus;

The canSetBitrate() function sets the nominal bit rate of the specified CAN channel. The sampling point is recalculated and kept as close as possible to the value before the call.

Parameters
[in]hndAn open handle to a CAN channel.
[in]bitrateThe new bit rate, in bits/second.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canSetBusParamsC200(), canSetBusParams(), canGetBusParams()

◆ canSetBusOutputControl()

canStatus canSetBusOutputControl ( const int  hnd,
const unsigned int  drivertype 
)
C#
static Canlib.canStatus canSetBusOutputControl(CanHandle handle, Int32 drivertype);
Delphi
function canSetBusOutputControl(handle: canHandle; drivertype: Cardinal): canStatus;

This function sets the driver type for a CAN controller. This corresponds loosely to the bus output control register in the CAN controller, hence the name of this function. CANlib does not allow for direct manipulation of the bus output control register; instead, symbolic constants are used to select the desired driver type.

Note
Not all CAN driver types are supported on all cards.
Parameters
[in]hndA handle to an open circuit.
[in]drivertypeCan driver type, canDRIVER_xxx)
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canGetBusOutputControl()
Examples:
example/cpp/candemo/candemo.cpp.

◆ canSetBusParams()

canStatus canSetBusParams ( const int  hnd,
long  freq,
unsigned int  tseg1,
unsigned int  tseg2,
unsigned int  sjw,
unsigned int  noSamp,
unsigned int  syncmode 
)
C#
static Canlib.canStatus canSetBusParams(CanHandle handle, Int32 freq, Int32 tseg1, Int32 tseg2, Int32 sjw, Int32 noSamp);
Delphi
function canSetBusParams(handle: canHandle; freq: Longint; tseg1, tseg2, sjw, noSamp, syncmode: Cardinal): canStatus;

This function sets the nominal bus timing parameters for the specified CAN controller.

The library provides default values for tseg1, tseg2, sjw and noSamp when freq is specified to one of the pre-defined constants, canBITRATE_xxx for classic CAN and canFD_BITRATE_xxx for CAN FD.

If freq is any other value, no default values are supplied by the library.

If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call canBusOff() once for each handle. The same applies to canBusOn() - the physical channel will not go off bus until the last handle to the channel goes off bus.

Note
The value of sjw should normally be less than tseg1 and tseg2.

Use canSetBusParamsC200() to set the bus timing parameters in the ubiquitous 82c200 bit-timing register format.

Parameters
[in]hndAn open handle to a CAN controller.
[in]freqBit rate (measured in bits per second); or one of the predefined constants (canBITRATE_xxx for classic CAN and canFD_BITRATE_xxx for CAN FD).
[in]tseg1Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point.
[in]tseg2Time segment 2, that is, the number of quanta from the sampling point to the end of the bit.
[in]sjwThe Synchronization Jump Width.
[in]noSampThe number of sampling points; can be 1 or 3.
[in]syncmodeUnsupported and ignored.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Set CAN Bitrate, Set CAN FD Bitrate,
canSetBusParamsFd(), canSetBusParamsC200(), canGetBusParams()
canSetBusParamsTq(), canSetBusParamsFdTq(), canGetBusParamsTq()
Examples:
example/c/candump.c, example/c/canecho.c, example/c/gensig/gensig.c, example/c/thread.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, how-to/c/openChannels.c, tutorial/c/MonitorCanChannel.c, and tutorial/c/SendMessage.c.

◆ canSetBusParamsC200()

canStatus canSetBusParamsC200 ( const int  hnd,
unsigned char  btr0,
unsigned char  btr1 
)
C#
static Canlib.canStatus canSetBusParamsC200(CanHandle hnd, byte btr0, byte btr1);
Delphi
function canSetBusParamsC200(hnd: canHandle; btr0, btr1: byte): canStatus;

This function sets the bus timing parameters using the same convention as the 82c200 CAN controller (which is the same as many other CAN controllers, for example, the 82527.)

To calculate the bit timing parameters, you can use the bit timing calculator that is included with CANlib SDK. Look in the BIN directory.

82c200 Bit Timing

  • btr0 [b7..b6]: SJW - 1
  • btr0 [b5..b0]: Prescaler -1
  • btr1 [b7]: 1: 3 samples, 0: 1 samples
  • btr1 [b6..b4]: tseg2 - 1
  • btr1 [b3..b0]: tseg1 - 2
Note
CANlib will always behave as if the clock frequency is 16 MHz. It does not matter if the device has a different physical clock, since this will be compensated for by the driver.
Parameters
[in]hndA handle to an open CAN circuit.
[in]btr0The desired bit timing, formatted as the contents of the BTR0 register in the 82c200.
[in]btr1The desired bit timing, formatted as the contents of the BTR1 register in the 82c200.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Set CAN Bitrate, canSetBusParams()
canSetBusParamsTq()
Examples:
example/c/gensig/gensig.c.

◆ canSetBusParamsFd()

canStatus canSetBusParamsFd ( const int  hnd,
long  freq_brs,
unsigned int  tseg1_brs,
unsigned int  tseg2_brs,
unsigned int  sjw_brs 
)
C#
static Canlib.canStatus canSetBusParamsFd(CanHandle handle, Int32 freq_brs, Int32 tseg1_brs, Int32 tseg2_brs, Int32 sjw_brs);
Delphi
function canSetBusParamsFd(hnd: canHandle; freq_brs: Longint; tseg1_brs, tseg2_brs, sjw_brs: Cardinal): canStatus;

This function sets the data phase bus timing parameters for the specified CAN controller.

The library provides default values for tseg1_brs, tseg2_brs and sjw_brs when freq_brs is specified to one of the pre-defined constants, canFD_BITRATE_xxx.

If freq_brs is any other value, no default values are supplied by the library.

Parameters
[in]hndAn open handle to a CAN controller.
[in]freq_brsCAN FD data bit rate (measured in bits per second); or one of the predefined constants canFD_BITRATE_xxx.
[in]tseg1_brsTime segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point.
[in]tseg2_brsTime segment 2, that is, the number of quanta from the sampling point to the end of the bit.
[in]sjw_brsThe Synchronization Jump Width.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canSetBusParamsFdTq(), canGetBusParamsFdTq()
Examples:
example/c/candump.c, and how-to/c/openChannels.c.

◆ canSetBusParamsFdTq()

canStatus canSetBusParamsFdTq ( const int  hnd,
const kvBusParamsTq  arbitration,
const kvBusParamsTq  data 
)
C#
static Canlib.canStatus canSetBusParamsFdTq(CanHandle handle, kvBusParamsTq arbitration, kvBusParamsTq data);
Delphi
function canSetBusParamsFdTq(hnd: canHandle; arbitration: kvBusParamsTq; data: kvBusParamsTq): canStatus;

Set bus parameters for the specified CAN controller.

The channel MUST be opened with flags canOPEN_CAN_FD or canOPEN_CAN_FD_NONISO, see canOpenChannel(). In the case of classic can, use canSetBusParamsTq() instead.

To get device specific limits of bus parameters, see canCHANNELDATA_BUS_PARAM_LIMITS.

The Kvaser Bit Timing calculator, available on the Kvaser website, can be used to calculate specific bit rates.

Parameters
[in]hndA handle to an open CAN circuit.
[in]arbitrationSee kvBusParamsTq
[in]dataSee kvBusParamsTq

return canOK (zero) if success return canERR_xxx (negative) if failure

Examples:
example/c/busparams_tq.c.

◆ canSetBusParamsTq()

canStatus canSetBusParamsTq ( const int  hnd,
const kvBusParamsTq  nominal 
)
C#
static Canlib.canStatus canSetBusParamsTq(CanHandle handle, kvBusParamsTq nominal);
Delphi
function canSetBusParamsTq(hnd: canHandle; nominal: kvBusParamsTq): canStatus;

Set bus parameters for the specified CAN controller (classic CAN).

If the channel is opened (see canOpenChannel()) with flags canOPEN_CAN_FD or canOPEN_CAN_FD_NONISO, use canSetBusParamsFdTq() instead.

To get device specific limits of bus parameters, see canCHANNELDATA_BUS_PARAM_LIMITS.

The Kvaser Bit Timing calculator, available on the Kvaser website, can be used to calculate specific bit rates.

Parameters
[in]hndA handle to an open CAN circuit.
[in]nominalSee kvBusParamsTq

return canOK (zero) if success return canERR_xxx (negative) if failure

Examples:
example/c/busparams_tq.c.

◆ canSetDriverMode()

canStatus canSetDriverMode ( const int  hnd,
int  lineMode,
int  resNet 
)
C#
static Canlib.canStatus canSetDriverMode(CanHandle hnd, Int32 lineMode, Int32 resNet);
Delphi
function canSetDriverMode(hnd: canHandle; lineMode, resNet: Integer): canStatus;

This function sets the current CAN bus driver mode. This is typically a mode like sleep, wakeup, standby, fast mode, etc. The different modes are almost always hardware dependent and requires special DRVcan cables. As an example, the DRVcan S implements J2411 compliant single-wire CAN and supports four line modes, namely Normal, Sleep, Fast and Wakeup.

Standard ISO 11898 CAN do not support any of these bus driver modes.

Note
The bus driver mode is typically used to control things like one- or two-wire mode, sleep mode, and so on. It requires special support in the CAN driver circuit.
Parameters
[in]hndAn open handle to a CAN circuit.
[in]lineModeAn int which defines the line mode, canTRANSCEIVER_LINEMODE_xxx.
[in]resNetAn int which defines the resnet mode. Set this parameter to canTRANSCEIVER_RESNET_NA unless you have good reasons to set it to something else.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canGetDriverMode()
Note
Not implemented in linux.

◆ canSetNotify()

canStatus canSetNotify ( const int  hnd,
HWND  aHWnd,
unsigned int  aNotifyFlags 
)
C#
static Canlib.canStatus canSetNotify(CanHandle handle, IntPtr win_handle, Int32 aNotifyFlags);
Delphi
function canSetNotify(handle: canHandle; aHWnd: HWND; aNotifyFlags: Cardinal): canStatus;

This function associates a window handle with the CAN circuit. A WM__CANLIB message is sent to that window when certain events (specified by the canNOTIFY_xxx flags) occur.

When an event take place, a WM__CANLIB message will be sent to the window whose handle is aHWnd. This WM__CANLIB message will have:

  • WPARAM handle to the circuit where the event occurred
  • HIWORD(LPARAM) 0
  • LOWORD(LPARAM) canEVENT_xxx

In the routine that handles WM__CANLIB, you can call the CANlib API functions (for example, canRead()) using the handle found in wParam.

Parameters
[in]hndA handle to an open CAN circuit.
[in]aHWndHandle of the window which will receive the notification messages.
[in]aNotifyFlagsThe events specified with canNOTIFY_xxx, for which callback should be called.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure


In the routine that handles WM__CANLIB, you must call canRead() repeatedly until it returns canERR_NOMSG, regardless of the LPARAM value. This will flush the driver's internal event queues. If you fail to do this, no more events will be reported.

See also
Asynchronous Notifications
Examples:
example/c/tscript/envvar/envvar.c.

◆ canTranslateBaud()

canStatus canTranslateBaud ( long *const  freq,
unsigned int *const  tseg1,
unsigned int *const  tseg2,
unsigned int *const  sjw,
unsigned int *const  nosamp,
unsigned int *const  syncMode 
)
C#
static Canlib.canStatus canTranslateBaud(int bitrate, out Int32 freq, out Int32 tseg1, out Int32 tseg2, out Int32 sjw, out Int32 nosamp);
Delphi
function canTranslateBaud(var freq: Longint; var tseg1, tseg2, sjw, noSamp, syncMode: Cardinal): canStatus;

This function translates the canBITRATE_xxx constants to their corresponding bus parameter values. At return, this freq contains the actual bit rate (in bits per second). TSeg1 is the number of quanta (less one) in a bit before the sampling point. TSeg2 is the number of quanta after the sampling point.

Parameters
[in,out]freqA pointer to a DWORD which contains the canBITRATE_xxx constant to translate. The bitrate constant value is overwritten with the frequency value.
[out]tseg1A pointer to a buffer which receives the Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point.
[out]tseg2A pointer to a buffer which receives the Time segment 2, that is, the number of quanta from the sampling point to the end of the bit.
[out]sjwA pointer to a buffer which receives the Synchronization Jump Width.
[out]nosampA pointer to a buffer which receives the number of sampling points.
[out]syncModeUnsupported, always read as zero. May be set to NULL.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
canSetBusParams()
Examples:
example/c/gensig/gensig.c.

◆ canWrite()

canStatus canWrite ( const int  hnd,
long  id,
void *  msg,
unsigned int  dlc,
unsigned int  flag 
)
C#
static Canlib.canStatus canWrite(CanHandle handle, Int32 id, Byte[] msg, Int32 dlc, Int32 flag);
Delphi
function canWrite(handle: canHandle; id: Longint; msg: Pointer; dlc: Cardinal; flag: Cardinal): canStatus;

This function sends a CAN message. The call returns immediately after queuing the message to the driver.

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

Note
The message has been queued for transmission when this calls return. It has not necessarily been sent.
Parameters
[in]hndA handle to an open CAN circuit.
[in]idThe identifier of the CAN message to send.
[in]msgA pointer to the message data, or NULL.
[in]dlcThe length of the message in bytes.
For Classic CAN dlc can be at most 8, unless canOPEN_ACCEPT_LARGE_DLC is used.
For CAN FD dlc can be one of the following 0-8, 12, 16, 20, 24, 32, 48, 64.
[in]flagA combination of message flags, canMSG_xxx (including canFDMSG_xxx if the CAN FD protocol is enabled). Use this parameter to send extended (29-bit) frames and/or remote frames. Use canMSG_EXT and/or canMSG_RTR for this purpose.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure
See also
Sending Messages
canWriteSync(), canWriteWait()
Examples:
example/c/canecho.c, example/c/gensig/gensig.c, example/c/thread.c, example/c/tx.c, example/cpp/candemo/candemo.cpp, and tutorial/c/SendMessage.c.

◆ canWriteSync()

canStatus canWriteSync ( const int  hnd,
unsigned long  timeout 
)
C#
static Canlib.canStatus canWriteSync(CanHandle handle, Int64 timeout);
Delphi
function canWriteSync(handle: canHandle; timeout: Cardinal): canStatus;

Waits until all CAN messages for the specified handle are sent, or the timeout period expires.

Parameters
[in]hndA handle to an open CAN circuit.
[in]timeoutThe timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout.
Returns
canOK (zero) if the queue emptied before the timeout period came to its end.
canERR_TIMEOUT (negative) not all messages were transmitted when the timeout occurred.
canERR_PARAM (negative) This could be caused by an erroneous parameter, or if you have turned TXACKs off (by using canIoCtl()) because if you do you can't use this call. The driver simply doesn't know when all the messages are sent!
canERR_xxx (negative) if failure
See also
canWrite(), canWriteWait()
Examples:
example/c/thread.c, example/cpp/candemo/candemo.cpp, and tutorial/c/SendMessage.c.

◆ canWriteWait()

canStatus canWriteWait ( const int  hnd,
long  id,
void *  msg,
unsigned int  dlc,
unsigned int  flag,
unsigned long  timeout 
)
C#
static Canlib.canStatus canWriteWait(CanHandle handle, Int32 id, Byte[] msg, Int32 dlc, Int32 flag, Int64 timeout);
Delphi
function canWriteWait(handle: canHandle; id: Longint; var msg; dlc, flag, timeout: Cardinal): canStatus;

This function sends a CAN message. It returns when the message is sent, or the timeout expires.

This is a convenience function that combines canWrite() and canWriteSync().

If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.

Parameters
[in]hndA handle to an open CAN circuit.
[in]idThe identifier of the CAN message to send.
[in]msgA pointer to the message data, or NULL.
[in]dlcThe length of the message in bytes.
For Classic CAN dlc can be at most 8, unless canOPEN_ACCEPT_LARGE_DLC is used.
For CAN FD dlc can be one of the following 0-8, 12, 16, 20, 24, 32, 48, 64.
[in]flagA combination of message flags, canMSG_xxx. Use this parameter to send extended (29-bit) frames and/or remote frames. Use canMSG_EXT and/or canMSG_RTR for this purpose.
[in]timeoutThe timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout.
Returns
canOK (zero) if success
canERR_xxx (negative) if failure

◆ kvBitrateToBusParamsFdTq()

canStatus kvBitrateToBusParamsFdTq ( const canHandle  hnd,
int  freqA,
int  freqD,
kvBusParamsTq arbitration,
kvBusParamsTq data 
)
C#
static Canlib.canStatus Canlib.kvBitrateToBusParamsFdTq(CanHandle hnd, Int32 freqA, Int32 freqD, out kvBusParamsTq arbitration, out kvBusParamsTq data);
Delphi
function kvBitrateToBusParamsFdTq (handle: canHandle; const freqA, freqD: Integer; var arbitration, data: kvBusParamsTq): canStatus;

This function translates the canFD_BITRATE_xxx constants to corresponding bus parameter values. At return arbitration contains parameter values for the specified freqA, and data contains parameter values for the specified freqD. If the channel is opened in classic CAN mode see kvBitrateToBusParamsTq().

Parameters
[in]hndA handle to an open circuit.
[in]freqABitrate constant, canFD_BITRATE_xxx.
[in]freqDBitrate constant, canFD_BITRATE_xxx.
[in,out]arbitrationA pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freqA.
[in,out]dataA pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freqD.
Returns
canOK (zero) is success
canERR_xxx (negative) if failure
See also
canSetBusParamsFdTq(), kvBitrateToBusParamsTq()

◆ kvBitrateToBusParamsTq()

canStatus kvBitrateToBusParamsTq ( const canHandle  hnd,
int  freq,
kvBusParamsTq nominal 
)
C#
static Canlib.canStatus Canlib.kvBitrateToBusParamsTq(CanHandle hnd, Int32 freqA, out kvBusParamsTq nominal);
Delphi
function kvBitrateToBusparamsTq(handle: canHandle; const freq: Integer; var nominal: kvBusParamsTq): canStatus;

This function translates the canBITRATE_xxx constants to corresponding bus parameter values. At return nominal contains parameter values for the specified freq. If the channel is opened in CAN FD mode, see kvBitrateToBusParamsFdTq().

Parameters
[in]hndA handle to an open circuit.
[in]freqBitrate constant, canBITRATE_xxx.
[in,out]nominalA pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freq.
Returns
canOK (zero) is success
canERR_xxx (negative) if failure
See also
canSetBusParamsTq(), kvBitrateToBusParamsFdTq()