Defining a CODESYS
unsolicited message
The following section explains how to define an ADS Read or an ADS Write on a TwinCAT 3 PLC. The ADS Read will send a request to deviceWISE for data. The ADS Write will send data from the PLC to deviceWISE. ADS Reads and ADS Writes originating from TwinCAT 2's are not currently supported.
CODESYS ADS Read
The following code shows how to configure a CODESYS ADS Read function which sends a read request to deviceWISE when a trigger variable goes from 0->1. A deviceWISE CODESYS (ADS) trigger will fire when it receives a message with the corresponding index group, index offset, and command type. A trigger can also be configured to fire for any group or offset with the use of the -1 wildcard.
- Define a trigger variable, which will be used to
indicate when an unsolicited read should be sent to
deviceWISE.
triggerSend: BOOL := FALSE; - Define an ADS Read function called deviceWISE_ADSREAD
and set it to be trigger based.
SendMessageTrigger: F_TRIG;
deviceWISE_ADSREAD: ADSREAD; - Initialize the function with the following
parameters:
- NETID - AMS Sender Net ID as defined on device definition on deviceWISE
- PORT - AMS Sender Port
- IDXGRP - Group location requested by PLC
- IDXOFFS - Offset location requested by PLC
- LEN - Size of data requested
- DESTADDR - Variable where to write response data
- READ - Variable to trigger function off of
- TMOUT - Timeout value for read request
deviceWISE_ADSREAD( NETID:= '172.27.9.58.1.1',PORT:=30000,IDXGRP:=16#1,IDXOFFS:=16#0,LEN:=SIZEOF(boolArray),DESTADDR:=ADR(boolArray),READ:=triggerSend,TMOUT:= T#10S, );
The following screenshot shows a TwinCAT3 project that implements the previously described ADS Read behavior.
CODESYS ADS Write
The following code shows how to configure a CODESYS ADS Write function which sends a block of data to deviceWISE when a trigger variable goes from 0->1. A deviceWISE CODESYS (ADS) trigger will fire when it receives a message with the corresponding index group, index offset, and command type. A trigger can also be configured to fire for any group or offset with the use of the -1 wildcard.
- Define a trigger variable, which will be used to
indicate when an unsolicited read should be sent to
deviceWISE.
triggerSend: BOOL := FALSE; - Define an ADS Write function called
deviceWISE_ADSWRITE and set it to be trigger based.
SendMessageTrigger: F_TRIG;
deviceWISE_ADSWRITE: ADSWRITE; - Initialize the function with the following
parameters:
- NETID - AMS Sender Net ID as defined on device definition on deviceWISE
- PORT - AMS Sender Port
- IDXGRP - Group location sent by PLC
- IDXOFFS - Offset location sent by PLC
- LEN - Size of data to send
- SRCADDR - Data to write to deviceWISE
- WRITE - Variable to trigger function off of
- TMOUT - Timeout value
deviceWISE_ADSWRITE(NETID:= '172.27.9.58.1.1',PORT:= 30000,IDXGRP:= 16#1,IDXOFFS:= 16#0,LEN:= SIZEOF(boolArray),SRCADDR:= ADR(boolArray),WRITE:= triggerSend,TMOUT:= T#5S,BUSY=> ,ERR=> ,ERRID=> );
The following screenshot shows a TwinCAT3 project that implements the previously described ADS Write behavior.