Firstly, thanks for your respond !
But the problem still exists, let me describe it in details.
The modbus version is R1-2(very old version).
And the contents of st.cmd file are posted in the following:
#!../../bin/linux-x86_64/modbusApp
< envPaths
dbLoadDatabase("../../dbd/modbus.dbd")
modbus_registerRecordDeviceDriver(pdbbase)
# Use the following commands for TCP/IP
#read Device ID 2
drvAsynIPPortConfigure("AGM16-007", "192.168.1.241:502",0,1,1)
modbusInterposeConfig("AGM16-007", 2,0,2000)
# Read 100 words (1600 bits). Function code=3.
drvModbusAsynConfigure("RD1R", "AGM16-007", 3, 0, 95, 0, 1130, "rpDevice")
# Write 8 words (128 bits). Function code=16
drvModbusAsynConfigure("parawrite1", "AGM16-007", 16, 48, 8, 0, 10000, "rpDevice")
drvModbusAsynConfigure("timewrite1", "AGM16-007", 16, 64, 7, 0, 10000, "rpDevice")
#
dbLoadRecords("../../db/ssrfdb/RPmodbus.db","RPNAM=Gamma:01, PORT=RD1R, paraWDPORT=parawrite1, timeWDPORT=timewrite1")
iocInit
#################################################
After running, epics displays the following errors during its initialization:
2017/01/27 12:55:21.149 drvModbusAsyn::doModbusIO port parawrite1 is disconnected
Here is the whole messages:
[rp@localhost iocTest]$ ./test.cmd
#!../../bin/linux-x86_64/modbusApp
< envPaths
epicsEnvSet("ARCH","linux-x86_64")
epicsEnvSet("IOC","iocTest")
epicsEnvSet("TOP","/home/rp/epicswork/modbusR1-2")
epicsEnvSet("EPICS_BASE","/home/rp/epics/base-3.14.12.5")
epicsEnvSet("ASYN","/home/rp/epics/modules/asyn-4.9")
epicsEnvSet("GENSUB","/home/rp/epics/modules/genSubV1-6")
dbLoadDatabase("../../dbd/modbus.dbd")
modbus_registerRecordDeviceDriver(pdbbase)
# Use the following commands for TCP/IP
#read Device ID 2
drvAsynIPPortConfigure("AGM16-007", "192.168.1.241:502",0,1,1)
modbusInterposeConfig("AGM16-007", 2,0,2000)
# Read 100 words (1600 bits). Function code=3.
drvModbusAsynConfigure("RD1R", "AGM16-007", 3, 0, 95, 0, 1130, "rpDevice")
# Write 8 words (128 bits). Function code=16
drvModbusAsynConfigure("parawrite1", "AGM16-007", 16, 48, 8, 0, 10000, "rpDevice")
2017/01/27 12:55:21.149 drvModbusAsyn::doModbusIO port parawrite1 is disconnected
drvModbusAsynConfigure("timewrite1", "AGM16-007", 16, 64, 7, 0, 10000, "rpDevice")
###
dbLoadRecords("../../db/ssrfdb/RPmodbus.db","RPNAM=DCLS:RP:Gamma:01, PORT=RD1R, paraWDPORT=parawrite1, timeWDPORT=timewrite1")
iocInit
Starting iocInit
############################################################################
## EPICS R3.14.12.5 $Date: Tue 2015-03-24 09:57:35 -0500$
## EPICS Base built Jan 25 2017
############################################################################
iocRun: All initialization complete
epics>
Now I can read data from device, but the problem is I cannot set parameters to device.
for example, I can read Hour from device in addr 68, but i cannot write new hour to device using the db.
This is the correct db that read Hour from device:
record(ai, "$(RPNAM):HourVal"){
field(DTYP,"asynInt32")
field(INP, "@asynMask($(PORT) 68 16)MODBUS_DATA")
field(SCAN,"Passive")
field(FLNK, "$(RPNAM):WeekVal")
}
This is the db that I try to write Hour to device:
record(ao, "$(RPNAM):HourValSET"){
field(DTYP,"asynInt32")
field(OUT, "@asyn($(PORT), 68)")
field(SCAN,"Passive")
}
by typing the command to set new hour value '15':
caput Gamma:01:HourValSET 15
The error message displays in the following:
epics> 2017/01/27 12:56:04.314 drvModbusAsyn::writeInt32 port RD1R invalid request for Modbus function 3
2017/01/27 12:56:04.314 DCLS:RP:Gamma:01:HourValSET devAsynInt32 process error
Any suggestions and many thanks in advance !
Zhefu
You need to specify a MODBUS output function code ― function code 6 to write a single holding register, function code 16 to write multiple holding registers. Here re a couple examples
drvModbusAsynConfigure("eps1_io", "epsPLC_1", 0, 6, 16000, 1, 0, 1000, "Wago")
drvModbusAsynConfigure("eps1_ao", "epsPLC_1", 0,16, 17216, 54, 0, 1000, "Wago”)
Hi,
Below is the correct db that can read hour from the device:
record(ai, "$(RPNAM):HourVal"){
field(DTYP,"asynInt32")
field(INP, "@asynMask($(PORT) 68 16)MODBUS_DATA")
field(SCAN,"Passive")
field(FLNK, "$(RPNAM):WeekVal")
}
now, I want to set new hour to the device and I try to write the following db according to Analog Output Example Record from
"asynDriver: Asynchronous Driver Support" manual:
record(ao, "$(RPNAM):HourValSET"){
field(DTYP,"asynInt32")
field(OUT, "@asyn($(PORT), 68)")
field(SCAN,"Passive")
}
however, I failed, epics gives the following error messages:
drvModbusAsyn::writeInt32 port RD1R invalid request for Modbus function 3
Gamma:01:HourValSET devAsynInt32 process error
Could anyone give me some suggestions and thanks in advance !