Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01 3.00

Summary:
I am writing a new driver using the Citect DDK. How can I support a full range of data types when the protocol for the device I am using is based around 16 bit word registers? 

Solution:
Many protocols only have commands for reading and writing 16 bit word registers. It is up to the driver developer to support as many different data formats as is possible. The full range of Citect data types are DIGITAL, BYTE, INTEGER, LONG, REAL, BCD and LONG_BCD.

The table below is a representation of the data format conversions the Citect Compiler expects to allow. The driver must be coded to provide the conversions. Some data formats may be disabled globally for the driver using the options field in the PROTDIR.DBF, this is documented in the DDK.

Each row represents a data format supported by commands in the device protocol. Each column represents a data format supported by the Citect driver. For example Modbus uses 16 bit word registers so use row 3 (INTEGER). Then for this type the driver should support DIGITAL (subject to Note1), INTEGER, BCD, LONG (Note2), LONG_BCD(Note2), REAL(Note2) and STRING.

  DIGITAL BYTE INTEGER, BCD LONG, LONG_BCD REAL STRING
DIGITAL YES          
BYTE Note1 YES YES, Note2 YES, Note2 YES, Note2 YES
INTEGER Note1   YES YES, Note2 YES, Note2 YES
LONG Note1     YES   YES
REAL         YES  
STRING           YES

Note1: All the integral formats can be converted to DIGITAL format if one of %u or %o is used in the 'protocol'.DBF file in the TEMPLATE field, these are documented in the DDK.

Note 2: These type conversions are supported, the boundary checking may be made before allowing these conversions.

The compiler will generate a DATAPOINT structure which contains all the information the driver needs to identify the device data format and the Citect data format requested by the user. The DATAPOINT structure is documented in the DDK.

EXAMPLE:
The following example demonstrates how the compiler will handle a Variable tag of data format LONG requested from INTEGER size Modbus plc registers. Compile a Modbus type variable tag of address 400021 using the LONG data type.

The compiler uses the PROTDIR.DBF and the MODBUS.DBF files, you should look at these to understand where the conversion data is from.

The resulting DATAPOINT structure is:

LogicalUnit - not generated by the compiler
RawType 4 the data format requested in the Variable Tags form, RDT_LONG = 4
BitWidth 16 the size of the registers (or items) native to the protocol, in this case registers are 16 bit words, see the modbus.dbf file
UnitType 3 modbus 4????? addresses compile to UnitType = 3, see modbus.dbf
UnitAddress 20 the register address normalised to a zero base using the range from the modbus.dbf file
UnitCount 2 a LONG is 32 bits, Citect must read two 16 bit modbus registers

Now the if the driver recieves this DATAPOINT as part of a read request it will issue read register command to read 2 registers starting from register address 21.

On receiving the raw value the driver converts the data into the requested format. For the modbus driver this involves swapping byte order and then calculating the numeric value of the long (modbus longs are 10000 * low register + high register). You should look at the modbus example code to see this conversion.

 

Keywords:
 

Attachments