CAN Low Level ¶ This library contains functions for accessing the CAN field bus. Layer 7 applications (such as CANopen, J1939, DeviceNet and many others) can be realized based on this library. Note The library can be used to access the CANbus in parallel to other CAN applications (e.g. CANopenStack), even if they use the same port. All functions are thread-safe and can be used from several tasks in parallel. Note A CAN bus application example can be downloaded from the CODESYS Store . It contains a library providing an easy-to-use CAN API based on CANL2 which can be used directly in your application. The library source code is provided as well in case you are searching for an CL2 example project. Enums BUSSTATE (Enum) ERROR (Enum) Functions 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) IndicatorConstants (GVL) Structures DIAGNOSIS_INFO (Struct)
Enums ¶ BUSSTATE (Enum) ERROR (Enum)
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
IFBCommand (ITF) ¶ INTERFACE IFBCommand
Interfaces ¶ IFBCommand (Interface)