Logic Machine Forum
TCP Modbus - 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: TCP Modbus (/showthread.php?tid=688)

Pages: 1 2


TCP Modbus - leondias - 21.03.2017

Hello,

I'm trying to make a connection with Modbus TCP slave device.

I tried to do so with scripts (you can see it below) and visual mapper.
In visual mapper I tried many different combinations in device profile, but couldn't get right value:

Code:
{ "name": "Input 1", "bus_datatype": "float16", "type": "register", "address": 128, "datatype": "float16", "value_multiplier": 1, "units": " C" },
{ "name": "Input 1", "bus_datatype": "uint16", "type": "register", "address": 128, "datatype": "float16", "value_multiplier": 1, "units": " C" },
{ "name": "Input 1", "bus_datatype": "int16", "type": "register", "address": 128, "datatype": "int16", "value_multiplier": 1, "units": " C" }
and etc..

Full script (IP address of device is corrent - 192.168.1.210, port - 502, slave ID - 20):
Code:
require('luamodbus')

if not mb then
    mb = luamodbus.tcp()
    mb:open('192.168.1.210')
    mb:connect()
end

-- verbose output and select slave number 10
mb:setdebug(true)
mb:setslave(20)

-- read input from reg 1 to 5, get slave-specific data
local result = mb:readregistervalue(128, dt.float16)
grp.write('14/1/0', result, dt.float16)


local value = mb:reportslaveid()
alert(value)

-- close serial connection
mb:close()



RE: TCP Modbus - admin - 21.03.2017

Are you sure it's float16 on ModBus side? float16 is KNX-specific datatype and I've only seen one ModBus AC unit which has it as register value. Also, second mb:readregistervalue() parameter must be a string, not a dt.something. Do you have documentation for your ModBus device?


RE: TCP Modbus - leondias - 21.03.2017

(21.03.2017, 14:34)admin Wrote: Are you sure it's float16 on ModBus side? float16 is KNX-specific datatype and I've only seen one ModBus AC unit which has it as register value. Also, second mb:readregistervalue() parameter must be a string, not a dt.something. Do you have documentation for your ModBus device?

Yes, here it is

Now I try to read jus a outdoor temp. to get started. In the documentation its 129 address, but I'm trying with all 128, 129 and 130 to be sure Smile


RE: TCP Modbus - admin - 21.03.2017

Datatype should be "float32", you also might have to set "read_swap" property as stated here: http://openrb.com/docs/modbus.htm


RE: TCP Modbus - leondias - 21.03.2017

(21.03.2017, 14:42)admin Wrote: Datatype should be "float32", you also might have to set "read_swap" property as stated here: http://openrb.com/docs/modbus.htm

Can I use this property in script or only in visual mapper?
If yes, how?


RE: TCP Modbus - admin - 21.03.2017

You can use in both, but first you need to figure out correct byte/word order by using this in your script:
Code:
v1 = mb:readregistervalue(128, 'float32', 'n')
v2 = mb:readregistervalue(128, 'float32', 'b')
v3 = mb:readregistervalue(128, 'float32', 'w')
v4 = mb:readregistervalue(128, 'float32', 'bw')
log(v1, v2, v3, v4)

One of the values in logs should be correct.


RE: TCP Modbus - leondias - 22.03.2017

Thanks a lot! It works!


RE: TCP Modbus - unaxboy - 13.11.2017

(22.03.2017, 07:38)leondias Wrote: Thanks a lot! It works!

Hi leondias, I also trying to config Ping2. Can you share json with me?)


RE: TCP Modbus - unaxboy - 29.11.2017

(21.03.2017, 14:39)leondias Wrote:
(21.03.2017, 14:34)admin Wrote: Are you sure it's float16 on ModBus side? float16 is KNX-specific datatype and I've only seen one ModBus AC unit which has it as register value. Also, second mb:readregistervalue() parameter must be a string, not a dt.something. Do you have documentation for your ModBus device?

Yes, here it is

Now I try to read jus a outdoor temp. to get started. In the documentation its 129 address, but I'm trying with all 128, 129 and 130 to be sure Smile

I try do the same, but with writable addresses (315, 513, 533, 771, 1050).

Please, can someone help?


RE: TCP Modbus - admin - 29.11.2017

Are you trying to make a profile or use scripts? In any case you need to subtract 1 from documented address, so 315 becomes 314 and so on.


RE: TCP Modbus - unaxboy - 29.11.2017

(29.11.2017, 13:09)admin Wrote: Are you trying to make a profile or use scripts? In any case you need to subtract 1 from documented address, so 315 becomes 314 and so on.

I trying with profile. With read only addresses it works without subtract.


RE: TCP Modbus - admin - 29.11.2017

For writable addresses you have to add "writable": true


RE: TCP Modbus - unaxboy - 29.11.2017

(29.11.2017, 13:35)admin Wrote: For writable addresses you have to add "writable": true

My code:

Code:
   {
     "name": "Start/Stop",
     "bus_datatype": "bool",
     "datatype": "float32",
     "type": "register",
     "address": 315,
     "writable": 1,
     "value_custom": {
       "0": "Stop",
       "1": "Start",
     "read_swap": "n"
     }
   },



RE: TCP Modbus - admin - 29.11.2017

datatype must be int16 or uint16, also try address 314


RE: TCP Modbus - unaxboy - 29.11.2017

(29.11.2017, 15:54)admin Wrote: datatype must be int16 or uint16, also try address 314

Thanks! It's working. Trying the same for 771 (770). No luck(


RE: TCP Modbus - admin - 29.11.2017

What value are you getting? Try setting read_swap to b, datatype should be set to uint16, bus_datatype can be float16 and set value_multiplier to 0.01


RE: TCP Modbus - unaxboy - 29.11.2017

(29.11.2017, 17:15)admin Wrote: What value are you getting? Try setting read_swap to b, datatype should be set to uint16, bus_datatype can be float16 and set value_multiplier to 0.01

Thank you! Setting value_multiplier to 0.01 helped.

For everyone who use Komfovent Ping2 (modbus gateway for Komfovent ventilation AHU) my profile in attachment.


RE: TCP Modbus - Igor68 - 17.12.2017

Hi, help, please solve the problem. It is necessary to send a command to the infrared module using the Modbus TCP/IP protocol.
Team 01 02 00 00 00 0B 01 10 04 4F 00 02 04 00 03
Where 01 02 00 00 00 0B - MBAP header
01-number of the device in the network ID
10-function command FC
04 4F -address
mb: writeregisters (1103,0, 3) does not work.
With the help of programm Modbus Pool, commands are sent and executed)


RE: TCP Modbus - admin - 18.12.2017

Try adding mb:setslave(1) before writeregisters


RE: TCP Modbus - SportMaster10 - 12.09.2019

Hi!

A Komfovent DOMEKT REGO-400PE-AC-C4 recuperator with C4-plus automation is installed in my house.
According to the documentation (https://www.vortvent.nl/wp-content/uploads/2017/06/Vortvent-Komfovent-Modbus-registerlijst-C4-regeling-EN-2016.pdf) port settings 19200-8E1, slave_id = 20 , registrs 1000-1362.
Experimentally discovered that in fact the registers start at 10000.
Maybe someone has a complete list of registers and their purpose for C4-plus?

Thanks.