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: James Stevens <[email protected]>
To: [email protected]
Date: Fri, 18 Nov 2011 15:23:40 -0600 (CST)
Mark & Eric,

I looks like the correct address 
is 149, however, the data is not
displayed as a float.

old = 26.5    new = 266

I am using the binary, twos-complement
format for the data type.

The ASLO field in the old record is set 
to 0.1.

Regards--Jim

----- Original Message -----
From: "James Stevens" <[email protected]>
To: [email protected]
Sent: Friday, November 18, 2011 3:05:01 PM
Subject: Re: using tcp with modbus over asyn


Mark & Eric,

> 
> Does this same exact meter work correctly with the older ModbusTCP driver?
>

I am currently using the modbusIP driver which was written 
by someone from the  Canadian Light Source in 2003. It works 
fine. I am testing the 2-1 modbus over asyn driver with the
same device.

The CLSI modbusIP driver has a header file with a register map
and a C++ extension written by John Maclean during the summer 
of 2003 that maps a Modicon IP address to a link number...

???

Perhaps I can send you the CLSI drvModicon header file and source 
code to help me figure out how the old driver maps the registers 
to the Siemens 9610 Power Meter?

This is a portion of the drvModicon header file...

#define MCOILS          0                       /* Card number for coils                */
#define MDINS           1                       /* Card number for digital inputs       */
#define MAINS           3                       /* Card number for analog inputs        */
#define MREGS           4                       /* Card number for registers            */
#define MPSEUDO         33                      /* Card number for pseudo i/o           */

#define HIGH_REGISTER_LOW   61441
#define HIGH_REGISTER_TOP   61441

/* Number of Groups of items */
#define NUMMODCOILS         256         /* 256 groups of 8 coils                */
#define NUMMODDIS           256         /* 256 groups of 8 digitals             */
#define NUMMODAIS        80             /* 80 groups of 4 analogs               */
#define NUMREGISTERS    500     /* 500 groups of 4 registers            */
#define BITBLOCK          8             /* size of coil/digital groups          */
#define REGBLOCK          4             /* size of analog/register groups       */
#define NUM_HIGH_REGISTERS  (HIGH_REGISTER_TOP - HIGH_REGISTER_LOW + 1)  /* not grouped */
                                                            /* read 1 register at a time */
Cheers--Jim
  

----- Original Message -----
From: "Eric Norum" <[email protected]>
To: "Mark Rivers" <[email protected]>
Cc: "James Stevens" <[email protected]>, [email protected]
Sent: Friday, November 18, 2011 1:23:56 PM
Subject: Re: using tcp with modbus over asyn

Could your equipment have another level of mapping/offset being applied somewhere?
As an illustration, I am reading the values from a Horner PLC -- here's the salient portion of the st.cmd file:

# ModbusStartAddress = Horner Register Number + 2999
#       i.e. Horner %R1 is Modbus Offset 3000
#
# Read 97 starting at Modbus 4996: Horner %R1997 through %R2093, inclusive
drvModbusAsynConfigure("rfDrive_r0i", "rfDrivePLC_1", 0, 3, 4996, 97, 0, 1000, "Horner")
# Write 1 starting at Modbus 3999: Horner %R1000
drvModbusAsynConfigure("rfDrive_r0o", "rfDrivePLC_1", 0, 6, 3999,  1, 0, 2000, "Horner")

You can see that there's an offset of 2999 between the register number in the PLC and the number passed in the Modbus packet…. 

On Nov 17, 2011, at 9:01 PM, Mark Rivers wrote:

> 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
> 
> 
> 

-- 
Eric Norum
[email protected]







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

Navigate by Date:
Prev: Re: using tcp with modbus over asyn Eric Norum
Next: Re: using tcp with modbus over asyn James Stevens
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 James Stevens
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 ·