01-19-2021 02:58 AM
This is a stand alone VI which is basically finished and is working but I have two questions.
Would it be better to put the Read operations in a loop? I have two different devices on the same network. I ask because I am working on a second project where I have a single device but need to read 80 registers and the block diagram is working but is messy.
Although the VI works,as far as I can test it at present, I think I am missing the close Modbus. Where should I put that?
Many thanks.
Mark
01-19-2021 06:41 AM
I would recommend that you open your Modbus connections outside the while loop and wire the references to shift registers. You only need two Modbus sessions since three of the reads you do are to the same device. You can place the Modbus close on the outside of the while loop after it has stopped. Internally, simply read the registers that you need. You shouldn't be opening the connection every iteration of the loop. Open once, poll your data and then close once your application is complete.
01-19-2021 06:55 AM
Sorry but I do not quite understand.
opening the Modbus connection is done in the sub VI. Do you mean I should change this as well? Set IP and port (502) and New TCP Master outside the while loop (2 of them, one for each IP). But I cannot see how I pass the 4 starting addresses to the read Modbus. Am I missing something?
The TCPMaster instance(s) I need to pass throung the whole VI to a close Modbus outside the loop. I think I understand that.
"You shouldn't be opening the connection every iteration of the loop."
Although it works, I thought this was not a good idea.
Regards
Mark
01-19-2021 07:13 AM
Yes, your subVI would need to change. The subVI should accept the Modbus reference and the address to be read. The subVI should also pass the unmodified Modbus reference out.
Here is the basic concept:
01-20-2021 03:05 AM - edited 01-20-2021 03:07 AM
Thanks Mark, I changed the subVI accordingly and updated my main VI. Will test it as soon as possible.
Just one question: On the outer loop you have shift registers and I have used tunnels. Is this wrong?
Regards
Mark
01-20-2021 09:09 AM - edited 01-20-2021 09:13 AM
There is no need for the Flat Frame structure in the code. It can be removed. It serves no purpose wince you already have data flow using the wires.
It is always best to use shift registers for reference wires (which is the output of the Create Master VIs. On a while loop it is less critical but it can be a big issue on a For loop. If regular tunnels are used on a For loop and the loop does not execute (For example, auto-indexing an empty array) the reference passed out of the For loop will be invalid. the shift register guarantees the reference is passed through the loop. While loops always execute at least once so this is not a concern there. However, if you get in the habit of always using shift registers for references, you won't have any issues with loosing the reference.