Applies To: |
|
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.
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 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:
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: |
Related Links
Attachments