Logic Machine Forum
Modbus variables: import massive - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Modbus variables: import massive (/showthread.php?tid=1371)

Pages: 1 2


Modbus variables: import massive - Domoticatorino - 02.05.2018

Dear all, 
I am workin on a project on which LM will be communicate with 4 modbus devices in TCP/IP.

Every devices will have about 300 modbus variables.

Obviously I will import variables with Json file. Considering the big amount of variables is there the opportunity to link the modbus variable to KNX address in automatic and not manually step by step?

Because if I do a mistake with json file then I have to link modbus variables to knx group address again. 

Is there any help about that?

Thanks.


RE: Modbus variables: import massive - Erwin van der Zwart - 03.05.2018

Hi,

You can use this script to map your modbus profiles to objects automatically.
.lua   Auto create objects and map to modbus profile.lua (Size: 1.13 KB / Downloads: 134)


PS: Make backup before you run it because there is a lot created (:

It creates 255 objects each run and skips already mapped objects, so you need to change to address scope and run it again for the next 255 objects. So for 1200 objects you need to run it 5 times.

BR,

Erwin


RE: Modbus variables: import massive - Domoticatorino - 03.05.2018

Thank you very much Erwin,
I have seen that entries modbus are the folling:

"id", "internal_id", "device", "name", "active", "bus_write", "bus_address", "bus_datatype", "internal", "type", "value_delta","value_base","value_multiplier","value_bitmask","value_nan","value_conv","value_custom","units","address","address_scale","read_count","read_offset","read_swap","datatype","writable","write_only","write_multiple"

In json file has to be declared all of them or it is not necessary?

Thanks.


RE: Modbus variables: import massive - admin - 03.05.2018

Mandatory fields are marked with "Required":
http://openrb.com/docs/modbus.htm


RE: Modbus variables: import massive - Domoticatorino - 03.05.2018

Ok then. Thanks.

I love LM because there's a solution for everything.
Thanks to all team.


RE: Modbus variables: import massive - fabiorusco - 21.03.2019

Hello,
how many modbus variable can used in a Spacelynk modbus profile? The device connetted will be one.

Best regards


RE: Modbus variables: import massive - Daniel - 21.03.2019

(21.03.2019, 07:26)fabiorusco Wrote: Hello,
how many modbus variable can used in a Spacelynk modbus profile? The device connetted will be one.

Best regards

Technically there is no limit but more you add you will need longer pooling time.


RE: Modbus variables: import massive - fabiorusco - 22.03.2019

(21.03.2019, 08:33)Daniel. Wrote:
(21.03.2019, 07:26)fabiorusco Wrote: Hello,
how many modbus variable can used in a Spacelynk modbus profile? The device connetted will be one.

Best regards

Technically there is no limit but more you add you will need longer pooling time.

I have about 500 modbus variables.


RE: Modbus variables: import massive - Daniel - 22.03.2019

(22.03.2019, 07:33)fabiorusco Wrote:
(21.03.2019, 08:33)Daniel. Wrote:
(21.03.2019, 07:26)fabiorusco Wrote: Hello,
how many modbus variable can used in a Spacelynk modbus profile? The device connetted will be one.

Best regards

Technically there is no limit but more you add you will need longer pooling time.

I have about 500 modbus variables.

Above they mention 4 slaves with each 300 objects so 1200 in total.


RE: Modbus variables: import massive - fabiorusco - 22.03.2019

(22.03.2019, 08:16)Daniel. Wrote:
(22.03.2019, 07:33)fabiorusco Wrote:
(21.03.2019, 08:33)Daniel. Wrote:
(21.03.2019, 07:26)fabiorusco Wrote: Hello,
how many modbus variable can used in a Spacelynk modbus profile? The device connetted will be one.

Best regards

Technically there is no limit but more you add you will need longer pooling time.

I have about 500 modbus variables.

Above they mention 4 slaves with each 300 objects so 1200 in total.
Thank you!


RE: Modbus variables: import massive - fabiorusco - 02.04.2019

Hello,
I use spacelynk like a modbus slave (The master is a Scada). I will comunicate DI, AI, DO, AO with the Scada.
It's possible use modbus json profile to implement it?
Otherwise can I create a list with all the objects (modbus-KNX) and a script to implement it?
Thank you in advance.


RE: Modbus variables: import massive - Daniel - 02.04.2019

(02.04.2019, 06:20)fabiorusco Wrote: Hello,
I use spacelynk like a modbus slave (The master is a Scada). I will comunicate DI, AI, DO, AO with the Scada.
It's possible use modbus json profile to implement it?
Otherwise can I create a list with all the objects (modbus-KNX) and a script to implement it?
Thank you in advance.

Hi
For slave you have to use script. Fallow this example.
http://openrb.com/lm-as-modbus-tcp-slave/
BR


RE: Modbus variables: import massive - fabiorusco - 02.04.2019

I must manage the objects of the attached pdf file.

Write a script it's no easy, without a profile.

(02.04.2019, 10:46)fabiorusco Wrote: I must manage the objects of the attached pdf file.

Write a script it's no easy, without a profile.



RE: Modbus variables: import massive - Daniel - 02.04.2019

Profiles are only for master, there is no other way. This script is very ease, you just have to fill the array for object mapping and corresponding dpts in second array.


RE: Modbus variables: import massive - fabiorusco - 02.04.2019

Can you give me an example?
Thank you


RE: Modbus variables: import massive - Daniel - 02.04.2019

I sent you already full example above.  You need to fill these arrays


Code:
 -- list of coil mapping, starting from 0
 coils = { '1/1/1', '1/1/2' }

 -- list of register mapping, starting from 0
 registers = { '2/2/2', '3/3/3' }

 -- list of register data types, element count must match registers table
 regdt = { dt.int8, dt.uint16 }

[*]

Coils are binary objects and there you just add group addresses.
Registers are numeric objects and there you also have to add group addresses. 
For registers you also have to add register dpt in regdt table.  In this example group 2/2/2 is dt.int8, and group 3/3/3 is dt.uint16.  For each register you need to add dpt in next table in the same order.
Hope this is clear.


RE: Modbus variables: import massive - admin - 03.04.2019

The memory map that you have uses registers as bit masks. If this can be changed I suggest using coils instead which are meant for storing Boolean variables. This will make mapping to objects much easier.


RE: Modbus variables: import massive - fabiorusco - 03.04.2019

The memory map is mandatory, I can't change it. How can manage the masks?


RE: Modbus variables: import massive - admin - 03.04.2019

You will need extra scripts to create bitmask values from binary objects, see this post: https://forum.logicmachine.net/showthread.php?tid=1777


RE: Modbus variables: import massive - Daniel - 04.04.2019

Hi
Here is modified slave script.  I doubled the arrays for registers and added a shift.  Fill accordingly all the arrays.  registers1 will start from 4096 and registers2 will start from 8192. Make sure you add corresponding regdt for each register.  Shift can be changes by shiftR1 or shiftR2 parameter.

Code:
   if not mb then
     require('genohm-scada.eibdgm')
     require('luamodbus')
   
     -- list of coil mapping, starting from 0
     coils = { }
   
         -- registers table 1 shift starting from 1
         shiftR1 = 4095
             -- list of register mapping, starting from 4096
     registers1 = { '3/1/26', '3/1/29' }
       -- list of register data types, element count must match registers table
     regdt1 = { dt.int16, dt.int16 }
 
       
         -- registers table 2 shift starting from 1
            shiftR2 = 8191
          -- list of register mapping, starting from 8192
     registers2 = { '3/1/32', '3/1/35' }
       -- list of register data types, element count must match registers table
     regdt2 = { dt.int16, dt.int16 }  
 
 
   
   
   
     -- 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 register1
       for id, addr in ipairs(registers1) do
         if event.dst == addr then
           value = knxdatatype.decode(event.datahex, regdt1[ id ])
           mb:setregisters(id + shiftR1, value)
         end
       end
            -- try to find matching register2
       for id, addr in ipairs(registers2) do
         if event.dst == addr then
           value = knxdatatype.decode(event.datahex, regdt2[ id ])
           mb:setregisters(id + shiftR2, 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 addr1 = registers1[ register -shiftR1 ]
           local addr2 = registers2[ register -shiftR2 ]
       if addr1 then
         grp.write(addr1, value, regdt1[ register - shiftR1])
              elseif addr2 then
         grp.write(addr2, value, regdt2[ register - shiftR2])
       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('0.0.0.0', 502)
   
     -- setting slave id is optional
     -- mb:setslave(1)
   
     mb:setreceivetimeout(0.1)
     mb:setmapping(#coils, 0, shiftR2 + 1 + #registers2, 0)
   
     -- init coils
     for id, addr in ipairs(coils) do
       value = grp.getvalue(addr)
       mb:setcoils(id - 1, value)
     end
   
     -- init registers1
     for id, addr in ipairs(registers1) do
       value = grp.getvalue(addr)
       mb:setregisters(id + shiftR1, value)
     end
       -- init registers2
     for id, addr in ipairs(registers2) do
       value = grp.getvalue(addr)
       mb:setregisters(id + shiftR2, value)
     end
   
     -- set callbacks for coil and register write
     mb:setwritecoilcb(mbwritecoils)
     mb:setwriteregistercb(mbwriteregisters)
   end
   
   -- handle modbus and knx
   mb:handleslave()
   knxclient:step()