This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus rs485-2
#1
Hi

I have some projects where I need to use 2 RS485 ports on each LM5. 
On the current firmware the second port must be implemented using scripts, is this correct?

I need to integrate a heatpump with approximately 20 registers. 
It only possible to read one register at the time, with a max poll-frequense of 1 sec.

Is the datatype inside the ( ), the knx variable or the MB-registers dataype? 
All the registers are holding registers with the INT16, on modbus-slave, and are actually temperatures with the scaling 0.1.
Is this conversation done correctly in my script......?

I haven't used scripting on modbus for quite some time, so I wonder if the code is correct(ish Smile ):

Code:
--Heatpump, with a maximum polling frequens 1s for each register, and timeout 2,3sek
--If the polling of each adress is faster than 1 sec, the communication of the slave stops and the slave have to reboot
--what should the resident-script's sleep intervall be in this case (1 sec, between every execute)
--the os.sleep(1) is used to ensure that poll frequens is slow enough is this the correct approach??
--and will the log(err) be the correct code and is the value_1, err = the correct way to do this?

require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(1) --modbusadresse
mb:setresponsetimeout(3) 


--Register 1
value_1, err = mb:readregistervalue(40004, "float16")
grp.checkwrite(32/3/1, value_1*0.1) --respose-value from the slave??? 
log(err) --logs the response like time out?

os.sleep(1) --used to make sure it's only one poll to slave each second??? 

--Register 2
value_2, err = mb:readregistervalue(40014, "float16")
grp.checkwrite(32/3/2, value_2*0.1)
log(err)

os.sleep(1)

--Register 3
value_3, err = mb:readregistervalue(40018, "float16")
grp.checkwrite(32/3/3, value_3*0.1)
log(err)

os.sleep(1)
--Register 4
value_4, err = mb:readregistervalue(40062, "float16")
grp.checkwrite(32/3/4, value_4*0.1)
log(err)

os.sleep(1)

--Register 5
value_5, err = mb:readregistervalue(40080, "float16")
grp.checkwrite(32/3/5, value_5*0.1)
log(err)

os.sleep(1)

--Register 6
value_6, err = mb:readregistervalue(40106, "float16")
grp.checkwrite(32/3/6, value_6*0.1)
log(err)

os.sleep(1)

--Register 7
value_7, err = mb:readregistervalue(40128, "float16")
grp.checkwrite(32/3/7, value_7*0.1)
log(err)

os.sleep(1)

--Register 8
value_8, err = mb:readregistervalue(42102, "float16")
grp.checkwrite(32/3/8, value_8*0.1)
log(err)

os.sleep(1)

--Register 9
value_9, err = mb:readregistervalue(42148, "float16")
grp.checkwrite(32/3/9, value_9*0.1)
log(err)

os.sleep(1)

--Register 10
value_10, err = mb:readregistervalue(43002, "float16")
grp.checkwrite(32/3/10, value_10*0.1)
log(err)

os.sleep(1)

--Register 11
value_11, err = mb:readregistervalue(43008, "float16")
grp.checkwrite(32/3/11, value_11*0.1)
log(err)

os.sleep(1)

--Register 12
value_12, err = mb:readregistervalue(43018, "float16")
grp.checkwrite(32/3/12, value_12*0.1)
log(err)

os.sleep(1)

--Register 13
value_13, err = mb:readregistervalue(43038, "float16")
grp.checkwrite(32/3/13, value_13*0.1)
log(err)

os.sleep(1)

--Register 14
value_14, err = mb:readregistervalue(43146, "float16")
grp.checkwrite(32/3/14, value_14*0.1)
log(err)

os.sleep(1)

--Register 15
value_15, err = mb:readregistervalue(44004, "float16")
grp.checkwrite(32/3/15, value_15*0.1)
log(err)

os.sleep(1)

--Register 16
value_16, er = mb:readregistervalue(44008, "float16")
grp.checkwrite(32/3/16, value_16*0.1)
log(err)

os.sleep(1)

--Register 17
value_17, err = mb:readregistervalue(44010, "float16")
grp.checkwrite(32/3/17, value_17*0.1)
log(err)

os.sleep(1)

--Register 18
value_18, err = mb:readregistervalue(44018, "float16")
grp.checkwrite(32/3/18, value_18*0.1)
log(err)

os.sleep(1)

--Register 19
value_19, err = mb:readregistervalue(44124, "float16")
grp.checkwrite(32/3/19, value_19*0.1)
log(err)

os.sleep(1)

--Register 20
value_20, err = mb:readregistervalue(44126, "float16")
grp.checkwrite(32/3/20, value_20*0.1)
log(err)

os.sleep(1)

mb:close()

Hope someone could give me some feedback or friendly advise on this one Big Grin

BR
Eirik
Reply


Messages In This Thread
Modbus rs485-2 - by eirik - 26.05.2018, 08:08
RE: Modbus rs485-2 - by admin - 26.05.2018, 09:59

Forum Jump: