EPICS Controls 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  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: using tcp with modbus over asyn
From: "Mark Rivers" <[email protected]>
To: "James Stevens" <[email protected]>
Cc: [email protected]
Date: Thu, 17 Nov 2011 23:01:42 -0600
Hi James,
 
OK, so it appears the slave address is OK.
 
The device is definitely answering your query.
 
On page 85 of that manual it shows that where the Modbus slave module gets its data is configurable.  Is it possible that this meter is not configured to get the data you think it is at addess 40150?
 
Does this same exact meter work correctly with the older ModbusTCP driver?  If so then you may need to run "ethereal" and capture network packets to see what the difference is between the old driver and the new asyn driver.
 
Mark
 

________________________________

From: James Stevens [mailto:[email protected]]
Sent: Thu 11/17/2011 6:49 PM
To: Mark Rivers
Cc: [email protected]
Subject: Re: using tcp with modbus over asyn




Mark,

Thank you for your response.

On page 85 of the user guide it states
that "The Modbus Unit ID of the meter
over Ethernet is 100."

http://www.sea.siemens.com/us/internet-dms/btlv/PowerDistributionComm/PowerDistribution/Docs/9510_9610_User_Guide.pdf

When I tried setting the slave address to
zero, I got a timeout error.

epics> 2011/11/17 18:46:33.771 drvModbusAsyn::doModbusIO port UPSDASHCP2 error calling writeRead, error=164.54.2.216:502 timeout: Resource temporarily unavailable, nwrite=6/6, nread=0
2011/11/17 18:46:38.269 S:UPS:CP2:I4ai:AI devAsynInt32 process read error
2011/11/17 18:46:38.270 S:UPS:CP2:IAvgMax:AI devAsynInt32 process read error
2011/11/17 18:46:38.270 S:UPS:CP2:IAvgMin:AI devAsynInt32 process read error
2011/11/17 18:46:38.271 S:UPS:CP2:aa:AI devAsynInt32 process read error
2011/11/17 18:46:38.271 S:UPS:CP2:f:AI devAsynInt32 process read error
2011/11/17 18:46:38.271 S:UPS:CP2:p1a:AI devAsynInt32 process read error
2011/11/17 18:46:38.271 S:UPS:CP2:p2a:AI devAsynInt32 process read error
2011/11/17 18:46:38.271 S:UPS:CP2:p3a:AI devAsynInt32 process read error

Regards--Jim Stevens

----- Original Message -----
From: "Mark Rivers" <[email protected]>
To: "James Stevens" <[email protected]>, [email protected]
Sent: Thursday, November 17, 2011 6:23:43 PM
Subject: RE: using tcp with modbus over asyn

Hi James,

> How can I verify that I am reading the correct base address?

Here is the message that was sent to the Modbus device:

00 01 00 00 00 06 64 03 9c d6 00 10

The first 6 bytes of this message are the modbusMBAPHeader:

typedef struct modbusMBAPHeader_str
{
    unsigned short transactId;
    unsigned short protocolType;
    unsigned short cmdLength;
} modbusMBAPHeader;

They are not very interesting, but they look correct.  cmdLength=6,
which is the length of the modbusReadRequest below.

The next part of the message is the modbusReadRequest

typedef struct modbusReadRequest_str
{
    unsigned char    slave;
    unsigned char    fcode;
    unsigned short   startReg;
    unsigned short   numRead;
} modbusReadRequest;

So slave = 0x64 = 100
That is the slave address you told it to use in
drvModbusAsynConfigure().  Are you sure this is correct?  All Modbus TCP
devices I have used had a slave address of 0.

fcode = 03
That is the function code you told it to use.  That seems correct,
3=Read Holding Registers.

startReg = 9c d6 = 40150
That is the base address you told it to use.

numRead = 00 10 = 16
That is the length you told it to read.

So it appears to me that the message being sent to the device is
correct.

Here is the response you are getting from the device:

00 01 00 00 00 23 64 03 20 ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff

The first 6 bytes of the response are again the modbusMBAPHeader:

typedef struct modbusMBAPHeader_str
{
    unsigned short transactId;
    unsigned short protocolType;
    unsigned short cmdLength;
} modbusMBAPHeader;

So the cmdLength = 0x23 = 35.

I believe that what comes next is the slave address (0x64=100), though
that is skipped in the driver.

Next comes the modbusReadResponse:

typedef struct modbusReadResponse_str
{
    unsigned char  fcode;
    unsigned char  byteCount;
    unsigned char  data[1];
} modbusReadResponse;

So the fcode=03 which is correct.  If the device returns an error it
changes the fcode on the return to "or" it with MODBUS_EXCEPTION_FCN. 

#define MODBUS_EXCEPTION_FCN            0x80

That is tested as follows:
    if (readResp->fcode & MODBUS_EXCEPTION_FCN) {
        exceptionResp = (modbusExceptionResponse *)pPlc->modbusReply;
        asynPrint(pPlc->pasynUserTrace, ASYN_TRACE_ERROR,
                  "%s::doModbusIO port %s Modbus exception=%d\n",
                  driver, pPlc->portName, exceptionResp->exception);

byteCount = 0x20=32, so it is returning you 32 bytes.  That is correct,
since you asked for 16 holding registers.

So it looks like the device is responding as expected.  I don't know why
your data is wrong, except that perhaps you are using the wrong slave
address?

Cheers,
Mark






-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of James Stevens
Sent: Thursday, November 17, 2011 5:43 PM
To: [email protected]
Subject: using tcp with modbus over asyn


Let me restate my last post.

I am trying to update a soft IOC using the modbusIP
driver (version 1-1-asd6) from the Canadian Light
Source to Mark Rivers' modbus over asyn version
2-1.

The soft IOC is reading a Siemens 9610 Power
Meter on the accelerator network.

I started by trying to read an unsigned 16 bit
register at the 40150 decimal base address, but
the values read back from the power meter are
all ff's.

How can I verify that I am reading the correct
base address?

#ups-cp2
drvAsynIPPortConfigure("L0","164.54.2.216:502",0,0,1)
modbusInterposeConfig("L0",0,5500,0)
drvModbusAsynConfigure("UPSDASHCP2","L0",100,3,40150,16,0,5000,"9610PM")
#asynSetTraceMask("L0",0,3)
asynSetTraceIOMask("L0",0,2)
## Load record instances
dbLoadRecords("db/SIEM9610.vdb","L=CP2")
dbLoadRecords("db/asynRecord.db","P=SR:,R=SIEM:9610,PORT=L0,ADDR=0,OMAX=
0,IMAX=0")
cd /home/helios5/JBS/upsmbus/1/iocBoot/siocupsmon
iocInit
Starting iocInit
########################################################################
####
## EPICS R3.14.11-asd1 $R3-14-11$ $2009/08/28 18:47:36$
## EPICS Base built Aug 28 2009
########################################################################
####
cas warning: Configured TCP port was unavailable.
cas warning: Using dynamically assigned TCP port 52753,
cas warning: but now two or more servers share the same UDP port.
cas warning: Depending on your IP kernel this server may not be
cas warning: reachable with UDP unicast (a host's IP in
EPICS_CA_ADDR_LIST)
iocRun: All initialization complete
epics> 2011/11/17 17:40:24.571 164.54.2.216:502 write 12

00 01 00 00 00 06 64 03 9c d6 00 10
2011/11/17 17:40:24.574 164.54.2.216:502 read 41

00 01 00 00 00 23 64 03 20 ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff

Regards--Jim Stevens




Replies:
Re: using tcp with modbus over asyn Eric Norum
References:
Re: using tcp with modbus over asyn James Stevens

Navigate by Date:
Prev: RE: asyn / vxi11 / trace output Mark Rivers
Next: RE: recommendations for win64 build graham.cox
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: using tcp with modbus over asyn James Stevens
Next: Re: using tcp with modbus over asyn Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
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 ·