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  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024  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  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Re: Re: modbus write registers error to Pilz PLC
From: Mark Rivers via Tech-talk <tech-talk at aps.anl.gov>
To: '高振华' <gaozh at ihep.ac.cn>
Cc: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Wed, 3 Feb 2021 19:27:58 +0000
I am puzzled.  It looks like you sent the complete output when the IOC boots, but I don't see an iocInit command?  Perhaps that is why dbstat is crashing the IOC?

Make sure you are calling iocInit.  After iocInit type this command:

asynReport 1

That will show you the status of each asyn port.

Mark


-----Original Message-----
From: 高振华 <gaozh at ihep.ac.cn> 
Sent: Wednesday, February 3, 2021 2:23 AM
To: Mark Rivers <rivers at cars.uchicago.edu>
Cc: tech-talk at aps.anl.gov
Subject: Re: Re: Re: modbus write registers error to Pilz PLC


Hi Mark,

I am contacting Pilz to see if it is possible to make the write address readable and write  (I am new to Pilz PLC and not familiar with its configuration process).

I tried the first method,
1) Set pollMsec=0 in the drvAsynModbusConfigure command for write operations.  
Set the pollMsec parameter for function codes 6 and 16 to 0, There was no error when starting IOC,However, function code 3's sending and receiving information is only displayed once and will not update the display (when tracing).
To view the status, use the dbstat command to display the following information:
segmentation fault(core dumped).
How to resolve this problem?
The following information is displayed when starting IOC:
[root@localhost iocTest]# ./Koyo1.cmd
#!./../../bin/linux-x86_64/modbusApp
< envPaths
epicsEnvSet("IOC","iocTest")
epicsEnvSet("TOP","/opt/epics/support/modbus")
epicsEnvSet("SUPPORT","/opt/epics/support")
epicsEnvSet("ASYN","/opt/epics/support/asyn")
epicsEnvSet("EPICS_BASE","/opt/epics/base")
dbLoadDatabase("../../dbd/modbus.dbd")
modbus_registerRecordDeviceDriver(pdbbase)
# Use the following commands for TCP/IP
drvAsynIPPortConfigure("Koyo1","192.168.70.40:502",0,0,1)
asynSetOption("Koyo1",0, "disconnectOnReadTimeout", "Y")
modbusInterposeConfig("Koyo1",0,5000,0)
# The DL205 has word access to the Xn inputs at Modbus offset 40400 (octal) # Read 8 words (128 bits).  Function code=3.
#drvModbusAsynConfigure("K1_Xn_Word",     "Koyo1", 0, 3, 040400, 010,    0,  100, "Koyo")
drvModbusAsynConfigure("K1_Xn_Word",     "Koyo1", 255, 3, 0x3,0x3,   0,  100, "Koyo")
# Write 8 words (128 bits).  Function code=6.
#drvModbusAsynConfigure("K1_Yn_Out_Word", "Koyo1", 255, 6, 0x0, 0x03,  0,  100, "Koyo") drvModbusAsynConfigure("K1_Yn_Out_Word", "Koyo1", 255, 6, 0x0, 0x03,  0,  0, "Koyo") # We access the same 16 words (C0-C377) as array outputs (256 bits). Function code=16.
#drvModbusAsynConfigure("K1_Cn_Out_Word_Array", "Koyo1", 255, 16, 0x0, 0x3,    0,   1, "Koyo")
drvModbusAsynConfigure("K1_Cn_Out_Word_Array", "Koyo1", 255, 16, 0x0, 0x3,    0,   0, "Koyo")
# Enable ASYN_TRACEIO_HEX on octet server
asynSetTraceIOMask("Koyo1",0,4)    
# Enable ASYN_TRACE_ERROR and ASYN_TRACEIO_DRIVER on octet server
asynSetTraceMask("Koyo1",0,9)
dbLoadTemplate("Koyo1.substitutions")
2021/02/03 11:11:03.048 192.168.70.40:502 write 12

00 01 00 00 00 06 ff 03 00 03 00 03
2021/02/03 11:11:03.058 192.168.70.40:502 read 15

00 01 00 00 00 09 ff 03 06 00 00 00 00 00 00 
epics> dbstat
Segmentation fault (core dumped)
[root@localhost iocTest]# 

thank you very much,
Gao Zhenhua



> -----原始邮件-----
> 发件人: "高振华" <gaozh at ihep.ac.cn>
> 发送时间: 2021-02-01 08:13:20 (星期一)
> 收件人: "mark rivers" <rivers at cars.uchicago.edu>
> 抄送: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
> 主题: Re: Re: modbus write registers error to Pilz PLC
> 
> 
> Hi Mark,
> Thank you very much for your advice,I will test it soon.
> 
> Best Wishes,
> Gao Zhenhua
> 
> 
> > -----原始邮件-----
> > 发件人: "Mark Rivers" <rivers at cars.uchicago.edu>
> > 发送时间: 2021-01-31 21:38:12 (星期日)
> > 收件人: "高振华" <gaozh at ihep.ac.cn>, "tech-talk at aps.anl.gov" 
> > <tech-talk at aps.anl.gov>
> > 抄送: 
> > 主题: Re: modbus write registers error to Pilz PLC
> > 
> > Hi Zhenhua,
> > 
> > 
> > I believe I understand the problem.   Here is some text from the EPICS Modbus documentation (https://epics-modbus.readthedocs.io/en/latest/) that explains the issue:
> > 
> > 
> > ***************************************************************
> > 
> > For write operations it is possible to specify that a single read operation should be done when the port driver is created. This is normally used so that EPICS obtains the current value of an output device when the IOC is initialized.
> > 
> > ...
> > 
> > drvModbusAsynConfigure(portName,
> >                        tcpPortName,
> >                        slaveAddress,
> >                        modbusFunction,
> >                        modbusStartAddress,
> >                        modbusLength,
> >                        dataType,
> >                        pollMsec,
> >                        plcType);
> > ...
> > 
> > pollMsec   int   Polling delay time in msec for the polling thread for read functions. For write functions, a non-zero value means that the Modbus data should be read once when the port driver is first created.
> > ...
> > Note for Wago devices
> > This initial read operation is normally done at the same Modbus address as the write operations. However, Wago devices are different from other Modbus devices because the address to read back a register is not the same as the address to write the register. For Wago devices the address used to read back the initial value for a Modbus write function must be 0x200 greater than the address for the write function. This is handled by adding this 0x200 offset for the readback address if the plcType argument to drvModbusAsynConfigure contains the substring “Wago” (case sensitive). Note that this does not affect the address for Wago read functions. The user must specify the actual Modbus address for read functions.
> > ***************************************************************
> > 
> > So when you create the ports for the output operations it is trying to read the current values from those registers because you have specified a non-zero value for pollMsec in your drvModbusAsynConfigure command.  That is generating Modbus exception 2 because the Pilz 4000 does not allow read operations on those registers.  There are 3 options to fix this problem:
> > 
> > 1) Set pollMsec=0 in the drvAsynModbusConfigure command for write operations.  This will fix the problem, but it means that the initial value of the output PV will not agree with the actual hardware value when the IOC boots.  That may or may not be OK for you.
> > 
> > 2) If possible configure the Pilz 4000 to allow read access to the same register addresses that it uses for write operations.
> > 
> > 3) If option 1 or 2 does not work for you then modify the driver so that if the plcType is Pilz4000 it uses an offset between the write and read addresses.  This is what is done for the Wago devices which have a similar problem.
> > 
> > Mark
> > 
> > 
> > ________________________________
> > From: 高振华 <gaozh at ihep.ac.cn>
> > Sent: Sunday, January 31, 2021 6:56 AM
> > To: Mark Rivers; tech-talk at aps.anl.gov
> > Subject: modbus write registers error to Pilz PLC
> > 
> > Hello Mark,
> > Can Modbus R2-11 be used on the Pilz 4000 PLC?
> > I am using the PILZ 4000 PLC, but an error exception=2 occurred while debugging Modbus TCP communication.
> > The IOC has been able to read multiple register (function code 3), 
> > But cannot write to a single register and write to multiple registers(function code 6 and function code 16),Error: exception=2.
> > Examples of Pilz PLC's command and return value formats are as follows:
> > (Confirmed with LabVIEW program)
> > Function code 6:
> > command: 0000 0000 0006 0106 0000 6262,
> > Note: 12 bytes in total.
> > Function code 16: Write three words
> > command: 0000 0000 000D 0110 0000 0003 0662 6263 6364 64
> > Note: 19 bytes in total.
> > PLC(server) read-write register address allocation during test is as 
> > follows: (data type:word)
> > 4x0001 to 4x0003 are the write addresses(0x0 to 0x2), (computer 
> > writes to the PLC),
> > 4x0004 to 4x0006 are read addresses(0x3 to 0x5), (computer reads 
> > from the PLC)
> > 
> > Here is Koyo1.cmd file:
> > dbLoadDatabase("../../dbd/modbus.dbd")
> > modbus_registerRecordDeviceDriver(pdbbase)
> > #drvAsynIPPortConfigure("Koyo1","164.54.160.158:502",0,0,1)
> > drvAsynIPPortConfigure("Koyo1","192.168.70.40:502",0,0,1)
> > asynSetOption("Koyo1",0, "disconnectOnReadTimeout", "Y")
> > modbusInterposeConfig("Koyo1",0,5000,0)
> > # The DL205 has word access to the Xn inputs at Modbus offset 40400 
> > (octal) # Read 8 words (128 bits).  Function code=3.
> > #drvModbusAsynConfigure("K1_Xn_Word",     "Koyo1", 0, 3, 040400, 010,    0,  100, "Koyo")
> > drvModbusAsynConfigure("K1_Xn_Word",     "Koyo1", 255, 3, 0x3,0x3,   0,  100, "Koyo")
> > 
> > # Write 8 words (128 bits).  Function code=6.
> > #drvModbusAsynConfigure("K1_Yn_Out_Word", "Koyo1", 0, 6, 040500, 010,    0,  100, "Koyo")
> > drvModbusAsynConfigure("K1_Yn_Out_Word", "Koyo1", 255, 6, 0x0, 0x03,  
> > 0,  100, "Koyo")
> > 
> > # We access the same 16 words (C0-C377) as array outputs (256 bits). Function code=16.
> > #drvModbusAsynConfigure("K1_Cn_Out_Word_Array", "Koyo1", 0, 16, 040600, 020,    0,   1, "Koyo")
> > drvModbusAsynConfigure("K1_Cn_Out_Word_Array", "Koyo1", 255, 16, 0x0, 0x3,    0,   1, "Koyo")
> > 
> > asynSetTraceIOMask("Koyo1",0,4)
> > asynSetTraceMask("Koyo1",0,9)
> > dbLoadTemplate("Koyo1.substitutions")
> > iocInit
> > Here is Koyo1.substitutions file:
> > # These are the Yn outputs done with word access.  Y0-Y7 file 
> > "../../db/bo_word.template" { pattern
> > {P,           R,          PORT,               OFFSET,   MASK,      ZNAM,   ONAM}
> > {KOYO1:,    Y0OutW,     K1_Yn_Out_Word,     0,        0x0001,    Low,    High}
> > {KOYO1:,    Y1OutW,     K1_Yn_Out_Word,     0,        0x0002,    Low,    High}
> > {KOYO1:,    Y2OutW,     K1_Yn_Out_Word,     0,        0x0004,    Low,    High}
> > {KOYO1:,    Y3OutW,     K1_Yn_Out_Word,     0,        0x0008,    Low,    High}
> > {KOYO1:,    Y4OutW,     K1_Yn_Out_Word,     0,        0x0010,    Low,    High}
> > {KOYO1:,    Y5OutW,     K1_Yn_Out_Word,     0,        0x0020,    Low,    High}
> > {KOYO1:,    Y6OutW,     K1_Yn_Out_Word,     0,        0x0040,    Low,    High}
> > {KOYO1:,    Y7OutW,     K1_Yn_Out_Word,     0,        0x0080,    Low,    High}
> > }
> > file "../../db/intarray_out.template" { pattern
> > {P,           R,            PORT,                  NELM}
> > {KOYO1:,    CnOutWArray,  K1_Cn_Out_Word_Array,    3}
> > }
> > 
> > Here is bo_word.template file:
> > [cid:54cafd04$1$17758759031$Coremail$gaozh$ihep.ac.cn]
> > Here is intarray_out.template file:
> > [cid:67c8a56d$2$17758759032$Coremail$gaozh$ihep.ac.cn]
> > Why is INP here instead of OUT?
> > drvModbusAsynConfigure function with function code 6: starting address 0x0, length 0x3.
> > [cid:5d690bc3$3$17758784fdc$Coremail$gaozh$ihep.ac.cn]
> > drvModbusAsynConfigure function with function code 16: starting address 0x0, length 0x3.
> > [cid:4b2a765d$4$177587b0f7a$Coremail$gaozh$ihep.ac.cn]
> > Please help to see what the reason is?
> > My application environment:
> > EPICS 7.0.3
> > Asyn R4-33
> > Modbus R2-11
> > 
> > Thanks
> > Gao Zhenhua
> > --
> > BSRF(Beijing Synchrotron Radiation Facility) 
> > Email:gaozh at ihep.ac.cn<mailto:gaozh at ihep.ac.cn>
 




Replies:
Re: RE: Re: Re: modbus write registers error to Pilz PLC 高振华 via Tech-talk
References:
modbus write registers error to Pilz PLC 高振华 via Tech-talk
Re: modbus write registers error to Pilz PLC Mark Rivers via Tech-talk
Re: Re: modbus write registers error to Pilz PLC 高振华 via Tech-talk
Re: Re: Re: modbus write registers error to Pilz PLC 高振华 via Tech-talk

Navigate by Date:
Prev: Autosave PVs showing up as INVALID(UDF_ALARM) Iain Marcuson via Tech-talk
Next: Re: Autosave PVs showing up as INVALID(UDF_ALARM) Mooney, Tim M. via Tech-talk
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  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Re: Re: modbus write registers error to Pilz PLC 高振华 via Tech-talk
Next: Re: RE: Re: Re: modbus write registers error to Pilz PLC 高振华 via Tech-talk
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  <20212022  2023  2024 
ANJ, 04 Feb 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·