Logic Machine Forum
AHU MODBUS TCP VALUE - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: AHU MODBUS TCP VALUE (/showthread.php?tid=1687)



AHU MODBUS TCP VALUE - Elmyran - 01.11.2018

Hi, I try to connect to Schneider-electric Homelynx and get the airflow from an IVP AHU ventilation unit with a climactix controller.
I need to compare two values in order to control a mixing valve.
The valve opens and closes until the two values are as equal as possible.
The value is to be retrieved from a Holding register with the address 4x0055 and 4x0056.
But unfortunately I do not get any values, it seems that it does not connect or I have typed the wrong code to get the air value correctly.

Code:
require('luamodbus')
if not mb then
   mb = luamodbus.tcp()
   mb:open('192.168.201.53')
   mb:connect()
end
mb:setdebug(true)
openvalue =  grp.getvalue('6/3/1')

tfvalue = mb:readinputregisters(54)
ffvalue = mb:readinputregisters(55)
mb:close()
if tfvalue > ffvalue then
 if openvalue < 220 then
   openvalue = openvalue + 25
 end
end
if ffvalue < ffvalue then
 if openvalue > 25 then
   openvalue = openvalue - 25
 end
end

grp.write('6/3/1', openvalue)

I would be very grateful if you can help me with this problem
/Tommy


RE: AHU MODBUS TCP VALUE - Erwin van der Zwart - 01.11.2018

Hi,

First of all you have not set a port on the Modbus TCP connection:
Code:
mb:open('192.168.201.53', 502)
Try also:
Code:
tfvalue, ffvalue = mb:readregisters(55, 2)

log(tfvalue,ffvalue)
If that does not work try changing 55 to 54

BR,

Erwin


RE: AHU MODBUS TCP VALUE - CHOUAIBOU - 01.11.2018

(01.11.2018, 19:42)Elmyran Wrote: Hi, I try to connect to Schneider-electric Homelynx and get the airflow from an IVP AHU ventilation unit with a climactix controller.
I need to compare two values in order to control a mixing valve.
The valve opens and closes until the two values are as equal as possible.
The value is to be retrieved from a Holding register with the address 4x0055 and 4x0056.
But unfortunately I do not get any values, it seems that it does not connect or I have typed the wrong code to get the air value correctly.

Code:
require('luamodbus')
if not mb then
   mb = luamodbus.tcp()
   mb:open('192.168.201.53')
   mb:connect()
end
mb:setdebug(true)
openvalue =  grp.getvalue('6/3/1')

tfvalue = mb:readinputregisters(54)
ffvalue = mb:readinputregisters(55)
mb:close()
if tfvalue > ffvalue then
 if openvalue < 220 then
   openvalue = openvalue + 25
 end
end
if ffvalue < ffvalue then
 if openvalue > 25 then
   openvalue = openvalue - 25
 end
end

grp.write('6/3/1', openvalue)

I would be very grateful if you can help me with this problem
/Tommy
Hi Tommy,
To establish modbus TCP connection between modbus master and modbus slave, you need to specify the port and the slave Id.


B.R,
Chouaibou.


RE: AHU MODBUS TCP VALUE - Erwin van der Zwart - 01.11.2018

Hi,

Not 100% sure but i believe slave id is optional by TCP device (without it the default is used).

BR,

Erwin


RE: AHU MODBUS TCP VALUE - admin - 02.11.2018

Is it a resident or a scheduled script? If it's resident then it will only work once because you are closing the connection via mb:close(). Setting slave id for TCP is optional by standard (255 is used when not set) but some devices might require it.

Start by logging each step return results:
Code:
require('luamodbus')
local mb = luamodbus.tcp()

local res, err = mb:open('192.168.201.53')
log('open', res, err)

local res, err = mb:connect()
log('connect', res, err)

local res, err = mb:readinputregisters(54)
log('read', res, err)

mb:close()



RE: AHU MODBUS TCP VALUE [solved] - Elmyran - 02.11.2018

Thanks for your help, I got the script to work today. When I contacted AHU, I realized that it was the wrong values I received. There were inputs 95 and 96 that I needed to compare.
Here is the final working code:

Code:
require('luamodbus')
if not mb then
   mb = luamodbus.tcp()
   mb:open('192.168.201.53', 502)
   mb:connect()
end

openvalue =  grp.getvalue('6/3/1', dt.uint8)

tfvalue = mb:readinputregisters(94, dt.uint16) -- 3x0095 Supply air flow
ffvalue = mb:readinputregisters(95, dt.uint16) -- 3x0096 Exhaust air flow
if tfvalue and ffvalue == 0 then
  openvalue = 0
end
if tfvalue < ffvalue then
  if openvalue < 220 then
    openvalue = openvalue + 25
  end
end
if tfvalue > ffvalue then
if openvalue > 25 then
openvalue = openvalue - 25
end
end
grp.write('6/3/1', openvalue, dt.int8)

it was as simple as that. Big Grin