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  2012  2013  2014  2015  2016  <2017 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
<== Date ==> <== Thread ==>

Subject: Re: modbus write 2 16 bits holding registers with modbus function 16
From: Claudio Lambert <clambert@adc.net.ar>
To: Mark Rivers <rivers@cars.uchicago.edu>
Cc: "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Fri, 23 Jun 2017 12:18:30 -0300
Hi Mark,

I'm using modbusR2-1.

The OS where EPICS run is GNU/Linux x86_64 and the compiler is gcc 4.4.3.

I made the correction in the noAutoConnect flag but the error persist.

As additional information, there is no error writing a single record (Function Code=6).


Thanks again,

Claudio.

2017-06-23 11:47 GMT-03:00 Mark Rivers <rivers@cars.uchicago.edu>:

Hi Claudio,

 

I don't understand that error message.  What version of the EPICS Modbus package are you using?

 

In the latest version that error comes from this code starting at line 964 in drvModbusAsyn.c

 

            switch(pPlc->modbusFunction) {

                case MODBUS_WRITE_SINGLE_COIL:

                    buffer[0] = value;

                    status = doModbusIO(pPlc, pPlc->modbusSlave, pPlc->modbusFunction,

                                        modbusAddress, buffer, 1);

                    if (status != asynSuccess) return(status);

                    break;

                case MODBUS_WRITE_SINGLE_REGISTER:

                    status = writePlcInt(pPlc, dataType, offset, value, buffer, &bufferLen);

                    if (status != asynSuccess) return(status);

                    for (i=0; i<bufferLen; i++) {

                        status = doModbusIO(pPlc, pPlc->modbusSlave, pPlc->modbusFunction,

                                            modbusAddress+i, buffer+i, bufferLen);

                    }

                    if (status != asynSuccess) return(status);

                    break;

                case MODBUS_WRITE_MULTIPLE_REGISTERS:

                case MODBUS_WRITE_MULTIPLE_REGISTERS_F23:

                    status = writePlcInt(pPlc, dataType, offset, value, buffer, &bufferLen);

                    if (status != asynSuccess) return(status);

                    status = doModbusIO(pPlc, pPlc->modbusSlave, pPlc->modbusFunction,

                                        modbusAddress, buffer, bufferLen);

                    if (status != asynSuccess) return(status);

                    break;

                default:

                    asynPrint(pPlc->pasynUserTrace, ASYN_TRACE_ERROR,

                              "%s::writeInt32 port %s invalid request for Modbus"

                              " function %d\n",

                              driver, pPlc->portName, pPlc->modbusFunction);

                    return asynError;

            }

 

So the error comes when it falls through the switch into the default: block.  However, it is reporting that pPlc->modbusFunction is 16, which is what MODBUS_WRITE_MULTIPLE_REGISTERS is defined to be in modbus.h.

 

#define MODBUS_WRITE_MULTIPLE_REGISTERS      0x10

 

So it should have executed the case block above the default: section, not the default section.

 

What OS and compiler are you using?

 

Also, I notice something about this command in your startup script:

 

drvAsynIPPortConfigure("NOC02","192.168.1.1:502",0,1,1)

You have set the noAutoConnect flag.  This is generally not a good idea, I would suggest changing this line to:

drvAsynIPPortConfigure("NOC02","192.168.1.1:502",0,0,1)

However, I don't think this is related to the problem you are having.

 

Mark

 

 

From: tech-talk-bounces@aps.anl.gov [mailto:tech-talk-bounces@aps.anl.gov] On Behalf Of Claudio Lambert
Sent: Friday, June 23, 2017 9:05 AM
To: tech-talk@aps.anl.gov
Subject: modbus write 2 16 bits holding registers with modbus function 16

 

Hi all, I'm trying to write 2 x 16 bits holding registers (N, N+1) at same time, but I'm obtaining the following error:

epics> dbpf NOC02:CMD_TEST 45
DBR_DOUBLE:         45                 
epics> 2017/06/23 10:40:51.678 drvModbusAsyn::writeInt32 port NOC_F16 invalid request for Modbus function 16
2017/06/23 10:40:51.678 NOC02:CMD_TEST devAsynInt32 process error

This is the configuratión for the connection and record:


drvAsynIPPortConfigure("NOC02","192.168.1.1:502",0,1,1)
modbusInterposeConfig("NOC02",0,5000)
drvModbusAsynConfigure("NOC_F16", "NOC02", 1, 16, 2, 2, 6, 2000, "TTA")


record(longout,"NOC02:CMD_TEST") {
    field(DTYP,"asynInt32")
    field(OUT,"@asyn(NOC_F16 0)")
}

Any help would be appreciated.

Thanks in advance!



Replies:
RE: modbus write 2 16 bits holding registers with modbus function 16 Mark Rivers
References:
modbus write 2 16 bits holding registers with modbus function 16 Claudio Lambert
RE: modbus write 2 16 bits holding registers with modbus function 16 Mark Rivers

Navigate by Date:
Prev: RE: Problem compiling EPICS ioc with libusb Mark Rivers
Next: RE: modbus write 2 16 bits holding registers with modbus function 16 Mark Rivers
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
Navigate by Thread:
Prev: RE: modbus write 2 16 bits holding registers with modbus function 16 Mark Rivers
Next: RE: modbus write 2 16 bits holding registers with modbus function 16 Mark Rivers
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
ANJ, 23 Jun 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·