Hi Jon,
I didn't realize you were running an old version of modbus.
In R2-2 this is from the readInt32 function:
switch(pPlc->modbusFunction) {
case MODBUS_READ_COILS:
case MODBUS_READ_DISCRETE_INPUTS:
case MODBUS_READ_HOLDING_REGISTERS:
case MODBUS_READ_INPUT_REGISTERS:
*value = pPlc->data[offset];
break;
pPlc->data is unsigned short, so it will be copied to *value without casting to signed.
In R2-4 and later this is from readInt32:
switch(pPlc->modbusFunction) {
...
case MODBUS_READ_HOLDING_REGISTERS:
case MODBUS_READ_INPUT_REGISTERS:
case MODBUS_READ_INPUT_REGISTERS_F23:
status = readPlcInt(pPlc, offset, value);
if (status != asynSuccess) return status;
break;
This is from readPlcInt:
switch (dataType) {
case dataTypeUInt16:
result = value;
break;
...
case dataTypeInt16:
result = (epicsInt16)value;
break;
So for data type 4 (dataTypeInt16) it casts the value to epicsInt16 (signed) before copying to the epicsInt32 value.
If you want to correctly handle the data from your device you need to upgrade to modbus R2-4 or later.
Mark
________________________________________
From: [email protected] [[email protected]]
Sent: Thursday, December 03, 2015 12:16 PM
To: Mark Rivers
Cc: [email protected]
Subject: RE: ai RVAL via asyn + modbus: getting unsigned integer
On Thu, 3 Dec 2015, Mark Rivers wrote:
> Hi Jon,
> http://cars9.uchicago.edu/software/epics/modbusDoc.html
>
> Supported Modbus data types
> modbusDataType value drvUser field Description
> 0 UINT16 Unsigned 16-bit binary integers
> ...
> 4 INT16 16-bit signed (2's complement) integers. This data type extends the sign bit when converting to epicsInt32.
> ...
> So modbusDataType=0 is UINT16, unsigned 16-bit integer. That explains your problem, you should be using modbusDataType=4 (INT16) and your command line should be:
>
> drvModbusAsynConfigure("CollimCouch", "AcromagCollimCouch",0,4,0,9,4,100,"AcromagXT1221")
That must be it. The referenced documentation is for Modbus release 2-7 and
we are still running 2-2, which only supports data type codes 0 - 3. When we try
code 4 in 2-2, RVAL is always 0. The 2-2 doc says:
Type 0 is used for binary numbers in twos-complement format. The data can either be signed or unsigned.
But, as we found, it isn't very helpful for signed integers.
Thanks for clearing this up.
Jon Jacky
- References:
- RE: ai RVAL via asyn + modbus: getting unsigned integer Mark Rivers
- RE: ai RVAL via asyn + modbus: getting unsigned integer jon
- Navigate by Date:
- Prev:
RE: ai RVAL via asyn + modbus: getting unsigned integer jon
- Next:
EPICS 2016 Spring Meeting at ESS, Lund, Sweden Timo Korhonen
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
<2015>
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: ai RVAL via asyn + modbus: getting unsigned integer jon
- Next:
RE: ai RVAL via asyn + modbus: getting unsigned integer jon
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
<2015>
2016
2017
2018
2019
2020
2021
2022
2023
2024
|