Sample program 12 (R/W signature of calibration)

The box module features an advanced calibration mechanism to store, among other things, an individual signature with 256 bytes, which results from the calibration data. In this way the customer could provide a calibration with a specific signature, e.g. to detect unauthorized internal manipulation of the calibration data; see also chapter “Display of data changes”.

The function block described below can be used as a basis for an implementation in TwinCAT on a PLC. To simplify matters, only a CRC16 was used in this sample to serve a "signature" limited to two bytes. At a commented point in the FB implementation, another signature algorithm can be implemented, which can be up to 256 bytes long.

The sample function block is included in the TwinCAT 3 archive, which is available for download together with a visualization:

download link

Explanatory notes for the visualization "Calibration_Signature_RW"

The input variables of the ADS address and the "InputToggle" must be linked again if another terminal or Box (than ELM3602) is used for the sample. This must be entered in the field after starting the sample program. Alternatively, it can be entered before the start as initialization of the input variable "sTerminalTypeIn" of the function block "FB_VisuUpdate":

sTerminalTypeIn      : T_MaxString := 'ELM3602';

After the program start

The function block "FB_CalibrationSignature" is called in read mode by the visualization when channel +/- or interface +/- or "read" is actuated and in write mode when "write" is actuated. If, after reading, the calculated and the read signature match, bCmpResult becomes TRUE (no inequality). After a write access the entry remains in the read CoE and can be checked by reading (a write access does not change the state of bCmpResult).

Sample program 12 (R/W signature of calibration) 1:
Visualization of the sample implementation: Calibration signature

The variable bError (visualization representation: "R/W Error") provides information about a general error that has occurred when accessing the box module as well as the failure to find stored information of the box module (either the entry in the GVL is missing or the box module is not present).

Explanatory notes for FB_CalibrationSignature

The interface of the function block is structured as follows:

   bInitialize                : BOOL := FALSE; // TRUE = Initialised
   bEnable                    : BOOL := FALSE; // Activate module
   tAmsNetIdArr               : AMSADDR;       // Ads address of the terminal/ box
   nIfSlectCoE                : WORD;          // Interface number of the CoE
   nChSelectCoE               : WORD := 1;     // Channel number
   eOption                    : E_CALSIG_OPTIONS; // Access get/set (read/write)
   stCoEPAIInfoDataCalCnt     : ST_CoE;        // Cal. counter object (EPP3504‑0023)
   bDone                      : BOOL; // Process end
   bCmpResult                 : BOOL; // Signature comparision: TRUE = equal
   nInterfaceUserCalCnt       : WORD; // Value of calibration counter
   bError                     : BOOL; // Case of error
   bCancel                    : BOOL; // Cancel
   nErrorId                   : UDINT;// Error number (all sources)
   anSigDataOutCoE            : ARRAY[0..(GVL_CoE.nSigLen-1)] OF BYTE; // Signature stored
   anSigDataOutCalc           : ARRAY[0..(GVL_CoE.nSigLen-1)] OF BYTE; // Signature calculated

For initialization the "Net Id" and "Port No." must be transferred to the variable "tAmsNetIdArr" of the FB instance. In addition, the CoE object for reading the calibration counter must be transferred via 'stCoEPAIInfoDataCalCnt', since this is different for of the EPP3504‑0023 box module.

A call is made with "bEnable := TRUE" for activation and with specification of the interface number (nIfSlectCoE) that applies to the box module to be addressed, the channel (nChSelectCoE) and for reading the stored signature "eOption := E_CALSIG_OPTIONS.get" or for writing "eOption := E_CALSIG_OPTIONS.set".

Then the function block is called until the output variable "bDone" is TRUE.

The outputs anSigDataOutCalc, anSigDataOutCoE, nInterfaceUserCalCnt and bCmpResult will provide content according to the selected option and the calculated/stored data of the box module.

To attempt to clear an error that has occurred in the case of "bError" = TRUE, the FB can be called with "bInit := FALSE" (e.g. if the channel number or the interface number has been corrected according to the addressed box module). The "nErrorId" can be used for evaluation.

In the function block, the signature calculation can be changed/extended at the following point:

// Calculate signature
// ============== User code here ==============
// Example: simple CRC:
nCrc := nIfSlectCoE + nChSelectCoE; // Default setting of start value
nCrc := F_DATA_TO_CRC16_CCITT(ADR(aData), nDataLen, nCrc); // Calculate "signature"
memset(ADR(anSigDataOutCalc), 16#FF, GVL_CoE.nSigLen);
memcpy(ADR(anSigDataOutCalc), ADR(nCrc), 2); // <- Dependant be the type of encryption
// =================================================