Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020 
<== Date ==> <== Thread ==>

Subject: reading negative 16-bit numbers over Asyn modbus
From: <matthew.pearson@diamond.ac.uk>
To: <tech-talk@aps.anl.gov>
Date: Thu, 5 Apr 2012 17:50:49 +0000
Hi,

I have a Eurotherm 3217 controller that I'm talking to using modbus RTU over RS485 (via a Moxa terminal server). It seems to work fine, but I'm having trouble reading a negative number.

The Asyn support is configured to use modbus function code 3, like this: (from the eurotherm2k support module eurothermModbus.c):

mkname(str, strmaxlen, asynPortName, modbusAddress, loopNumber, 0, "PV");
asynRet = drvModbusAsynConfigure(str, asynPortName, modbusAddress,
		MODBUS_READW, loopStart+PV_OFFSET, 3,
		0, EUROTHERM_POLL_MS, "");

Where:
loop number is 1.
modbus addr is 1.
MODBUS_READW is 3 (this is the function code, so it's reading 16-bit words).
loopStart+PV_OFFSET is 1+0, so 1.
3 is the modbus length, which means 3*16-bit.
The 0 data type is Unsigned 16-bit binary integers.

This works fine for positive numbers, but negative fails. I tried changing the modbus data type to 4, which should mean INT16 2's complement, but it seems to fail at some point and just return zero in the record.

If I turn on asyn trace, the negative word I am reading back is "fd 1c". The actual reading I expect is about -750. So this looks to be correct if assuming 2's complement encoding. 

Anybody successfully read negative integers over modbus?

I'm using modbus 2-2, and asyn 4-14.

Update... looking at drvModbusAsyn.c, I see that convertFromBinary() only implements 3 types of type conversion (modbus data types 1, 2 and 3 in the list in the documentation?)

Cheers,
Matthew



Dr Matthew Pearson
Senior Software Systems Engineer
Diamond Light Source
Chilton, Didcot
OX11 0DE
UK

MX Controls Team Leader
Beamline Controls - I19, I24, B24




-- 
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 





Replies:
RE: reading negative 16-bit numbers over Asyn modbus Mark Rivers

Navigate by Date:
Prev: Re: Question about 85XX dual core CPU board for VxWorks/EPICS Andrew Johnson
Next: RE: reading negative 16-bit numbers over Asyn modbus Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020 
Navigate by Thread:
Prev: Re: Question about 85XX dual core CPU board for VxWorks/EPICS 王林
Next: RE: reading negative 16-bit numbers over Asyn modbus Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·