BUSSTATE (ENUM) ¶ TYPE BUSSTATE : This data type describes the current state of the CAN network. Attributes: qualified_only InOut: Name Comment UNKNOWN The state of the network is not known or busstate is not implemented by driver. ERR_FREE No occurrence of CAN bus errors so far. The error counters of the chip are zero. ACTIVE Only few CAN bus errors so far. The error counters of the chip are below the warning level. WARNING Occurence of some CAN bus errors. The error counters are above the warning level. PASSIVE Too many CAN bus errors. The error counters are above the error level. BUSOFF The node has been separated from the CAN bus. The error counter has exceeded the admissible maximum.
ERROR (ENUM) ¶ TYPE ERROR : This data type describes all errors that can occur while running CL2 functions: Attributes: qualified_only InOut: Name Initial Comment NO_ERROR 0 no occurence of errors NO_29BIT_ID 10202 29Bit identifiers are not supported WRONG_BAUDRATE 10203 baudrate is not supported NO_MEMORY 10204 memory space cannot be allocated INVALID_NETID 10205 invalid Network ID INVALID_PRIORITY 10206 invalid priority INVALID_DRIVER_HANDLE 10207 invalid driver handle INVALID_MESSAGE_HANDLE 10208 invalid message handle INVALID_ID_HANDLE 10209 invalid identifier handle NO_DRIVER 10210 no CAN driver available SENDING_ERROR 10211 message could not be sent NO_SYNC_SERVICE 10212 SYNC-service is not supported NO_SYNC_PRODUCER 10213 SYNC-producer is not supported NO_SYNC_CONSUMER 10214 SYNC-consumer is not supported NO_SYNC_EVENT 10215 SYNC-event is not supported NO_SYNC_WINDOW 10216 window length is not supported NO_SYNC_FOREWARNTIME 10217 forewarn time is not supported WRONG_PARAM 10224 wrong parameter INVALID_HANDLE 10249 the handle was invalid
Functions ¶ This folder contains managed and unmanaged CL2 functions. Managed (functions without prefix “_”) means that resources are managed by a resource manager and resources are automatically released on reset application (e.g. driver and receivers are automatically closed). Unmanaged means that resources should be released by application. Unmanaged functions (functions with prefix “_”) offer better performance because there is no resource manager overhead and message handles can be casted directly to POINTER TO CL2I.MESSAGE (see CAN Low Level Imp Extern library for more details). Note Do not mix up managed and unmanaged functions. Handles from unmanaged functions should not be passed to managed functions and vice versa. Note With SIL2 runtime all functions are unmanaged! Basic Functions CloneMessage (Function) CreateIdAreaReceiver (Function) CreateMaskReceiver (Function) CreateMessage (Function) CreateSingleIdReceiver (Function) DeleteReceiver (Function) DriverClose (Function) DriverGetSize (Function) DriverOpenH (Function) DriverOpenP (Function) FreeMessage (Function) Read (Function) RegisterIdArea (Function) UnregisterIdArea (Function) Write (Function) Diagnostic Information GetBaudrate (Function) GetBusAlarm (Function) GetBusState (Function) GetBusload (Function) GetDiagnosis (Function) GetLostCounter (Function) GetReceiveCounter (Function) GetReceiveErrorCounter (Function) GetReceivePoolSize (Function) GetReceiveQueueLength (Function) GetTransmitCounter (Function) GetTransmitErrorCounter (Function) GetTransmitPoolSize (Function) GetTransmitQueueLength (Function) IsSendingActive (Function) ResetBusAlarm (Function) Extended Functionality DisableSyncService (Function) EnableSyncService (Function) Indicator Services GetCiAState (Function) SetCiAState (Function) Internal Basic Functions _CloneMessage (Function) _CreateArrayReceiver (Function) _CreateIdAreaReceiver (Function) _CreateMaskReceiver (Function) _CreateMessage (Function) _CreateSingleIdReceiver (Function) _DeleteReceiver (Function) _DriverClose (Function) _DriverGetSize (Function) _DriverOpenH (Function) _DriverOpenP (Function) _FreeMessage (Function) _Read (Function) _ReadArrayReceiver (Function) _RegisterIdArea (Function) _UnregisterIdArea (Function) _Write (Function) Diagnostic Information _GetBaudrate (Function) _GetBusAlarm (Function) _GetBusState (Function) _GetBusload (Function) _GetDiagnosis (Function) _GetLostCounter (Function) _GetReceiveCounter (Function) _GetReceiveErrorCounter (Function) _GetReceivePoolSize (Function) _GetReceiveQueueLength (Function) _GetTransmitCounter (Function) _GetTransmitErrorCounter (Function) _GetTransmitPoolSize (Function) _GetTransmitQueueLength (Function) _IsSendingActive (Function) _ResetBusAlarm (Function) Extended Functionality _DisableSyncService (Function) _EnableSyncService (Function) Indicator Services _GetCiAState (Function) _SetCiAState (Function) Message Information _GetMessageDataPointer (Function) _GetMessageId (Function) _GetMessageLength (Function) _GetMsgCount (Function) _GetNetId (Function) _GetTimeStamp (Function) _Is29BitIdMessage (Function) _IsRTRMessage (Function) _IsTransmitMessage (Function) _LostMessages (Function) Message Information GetMessageDataPointer (Function) GetMessageId (Function) GetMessageLength (Function) GetMsgCount (Function) GetNetId (Function) GetTimeStamp (Function) Is29BitIdMessage (Function) IsRTRMessage (Function) IsTransmitMessage (Function) LostMessages (Function)
Basic Functions ¶ Basic Functions for receiving and sending CAN messages. CloneMessage (Function) CreateIdAreaReceiver (Function) CreateMaskReceiver (Function) CreateMessage (Function) CreateSingleIdReceiver (Function) DeleteReceiver (Function) DriverClose (Function) DriverGetSize (Function) DriverOpenH (Function) DriverOpenP (Function) FreeMessage (Function) Read (Function) RegisterIdArea (Function) UnregisterIdArea (Function) Write (Function)
CloneMessage (FUN) ¶ FUNCTION CloneMessage : CAA.HANDLE This function duplicates an existing message. This duplicated message may be modified and sent via Write for example. Example VAR hReceiver : CAA.HANDLE ; hMsg : CAA.HANDLE ; hMsgCloned : CAA.HANDLE ; ctMsgLeft : CAA.COUNT ; eError : CL2.ERROR ; END_VAR //receive a message from hReceiver hMsg := CL2.Read ( hReceiverId := hReceiver , pctMsgLeft := ADR ( ctMsgLeft ), peError := ADR ( eError )); IF hMsg <> CAA.gc_hINVALID THEN //Clone received message hMsgCloned := CL2.CloneMessage ( hMessage := hMsg , peError := ADR ( eError )); //free original message CL2.FreeMessage ( hMessage := hMsg ); hMsg := CAA.gc_hINVALID ; //work with hMsgCloned... END_IF InOut: Scope Name Type Comment Return CloneMessage CAA.HANDLE cloned message handle Input hMessage CAA.HANDLE handle of message to clone peError POINTER TO ERROR optional pointer to error enum
CreateIdAreaReceiver (FUN) ¶ FUNCTION CreateIdAreaReceiver : CAA.HANDLE This function creates a receiver to which several identifier areas may be added using the function RegisterIdArea . This receiver type is used if messages within a specific cobID area should be received. For receiving a message use the returned receiver handle for Read function call. There are two kind of receivers: Always Newest Receivers (xAlwaysNewest := TRUE): Receiver holds only the last received message. Receiver with Queue (xAlwaysNewest := FALSE): Receiver holds messages in chronological order. Note To avoid losing receive messages an application has to read all messages of a receiver each cycle. All messages should be processed and released by FreeMessage afterwards. Note Current implementation of this receiver type does not support 29 bit identifiers. Example VAR hDriver : CAA.HANDLE ; hReceiver : CAA.HANDLE ; hMsg : CAA.HANDLE ; ctMsgLeft : CAA.COUNT ; eError : CL2.ERROR ; END_VAR //Create an IdAreaReceiver hReceiver := CL2.CreateIdAreaReceiver ( hDriver := hDriver , //driver handle xAlwaysNewest := FALSE , //FALSE ==> receiver with queue; TRUE ==> only newest message eEvent := CB.EVENT.NO_EVENT , //no receive event xEnableSyncWindow := FALSE , //not implemented peError := ADR ( eError ) //optional pointer to error ); IF hReceiver <> CAA.gc_hINVALID THEN //Add an area for CANopen Emergency messages (cobId 16#81-16#9F) CL2.RegisterIdArea ( hReceiverId := hReceiver , //receiver cobIdStart := 16#81 , //start cobID cobIdEnd := 16#9F , //end cobID xRTRValue := FALSE , //no RTR messages xRTRMask := TRUE , //activate RTR filter ==> xRTRValue will be checked x29BitIdValue := FALSE , //no 29 bit CAN messages x29BitIdMask := TRUE , //activate 29 bit filter ==> x29BitIdValue will be checked xTransmitValue := FALSE , //only receive messages, no transmit message loopback xTransmitMask := TRUE //activate transmit mask filter ==> xTransmitValue will be checked ); END_IF REPEAT //receive a message from hReceiver hMsg := CL2.Read ( hReceiverId := hReceiver , pctMsgLeft := ADR ( ctMsgLeft ), peError := ADR ( eError )); IF hMsg <> CAA.gc_hINVALID THEN //TODO: Process message (CL2.GetMessageDataPointer, CL2.GetMessageId, ...) CL2.FreeMessage ( hMsg ); //release message hMsg := CAA.gc_hINVALID ; //to avoid using an already released message END_IF UNTIL ctMsgLeft = 0 END_REPEAT Optionally, an event can be registered which is triggered upon reception of a corresponding message. A callback function can be registerd via CB.RegisterCallback (CAA Callback library). Use event class CB.EVENT_CLASS.FIELDBUS , event source CB.EVENT_SOURCE.CB_DRIVER and any unassigned event number (see CB.EVENT ). Use the same event number for eEvent input. Input variable dwParam of the registered callback function contains the CAN ID of the received message. See CreateSingleIdReceiver for example code. Note Event mechanism is not supported on all systems. Futhermore it is not possible to register an event for extended identifiers (29bit). InOut: Scope Name Type Comment Return CreateIdAreaReceiver CAA.HANDLE new receiver handle or CAA.gc_hINVALID in case of failure Input hDriver CAA.HANDLE handle of CAN interface xAlwaysNewest BOOL TRUE: returns only the newest message; FALSE: receiver with queue. eEvent CB.EVENT trigger event when message received xEnableSyncWindow BOOL use SYNC window: not implemented ==> do not care peError POINTER TO ERROR optional pointer to error enum
CreateMaskReceiver (FUN) ¶ FUNCTION CreateMaskReceiver : CAA.HANDLE This function creates a receiver for a specific identifier area. For receiving a message use the returned receiver handle for Read function call. Mask receivers are very similar to Area Receivers (see also RegisterIdArea ). The only difference is that CAN ID filtering is not done by range but by bit mask. Inputs cobIdValue and cobIdMask are interpreted as follows: Value 0 1 0 1 x : this bit may be either TRUE or FALSE 0 : this bit has to be FALSE 1 : this bit hat to be TRUE Mask 0 0 1 1 Result X X 0 1 In general: The values of the masks activate the evaluation of the value parameters. If the mask value is FALSE the value parameter is ignored. There are two kind of receivers: Always Newest Receivers (xAlwaysNewest := TRUE): Receiver holds only the last received message. Receiver with Queue (xAlwaysNewest := FALSE): Receiver holds messages in chronological order. Receivers can be also used for Tx loopback. If xTransmitMask is set to FALSE or xTransmitMask and xTransmitValue are set to TRUE CAN messages which are sent via Write will be received (applies to all transmit messages on the CAN interface). Use function IsTransmitMessage to distinguish between receive and transmit messages. Note To avoid losing receive messages an application has to read all messages of a receiver each cycle. All messages should be processed and released by FreeMessage afterwards. Example VAR hDriver : CAA.HANDLE ; hReceiver : CAA.HANDLE ; hMsg : CAA.HANDLE ; ctMsgLeft : CAA.COUNT ; eError : CL2.ERROR ; END_VAR //Create a MaskReceiver which receives all messages with CAN ID 16#80. hReceiver := CL2.CreateMaskReceiver ( hDriver := hDriver , cobIdValue := 16#80 , //cobID value cobIdMask := 16#FFFFFFFF , //cobID mask ==> all bits of value are relevant xRTRValue := FALSE , //no RTR messages xRTRMask := TRUE , //activate RTR filter ==> xRTRValue will be checked x29BitIdValue := FALSE , //no 29 bit CAN messages x29BitIdMask := TRUE , //activate 29 bit filter ==> x29BitIdValue will be checked xTransmitValue := FALSE , //only receive messages, no transmit message loopback xTransmitMask := TRUE , //activate transmit mask filter ==> xTransmitValue will be checked xAlwaysNewest := FALSE , //FALSE := receiver with queue; TRUE: only newest message eEvent := CB.EVENT.NO_EVENT , //no receive event xEnableSyncWindow := FALSE , //not implemented peError := ADR ( eError ) //optional pointer to error ); REPEAT //receive a message from hReceiver hMsg := CL2.Read ( hReceiverId := hReceiver , pctMsgLeft := ADR ( ctMsgLeft ), peError := ADR ( eError )); IF hMsg <> CAA.gc_hINVALID THEN //TODO: Process message (CL2.GetMessageDataPointer, CL2.GetMessageId, ...) CL2.FreeMessage ( hMsg ); //release message hMsg := CAA.gc_hINVALID ; //to avoid using an already released message END_IF UNTIL ctMsgLeft = 0 END_REPEAT Optionally, an event can be registered which is triggered upon reception of a corresponding message. A callback function can be registerd via CB.RegisterCallback (CAA Callback library). Use event class CB.EVENT_CLASS.FIELDBUS , event source CB.EVENT_SOURCE.CB_DRIVER and any unassigned event number (see CB.EVENT ). Use the same event number for eEvent input. Input variable dwParam of the registered callback function contains the CAN ID of the received message. See CreateSingleIdReceiver for example code. Note Event mechanism is not supported on all systems. Futhermore it is not possible to register an event for extended identifiers (29bit). InOut: Scope Name Type Comment Return CreateMaskReceiver CAA.HANDLE new receiver handle or CAA.gc_hINVALID in case of failure Input hDriver CAA.HANDLE handle of CAN interface cobIdValue CL2I.COBID CobID value cobIdMask CL2I.COBID CobID mask xRTRValue BOOL Value RTR bit; only evaluated if xRTRMask is set to TRUE xRTRMask BOOL Mask RTR bit x29BitIdValue BOOL Value 29 Bit Id; only evaluated if x29BitIdMask is set to TRUE x29BitIdMask BOOL Mask 29 Bit Id xTransmitValue BOOL Value Transmit message; only evaluated if xTransmitMask is set to TRUE xTransmitMask BOOL Mask Transmit message xAlwaysNewest BOOL TRUE : returns only the newest message; FALSE : receiver with queue. eEvent CB.EVENT trigger event when message received xEnableSyncWindow BOOL use SYNC window: not implemented ==> do not care peError POINTER TO ERROR optional pointer to error enum
CreateMessage (FUN) ¶ FUNCTION CreateMessage : CAA.HANDLE This function allocates a new message from the data pool of the driver and makes it available via its handle hMessage . In addition, the function sets the identifier, cobld, data length and RTR flag of the message. Such a message must either be sent with Write or released with FreeMessage . It can also be duplicated by use of CloneMessage . Example See Write . InOut: Scope Name Type Comment Return CreateMessage CAA.HANDLE new message handle or CAA.gc_hINVALID if no resources left Input hDriver CAA.HANDLE handle of CAN interface cobID CL2I.COBID cob ID usiLength USINT length of valid data bytes xRTR BOOL RTR bit x29BitID BOOL 29 Bit ID peError POINTER TO ERROR optional pointer to error enum
CreateSingleIdReceiver (FUN) ¶ FUNCTION CreateSingleIdReceiver : CAA.HANDLE This function creates a receiver for one specific CAN identifier. For receiving a message use the returned receiver handle for Read function call. There are two kind of receivers: Always Newest Receivers (xAlwaysNewest := TRUE): Receiver holds only the last received message. Receiver with Queue (xAlwaysNewest := FALSE): Receiver holds messages in chronological order. Receivers can be also used for Tx loopback. If xTransmit is set to TRUE CAN messages which are sent via Write will be received (applies to all transmit messages on the CAN interface). Use function IsTransmitMessage to distinguish between receive and transmit messages. Note To avoid losing receive messages an application has to read all messages of a receiver each cycle. All messages should be processed and released by FreeMessage afterwards. Example In this example a single ID receiver is created. It receives all RTR messages on CAN ID 16#100. VAR hDriver : CAA.HANDLE ; hReceiver : CAA.HANDLE ; hMsg : CAA.HANDLE ; pData : POINTER TO CL2I.DATA ; eError : CL2.ERROR ; ctMsgLeft : CAA.COUNT ; END_VAR hReceiver := CL2.CreateSingleIdReceiver ( hDriver := hDriver , cobId := 16#100 , xRTR := TRUE , x29BitId := FALSE , xTransmit := FALSE , xAlwaysNewest := FALSE , eEvent := CB.EVENT.NO_EVENT , //no receive event xEnableSyncWindow := FALSE , //not implemented peError := ADR ( eError ) //optional pointer to error ); REPEAT //receive a message from hReceiver hMsg := CL2.Read ( hReceiverId := hReceiver , pctMsgLeft := ADR ( ctMsgLeft ), peError := ADR ( eError )); IF hMsg <> CAA.gc_hINVALID THEN //TODO: Process message (CL2.GetMessageDataPointer, CL2.GetMessageId, ...) CL2.FreeMessage ( hMsg ); //release message hMsg := CAA.gc_hINVALID ; //to avoid using an already released message END_IF UNTIL ctMsgLeft = 0 END_REPEAT Optionally, an event can be registered which is triggered upon reception of a corresponding message. A callback function can be registerd via CB.RegisterCallback (CAA Callback library). Use event class CB.EVENT_CLASS.FIELDBUS , event source CB.EVENT_SOURCE.CB_DRIVER and any unassigned event number (see CB.EVENT ). Use the same event number for eEvent input. Input variable dwParam of the registered callback function contains the CAN ID of the received message. Note Event mechanism is not supported on all systems. Futhermore it is not possible to register an event for extended identifiers (29bit). Example In this example a single ID receiver with event callback is created. Step 1: Define a callback function with following interface (function name can be changed!). FUNCTION CallbackReceiveCANMessage : DWORD VAR_INPUT dwSpec : DWORD ; (* CB.Event and CB.EventClass *) dwSource : DWORD ; (* CB.EventSource *) dwParam : DWORD ; (* CAN ID *) END_VAR Step 2: Activate Enable system call in build settings of CallbackReceiveCANMessage . Step 3: Register callback and create receiver. VAR hDriver : CAA.HANDLE ; hReceiver : CAA.HANDLE ; eError : CL2.ERROR ; callback : CB.CB_CALLBACK ; hEvent : CAA.HANDLE ; eCBError : CB.ERROR ; END_VAR callBack.eClass := CB.EVENT_CLASS.FIELDBUS ; callback.eSource := CB.EVENT_SOURCE.DRIVER ; callback.eEvent := 10000 ; //any unassigned event number callback.pPOUFunc := ADR ( CallbackReceiveCANMessage ); hEvent := CB.RegisterCallback ( callback , ADR ( eCBError )); hReceiver := CL2.CreateSingleIdReceiver ( hDriver := hDriver , cobId := 16#100 , xRTR := FALSE , x29BitId := FALSE , xTransmit := FALSE , xAlwaysNewest := FALSE , eEvent := 10000 , //use the previously registered event number xEnableSyncWindow := FALSE , //not implemented peError := ADR ( eError ) //optional pointer to error ); InOut: Scope Name Type Comment Return CreateSingleIdReceiver CAA.HANDLE new receiver handle or CAA.gc_hINVALID in case of failure Input hDriver CAA.HANDLE handle of CAN interface cobId CL2I.COBID id of message to be received xRTR BOOL TRUE : receive RTR messages, FALSE : receive no RTR messages x29BitId BOOL TRUE : receive 29 Bit Ids, FALSE : receive 11 Bid Ids xTransmit BOOL TRUE : receive Tx messages, FALSE : receive Rx messages xAlwaysNewest BOOL TRUE : returns only the newest message; FALSE : receiver with queue. eEvent CB.EVENT trigger event when message received xEnableSyncWindow BOOL use SYNC window: not implemented ==> do not care peError POINTER TO ERROR optional pointer to error enum
DeleteReceiver (FUN) ¶ FUNCTION DeleteReceiver : ERROR This function releases all ressources of a specific receiver. Note When calling DriverClose all receivers connected to this driver are released automatically. Do not call DeleteReceiver afterwards! InOut: Scope Name Type Comment Return DeleteReceiver ERROR ERROR.NO_ERROR or appropriate error code Input hReceiverId CAA.HANDLE handle of receiver