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) |
CAN related functions.
struct 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
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
canStatus canAccept | ( | const int | hnd, |
const long | envelope, | ||
const unsigned int | flag | ||
) |
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.
[in] | hnd | An open handle to a CAN circuit. |
[in] | envelope | The mask or code to set. |
[in] | flag | Any of canFILTER_SET_CODE_STD, canFILTER_SET_MASK_STD, canFILTER_SET_CODE_EXT or canFILTER_SET_MASK_EXT |
canStatus canBusOff | ( | const int | hnd | ) |
Takes the specified handle off-bus. If no other handle is active on the same channel, the channel will also be taken off-bus
[in] | hnd | An open handle to a CAN channel. |
canStatus canBusOn | ( | const int | hnd | ) |
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.
[in] | hnd | An open handle to a CAN channel. |
canStatus canClose | ( | const int | hnd | ) |
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.
[in] | hnd | An open handle to a CAN channel. |
canStatus canFlushReceiveQueue | ( | const int | hnd | ) |
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.
[in] | hnd | A handle to an open circuit. |
canStatus canFlushTransmitQueue | ( | const int | hnd | ) |
This function removes all messages pending transmission from the transmit queue of the circuit.
[in] | hnd | A handle to an open circuit. |
canStatus canGetBusOutputControl | ( | const int | hnd, |
unsigned int * | drivertype | ||
) |
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.
[in] | hnd | An open handle to a CAN circuit. |
[out] | drivertype | A pointer to an unsigned int which receives the current driver type. The driver type can be either canDRIVER_NORMAL or canDRIVER_SILENT. |
canStatus canGetBusParams | ( | const int | hnd, |
long * | freq, | ||
unsigned int * | tseg1, | ||
unsigned int * | tseg2, | ||
unsigned int * | sjw, | ||
unsigned int * | noSamp, | ||
unsigned int * | syncmode | ||
) |
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.
[in] | hnd | An open handle to a CAN controller. |
[out] | freq | Bit rate (bits per second). |
[out] | tseg1 | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[out] | tseg2 | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[out] | sjw | The Synchronization Jump Width. |
[out] | noSamp | The number of sampling points; can be 1 or 3. |
[out] | syncmode | Unsupported, always read as one. |
canStatus canGetBusParamsFd | ( | const int | hnd, |
long * | freq_brs, | ||
unsigned int * | tseg1_brs, | ||
unsigned int * | tseg2_brs, | ||
unsigned int * | sjw_brs | ||
) |
This function retrieves the current data bus parameters for the specified CAN FD channel.
[in] | hnd | An open handle to a CAN FD controller. |
[out] | freq_brs | Bit rate (bits per second). |
[out] | tseg1_brs | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[out] | tseg2_brs | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[out] | sjw_brs | The Synchronization Jump Width. |
canStatus canGetBusParamsFdTq | ( | const int | hnd, |
kvBusParamsTq * | nominal, | ||
kvBusParamsTq * | data | ||
) |
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.
[in] | hnd | A handle to an open CAN circuit. |
[out] | nominal | See kvBusParamsTq. |
[out] | data | See kvBusParamsTq. |
return canOK (zero) if success return canERR_xxx (negative) if failure
canStatus canGetBusParamsTq | ( | const int | hnd, |
kvBusParamsTq * | nominal | ||
) |
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.
[in] | hnd | A handle to an open CAN circuit. |
[out] | nominal | See kvBusParamsTq. |
return canOK (zero) if success return canERR_xxx (negative) if failure
canStatus canGetBusStatistics | ( | const int | hnd, |
canBusStatistics * | stat, | ||
size_t | bufsiz | ||
) |
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.
[in] | hnd | An open handle to a CAN channel. |
[out] | stat | A pointer to a canBusStatistics struct that will receive the bus statistics figures. |
[in] | bufsiz | The size, in bytes, of the stat buffer. |
canStatus canGetDriverMode | ( | const int | hnd, |
int * | lineMode, | ||
int * | resNet | ||
) |
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.
[in] | hnd | An open handle to a CAN circuit. |
[out] | lineMode | A pointer to an int which receives the current line mode (canTRANSCEIVER_LINEMODE_xxx). |
[out] | resNet | A pointer to an int which receives the current resnet mode. This value is usually canTRANSCEIVER_RESNET_NA except for special DRVcan cables. |
canStatus canGetHandleData | ( | const int | hnd, |
int | item, | ||
void * | buffer, | ||
size_t | bufsize | ||
) |
[in] | hnd | An open handle to a CAN channel. |
[in] | item | This parameter specifies what data to obtain for the specified handle. The value is one of the constants canCHANNELDATA_xxx |
[out] | buffer | The address of a buffer which is to receive the data. |
[in] | bufsize | The size of the buffer to which the buffer parameter points. |
int canOpenChannel | ( | int | channel, |
int | flags | ||
) |
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 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.
[in] | channel | The number of the channel. Channel numbering is hardware dependent. |
[in] | flags | A combination of canOPEN_xxx flags |
canStatus canRead | ( | const int | hnd, |
long * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[out] | id | Pointer 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] | msg | Pointer 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] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer 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] | time | Pointer to a buffer which receives the message time stamp. The unit of the time stamp is configurable using canIOCTL_SET_TIMER_SCALE, default is 1 ms. |
canStatus canReadErrorCounters | ( | const int | hnd, |
unsigned int * | txErr, | ||
unsigned int * | rxErr, | ||
unsigned int * | ovErr | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[out] | txErr | A pointer to a DWORD which receives the transmit error counter. |
[out] | rxErr | A pointer to a DWORD which receives the receive error counter. |
[out] | ovErr | A pointer to a DWORD which receives the number of overrun errors. |
canStatus canReadSpecific | ( | const int | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[in] | id | The desired CAN identifier. |
[out] | msg | Pointer 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] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer 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] | time | Pointer to a buffer which receives the message time stamp. |
canStatus canReadSpecificSkip | ( | const int | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[in] | id | The desired CAN identifier. |
[out] | msg | Pointer 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] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer 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] | time | Pointer to a buffer which receives the message time stamp. |
canStatus canReadStatus | ( | const int | hnd, |
unsigned long *const | flags | ||
) |
Returns the status for the specified circuit. flags points to a longword which receives a combination of the canSTAT_xxx flags.
[in] | hnd | A handle to an open circuit. |
[out] | flags | Pointer to a DWORD which receives the status flags; this is a combination of any of the canSTAT_xxx. |
canStatus canReadSync | ( | const int | hnd, |
unsigned long | timeout | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[in] | timeout | The timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
canStatus canReadSyncSpecific | ( | const int | hnd, |
long | id, | ||
unsigned long | timeout | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[in] | id | The desired message identifier. |
[in] | timeout | The timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
canStatus canReadWait | ( | const int | hnd, |
long * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time, | ||
unsigned long | timeout | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[out] | id | Pointer 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] | msg | Pointer 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] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer 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] | time | Pointer to a buffer which receives the message time stamp. The unit of the time stamp is configurable using canIOCTL_SET_TIMER_SCALE, default is 1 ms. |
[in] | timeout | If no message is immediately available, this parameter gives the number of milliseconds to wait for a message before returning. 0xFFFFFFFF gives an infinite timeout. |
canStatus canRequestBusStatistics | ( | const int | hnd | ) |
The canRequestBusStatistics function requests bus statistics from the hardware. The bus statistics figures can be retrieved later by a call to the canGetBusStatistics function.
[in] | hnd | An open handle to a CAN channel. |
canStatus canRequestChipStatus | ( | const int | hnd | ) |
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.
[in] | hnd | An open handle to a CAN channel. |
canStatus canResetBus | ( | const int | hnd | ) |
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.
[in] | hnd | A handle to an open circuit. |
canStatus canSetAcceptanceFilter | ( | const int | hnd, |
unsigned int | code, | ||
unsigned int | mask, | ||
int | is_extended | ||
) |
This routine sets the message acceptance filters on a CAN channel.
Format of code and mask:
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.
[in] | hnd | An open handle to a CAN circuit. |
[in] | code | The acceptance code to set. |
[in] | mask | The acceptance mask to set. |
[in] | is_extended | Select 29-bit CAN identifiers. |
canStatus canSetBitrate | ( | const int | hnd, |
int | bitrate | ||
) |
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.
[in] | hnd | An open handle to a CAN channel. |
[in] | bitrate | The new bit rate, in bits/second. |
canStatus canSetBusOutputControl | ( | const int | hnd, |
const unsigned int | drivertype | ||
) |
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.
[in] | hnd | A handle to an open circuit. |
[in] | drivertype | Can driver type, canDRIVER_xxx) |
canStatus canSetBusParams | ( | const int | hnd, |
long | freq, | ||
unsigned int | tseg1, | ||
unsigned int | tseg2, | ||
unsigned int | sjw, | ||
unsigned int | noSamp, | ||
unsigned int | syncmode | ||
) |
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.
Use canSetBusParamsC200() to set the bus timing parameters in the ubiquitous 82c200 bit-timing register format.
[in] | hnd | An open handle to a CAN controller. |
[in] | freq | Bit 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] | tseg1 | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[in] | tseg2 | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[in] | sjw | The Synchronization Jump Width. |
[in] | noSamp | The number of sampling points; can be 1 or 3. |
[in] | syncmode | Unsupported and ignored. |
canStatus canSetBusParamsC200 | ( | const int | hnd, |
unsigned char | btr0, | ||
unsigned char | btr1 | ||
) |
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
1
: 3 samples, 0
: 1 samples [in] | hnd | A handle to an open CAN circuit. |
[in] | btr0 | The desired bit timing, formatted as the contents of the BTR0 register in the 82c200. |
[in] | btr1 | The desired bit timing, formatted as the contents of the BTR1 register in the 82c200. |
canStatus canSetBusParamsFd | ( | const int | hnd, |
long | freq_brs, | ||
unsigned int | tseg1_brs, | ||
unsigned int | tseg2_brs, | ||
unsigned int | sjw_brs | ||
) |
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.
[in] | hnd | An open handle to a CAN controller. |
[in] | freq_brs | CAN FD data bit rate (measured in bits per second); or one of the predefined constants canFD_BITRATE_xxx. |
[in] | tseg1_brs | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[in] | tseg2_brs | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[in] | sjw_brs | The Synchronization Jump Width. |
canStatus canSetBusParamsFdTq | ( | const int | hnd, |
const kvBusParamsTq | arbitration, | ||
const kvBusParamsTq | data | ||
) |
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.
[in] | hnd | A handle to an open CAN circuit. |
[in] | arbitration | See kvBusParamsTq |
[in] | data | See kvBusParamsTq |
return canOK (zero) if success return canERR_xxx (negative) if failure
canStatus canSetBusParamsTq | ( | const int | hnd, |
const kvBusParamsTq | nominal | ||
) |
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.
[in] | hnd | A handle to an open CAN circuit. |
[in] | nominal | See kvBusParamsTq |
return canOK (zero) if success return canERR_xxx (negative) if failure
canStatus canSetDriverMode | ( | const int | hnd, |
int | lineMode, | ||
int | resNet | ||
) |
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.
[in] | hnd | An open handle to a CAN circuit. |
[in] | lineMode | An int which defines the line mode, canTRANSCEIVER_LINEMODE_xxx. |
[in] | resNet | An int which defines the resnet mode. Set this parameter to canTRANSCEIVER_RESNET_NA unless you have good reasons to set it to something else. |
canStatus canSetNotify | ( | const int | hnd, |
HWND | aHWnd, | ||
unsigned int | aNotifyFlags | ||
) |
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_xxxIn the routine that handles WM__CANLIB
, you can call the CANlib API functions (for example, canRead()) using the handle found in wParam
.
[in] | hnd | A handle to an open CAN circuit. |
[in] | aHWnd | Handle of the window which will receive the notification messages. |
[in] | aNotifyFlags | The events specified with canNOTIFY_xxx, for which callback should be called. |
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.
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 | ||
) |
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.
[in,out] | freq | A pointer to a DWORD which contains the canBITRATE_xxx constant to translate. The bitrate constant value is overwritten with the frequency value. |
[out] | tseg1 | A 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] | tseg2 | A 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] | sjw | A pointer to a buffer which receives the Synchronization Jump Width. |
[out] | nosamp | A pointer to a buffer which receives the number of sampling points. |
[out] | syncMode | Unsupported, always read as zero. May be set to NULL. |
canStatus canWrite | ( | const int | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int | dlc, | ||
unsigned int | flag | ||
) |
This function sends a CAN message. The call returns immediately after queuing the message to the driver so the message has not necessarily been transmitted.
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.
[in] | hnd | A handle to an open CAN circuit. |
[in] | id | The identifier of the CAN message to send. |
[in] | msg | A pointer to the message data, or NULL . |
[in] | dlc | The 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] | flag | A 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. |
canStatus canWriteSync | ( | const int | hnd, |
unsigned long | timeout | ||
) |
Waits until all CAN messages for the specified handle are sent, or the timeout period expires.
[in] | hnd | A handle to an open CAN circuit. |
[in] | timeout | The timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
canStatus canWriteWait | ( | const int | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int | dlc, | ||
unsigned int | flag, | ||
unsigned long | timeout | ||
) |
This function sends a CAN message and returns when the message has been successfully transmitted, 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.
[in] | hnd | A handle to an open CAN circuit. |
[in] | id | The identifier of the CAN message to send. |
[in] | msg | A pointer to the message data, or NULL . |
[in] | dlc | The 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] | flag | A 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] | timeout | The timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
canStatus kvBitrateToBusParamsFdTq | ( | const canHandle | hnd, |
int | freqA, | ||
int | freqD, | ||
kvBusParamsTq * | arbitration, | ||
kvBusParamsTq * | data | ||
) |
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().
[in] | hnd | A handle to an open circuit. |
[in] | freqA | Bitrate constant, canFD_BITRATE_xxx. |
[in] | freqD | Bitrate constant, canFD_BITRATE_xxx. |
[in,out] | arbitration | A pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freqA. |
[in,out] | data | A pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freqD. |
canStatus kvBitrateToBusParamsTq | ( | const canHandle | hnd, |
int | freq, | ||
kvBusParamsTq * | nominal | ||
) |
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().
[in] | hnd | A handle to an open circuit. |
[in] | freq | Bitrate constant, canBITRATE_xxx. |
[in,out] | nominal | A pointer to a kvBusParamsTq, upon return receives the bus busparamters specified by freq. |