Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/creating_driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ treats the registers as unsigned 16-bit integers.
by Koyo PLCs for numbers such as ADC conversions.
* - UINT16
- Unsigned 16-bit binary integers.
* - UINT16_BS
- Unsigned 16-bit binary integers.The high-order 8-bit byte and low-order 8-bit byte
within the 16-bit register are swapped.
* - INT32_LE
- 32-bit integers, little endian (least significant word at Modbus address N, most
significant word at Modbus address N+1).
Expand Down
11 changes: 11 additions & 0 deletions modbusApp/src/drvModbusAsyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static modbusDataTypeStruct modbusDataTypes[MAX_MODBUS_DATA_TYPES] = {
{dataTypeBCDUnsigned, MODBUS_BCD_UNSIGNED_STRING},
{dataTypeBCDSigned, MODBUS_BCD_SIGNED_STRING},
{dataTypeUInt16, MODBUS_UINT16_STRING},
{dataTypeUInt16BS, MODBUS_UINT16_BS_STRING},
{dataTypeInt32LE, MODBUS_INT32_LE_STRING},
{dataTypeInt32LEBS, MODBUS_INT32_LE_BS_STRING},
{dataTypeInt32BE, MODBUS_INT32_BE_STRING},
Expand Down Expand Up @@ -2454,6 +2455,10 @@ asynStatus drvModbusAsyn::readPlcInt64(modbusDataType_t dataType, int offset, ep
i64Result = ui16Value;
break;

case dataTypeUInt16BS:
i64Result = bswap16(ui16Value);
break;

case dataTypeInt16SM:
i64Result = ui16Value;
if (i64Result & signMask) {
Expand Down Expand Up @@ -2616,6 +2621,10 @@ asynStatus drvModbusAsyn::writePlcInt64(modbusDataType_t dataType, int offset, e
case dataTypeUInt16:
buffer[0] = (epicsUInt16)value;
break;

case dataTypeUInt16BS:
buffer[0] = bswap16((epicsUInt16)value);
break;

case dataTypeInt16SM:
ui16Value = (epicsUInt16)value;
Expand Down Expand Up @@ -2767,6 +2776,7 @@ asynStatus drvModbusAsyn::readPlcFloat(modbusDataType_t dataType, int offset, ep

switch (dataType) {
case dataTypeUInt16:
case dataTypeUInt16BS:
case dataTypeInt16SM:
case dataTypeBCDSigned:
case dataTypeBCDUnsigned:
Expand Down Expand Up @@ -2893,6 +2903,7 @@ asynStatus drvModbusAsyn::writePlcFloat(modbusDataType_t dataType, int offset, e

switch (dataType) {
case dataTypeUInt16:
case dataTypeUInt16BS:
case dataTypeInt16SM:
case dataTypeBCDSigned:
case dataTypeBCDUnsigned:
Expand Down
2 changes: 2 additions & 0 deletions modbusApp/src/drvModbusAsyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define MODBUS_BCD_UNSIGNED_STRING "BCD_UNSIGNED"
#define MODBUS_BCD_SIGNED_STRING "BCD_SIGNED"
#define MODBUS_UINT16_STRING "UINT16"
#define MODBUS_UINT16_BS_STRING "UINT16_BS"
#define MODBUS_INT32_LE_STRING "INT32_LE"
#define MODBUS_INT32_LE_BS_STRING "INT32_LE_BS"
#define MODBUS_INT32_BE_STRING "INT32_BE"
Expand Down Expand Up @@ -83,6 +84,7 @@ typedef enum {
dataTypeBCDUnsigned,
dataTypeBCDSigned,
dataTypeUInt16,
dataTypeUInt16BS,
dataTypeInt32LE,
dataTypeInt32LEBS,
dataTypeInt32BE,
Expand Down