LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview: Read multiple input registers in Modbus. Where to put close Modbus?

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

Download All
0 Kudos
Message 1 of 6
(2,307 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 6
(2,269 Views)

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

0 Kudos
Message 3 of 6
(2,263 Views)

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:

Modbus_Example.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 4 of 6
(2,248 Views)

Thanks Mark, I changed the subVI accordingly and updated my main VI. Will test it as soon as possible.

 

vtiu_0-1611133552087.png

 

Just one question: On the outer loop you have shift registers and I have used tunnels. Is this wrong?

Regards

Mark

0 Kudos
Message 5 of 6
(2,233 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 6
(2,216 Views)