TrendLog.GetHook (METH) ¶ METHOD GetHook : BACnet.IBACnetServerPluginHook InOut: Scope Name Type Return GetHook BACnet.IBACnetServerPluginHook Input index UINT
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
DriverClose (FUN) ¶ FUNCTION DriverClose : ERROR Closes a CAN interface and frees all resources. InOut: Scope Name Type Comment Return DriverClose ERROR ERROR.NO_ERROR or appropriate error code Input hDriver CAA.HANDLE handle of CAN interface
DriverGetSize (FUN) ¶ FUNCTION DriverGetSize : CAA.SIZE Calculates the needed memory size for DriverOpenP . InOut: Scope Name Type Comment Return DriverGetSize CAA.SIZE Required memory size for DriverOpenP Input usiNetId USINT number of CAN interface [0..n] xSupport29Bit BOOL FALSE : only 11-Bit IDs, TRUE : support also 29-Bit ctMessages CAA.COUNT number of transmit messages which should be allocated peError POINTER TO ERROR optional pointer to error enum
DriverOpenH (FUN) ¶ FUNCTION DriverOpenH : CAA.HANDLE Opens a CAN interface and allocates memory from heap. Not every hardware supports each baud rate. If a baud rate is not supported or if the interface cannot be opened due to different reasons, the function returns CAA.gc_hINVALID . The function can be called several times on the same interface, so that multiple parts of a program can work on it. You can set uiBaudrate to 0 if the interface is already opened or if the default baudrate from configuration file should be used. See following section in configuration file: [CmpCAACanL2] ;If setting PersistentBaudrate is enabled (0: disabled; 1: enabled) ;the baudrate will be stored into Net.X.DefaultBaudrate (where X equals NetId) when opening the driver. PersistentBaudrate=1 ;Default baudrate for CAN network 0. This baudrate will be used when the network is opened (e.g from CmpBlkDrvCan or CANopen) with the baudrate set to 0. ;Net.0.DefaultBaudrate=1000 Net.0.DefaultBaudrate=1000 InOut: Scope Name Type Comment Return DriverOpenH CAA.HANDLE handle of CAN interface or CAA.gc_hINVALID if failed. Input usiNetId USINT number of CAN interface [0..n] uiBaudrate UINT Baudrate in kBit/s e.g. 1000 for 1 Mbit xSupport29Bits BOOL FALSE : only 11-Bit IDs, TRUE : support also 29-Bit ctMessages CAA.COUNT number of transmit messages which should be allocated peError POINTER TO ERROR optional pointer to error enum
DriverOpenP (FUN) ¶ FUNCTION DriverOpenP : CAA.HANDLE See DriverOpenH for details. In contrast to DriverOpenH no dynamic memory will be allocated. Memory specified by pMemory and szMemSize is used. Use DriverGetSize to calculate the required memory size. Please note that required memory size can change with new runtime version. Note pMemory should be aligned to a 4 byte address on 32bit systems and 8 byte address on 64bit. To get sure, you can declare the memory with ARRAY [0..n] of __XWORD. Please keep also in mind that required memory size is different for 32 and 64 bit systems. InOut: Scope Name Type Comment Return DriverOpenP CAA.HANDLE handle of CAN interface or CAA.gc_hINVALID if failed. Input usiNetId USINT number of CAN interface [0..n] uiBaudrate UINT Baudrate in kBit/s e.g. 1000 for 1 Mbit xSupport29Bits BOOL FALSE : only 11-Bit IDs, TRUE : support also 29-Bit szMemSize CAA.SIZE size of allocated memory pMemory CAA.PVOID pointer to aligned memory peError POINTER TO ERROR optional pointer to error enum
FreeMessage (FUN) ¶ FUNCTION FreeMessage : ERROR This function releases a message that has been created with CreateMessage , read with Read or duplicated with CloneMessage . Note Do not free a message after it has been passed to the CL2 layer. Example: Creating a message, then passing the message handle to CL2 by calling Write and releasing it afterwards may result in unexpected behaviour. InOut: Scope Name Type Comment Return FreeMessage ERROR ERROR.NO_ERROR or appropriate error code Input hMessage CAA.HANDLE handle of message to be freed