Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
Hi! I ask for your help, I am a beginner.
I am using LM as Slave via script.
When I try to write an integer value in my PLC to an integer register (uint16 in LM), I cannot do it. But if I write a floating point value to this register, then an integer value is written.
When I test in Modbus Poll, I have the status “illegal data address” Slave LM.
is it an offset problem? What should I do?
Posts: 4638
Threads: 24
Joined: Aug 2017
Reputation:
207
It might help if you show us the slave script.
------------------------------
Ctrl+F5
Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
27.11.2020, 10:04
(This post was last modified: 27.11.2020, 10:06 by ikhy.)
Code: if not mb then
require('genohm-scada.eibdgm')
require('luamodbus')
-- list of coil mapping, starting from 0
coils = { '1/1/1', '1/1/2','1/1/3' ,'1/1/4' }
-- list of register mapping, starting from 0
registers = { '3/1/1', '3/1/2'}
-- list of register data types, element count must match registers table
regdt = { dt.uint16,dt.uint16}
-- knx group write callback
function knxgroupwrite(event)
local value
-- try to find matching coil
for id, addr in ipairs(coils) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, dt.bool)
mb:setcoils(id - 1, value)
end
end
-- try to find matching register
for id, addr in ipairs(registers) do
if event.dst == addr then
value = knxdatatype.decode(event.datahex, regdt[ id ])
mb:setregisters(id - 1, value)
end
end
end
-- coil write callback
function mbwritecoils(coil, value)
local addr = coils[ coil + 1 ]
if addr then
grp.write(addr, value, dt.bool)
end
end
-- register write callback
function mbwriteregisters(register, value)
local addr = registers[ register + 1 ]
if addr then
grp.write(addr, value, regdt[ register + 1])
end
end
-- knx group monitor, handles group writes
knxclient = eibdgm:new({ timeout = 0.1 })
knxclient:sethandler('groupwrite', knxgroupwrite)
-- modbus slave, listen on all interfaces and default port 502
mb = luamodbus.tcp()
mb:open('хх.хх.хх.хх', 502)
-- setting slave id is optional
--mb:setslave(1)
mb:setreceivetimeout(0.1)
mb:setmapping(#coils, 0, #registers, 0)
-- init coils
for id, addr in ipairs(coils) do
value = grp.getvalue(addr)
mb:setcoils(id - 1, value)
end
-- init registers
for id, addr in ipairs(registers) do
value = grp.getvalue(addr)
mb:setregisters(id - 1, value)
end
-- set callbacks for coil and register write
mb:setwritecoilcb(mbwritecoils)
mb:setwriteregistercb(mbwriteregisters)
end
-- handle modbus and knx
mb:handleslave()
knxclient:step()
changed nothing
Posts: 4638
Threads: 24
Joined: Aug 2017
Reputation:
207
You have done everything correct here. I assume the objects 3/1/1 and 3/1/2 are 2 byte unsigned integer?
------------------------------
Ctrl+F5
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Which address are you using from ModBus side? You can only use 0 and 1 because you have 2 registers defined.
Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
27.11.2020, 10:14
(This post was last modified: 27.11.2020, 10:39 by ikhy.)
(27.11.2020, 10:11)admin Wrote: Which address are you using from ModBus side? You can only use 0 and 1 because you have 2 registers defined. yes. use 0 and 1 registers
immediately after connecting to LM
and I can write data from Modbus Poll. But from one type PCL i can not. and from other type PLC I can only when I write float
(27.11.2020, 10:09)Daniel. Wrote: You have done everything correct here. I assume the objects 3/1/1 and 3/1/2 are 2 byte unsigned integer? yes
I think maybe my controller starts reading not from 0, but from 16 bits. therefore, he understands part of the float as integer. And i need to do offset. is it possible?
Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
please, can you test this script in some Modbus Server? do you get an "illegal data address" too?
"illegal data address" : The data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid.
Posts: 4638
Threads: 24
Joined: Aug 2017
Reputation:
207
This script was used in many projects and nobody had this issue. Try reading register 1.
------------------------------
Ctrl+F5
Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
yes-yes! i totally agree with you. i see how many people use it. i only want to understand where is my issues. i can read and write values via modbus server but with errors.
Posts: 4638
Threads: 24
Joined: Aug 2017
Reputation:
207
The issue is somewhere in config of your PLC.
PS. LM is modbus server here, your PLC is client.
------------------------------
Ctrl+F5
Posts: 52
Threads: 13
Joined: Feb 2020
Reputation:
0
(27.11.2020, 13:22)Daniel. Wrote: The issue is somewhere in config of your PLC.
PS. LM is modbus server here, your PLC is client. yes! it was PLC issues. Thank you for the help!
|