hacker-cb / modbus-dart

BSD 3-Clause "New" or "Revised" License
37 stars 22 forks source link

Use of unit ID's is available #6

Closed Exquemelin closed 3 years ago

Exquemelin commented 3 years ago

Hello Hacker-CB,

I have been testing your modbus package in a LAN where I have a modbus/TCP converter, with two slave devices, so I needed to implement the use of unitID's. It works fine for me, using an app coded with fllutter.

I prefer to put the unitID as a optional parameter in the functions, so it still work with older versions of the package. If you have any question, don't hesitate to ask it to me. I hope that this code will be useful for you.

hacker-cb commented 3 years ago

Hello @Exquemelin.

Thank you for your work, but seems that it is very complicated to pass unitId as parameter over all methods.

I made more simple solution for you: https://github.com/Hacker-CB/modbus-dart/tree/unit_id Please try, and I will merge it to master if all is ok.

Exquemelin commented 3 years ago

Hello @Hacker-CB ,

I considered using the unitID as part of the conection as you use it. But I prefer to stablish only one conection to send messages to both devices, using an unique conection.

I have been testing your solution and it works properly. Even, if I use two simultaneous conections and petitions. You can merge it to the master. Thank you for your support.

hacker-cb commented 3 years ago

@Exquemelin

You don't need to use multiply connections. Just call client.setUnitId(XXX) between calls. I added example to README. Please confirm.

https://github.com/Hacker-CB/modbus-dart/blob/unit_id/README.md

hacker-cb commented 3 years ago

Merged to master 66b35cc0d8ba5c8f3db7b22e5f8673ea6208dce5, in version 0.1.0

Exquemelin commented 3 years ago

Ok, I understand what you mean. It's a good solution.

hacker-cb commented 3 years ago

Ok, great. So, you can use it in latest release