11-17-2025 07:36 AM
Hi EdHarries,
I am not sure how to help further. It sounds like you need to spend sometime understanding how LabVIEW programming works. NI learning center has some good resources for the same https://learn.ni.com/.
LabVIEW cannot go out of bound of what your program it to do so it will not try to control anything that you do not want it to. Auto iterating (assuming you mean Auto Indexing), just (to simplify) indexes array element, one iteration at a time. i= 0 is index 0, i = 1 is index 1 and i=n is nth element in the array. As it indexes that element, in your case, device session detail, data for register access and slave ID. Once the data is indexed, you do something with that data in that specific iteration. In your case, you read/write from/to the device that has its session indexed. Use probes or highlight execution to better understand this.
If you want to understand what several for loops are doing, use probes or highlight execution to better understand the VI.
Adjust wait timer value to meet your timing requirements. Rest, the VI should behave as required. If you are not getting the data in the format you expect it to, make modifications. Use probes to see data output from each for loop.
If any of the state is not getting triggered, check for spelling mistakes or white space.
Can you show your attempt on producer consumer architecture? Your attached VI is what I shared with you initially.
If the VI runs for ever, check the stopping conditions. Use highlight execution to see what process it not yet finished as it should have or where your VI is stuck.
If you do not need the other (write) case structure in the in the same for loop feel free to move it to the next case.
If you do not understand the state machine yet, use probes and highlight execution function.
String array holds the next state value. Your code idles when "run" button is clicked. To actually start the communication, you need to click on the "Start" button on the front panel. Start button event in the timeout case send out the first state's value i.e., "connect". Connect case connects to all the devices that you have provided information about in the array on the front panel. Use probe and highlight execution to visualize it.
Read the labels in that cluster, it is what you have in your VI, Starting address of the device (or address of interest) and quantity. Read or Write boolean is an addition to utilize them later in the code, if needed. Like for example, your code writes data to one device after all the read is done. Write button is set to "True" for that device, that way, the code knows that at the 6000 (last) iteration, it needs to write to the specific device after reading from it and skip the write for the once that does not have it selected. This was your requirement as stated in the flat sequence VI.
The VI that I have attached (which is the same that I shared last time with the changes that I shared screenshots for) does everything thing you need. It is a literal solution (+ some additions required on your end like write to a file function). This is the most help I can provide and I believe one can provide.
Use probes and highlight execution to better understand the VI.
Good luck!
11-17-2025 01:18 PM - edited 11-17-2025 01:29 PM
Thanks Xonmyth for your help, just one thing did you say you had modified the latest example because I cannot see any changes compared to the previous one?
Ed
Below is my correct file for the modification of your producer consumer example.
11-17-2025 01:34 PM - edited 11-17-2025 01:37 PM
Hi Ed,
Previous VI I shared did not have this:
VI in message 25 has a differently setup "Sequence7" case. Image above is from message 28 based on what you mentioned in the message 27.
Edit:
Read this for producer consumer architecture.You can skip it for now though as it will add more complexity to what you are trying to achieve.
https://www.ni.com/en/support/documentation/supplemental/21/producer-consumer-architecture-in-labvie...
11-18-2025 02:38 AM - edited 11-18-2025 02:44 AM
Hi Ed,
If Xonmyth's code is a bit too complex, one option is to return to your original code and just make the following two changes that appear in the various VIs I've seen posted, which are the only aspects I see that would noticeably increase its performance over what you had originally:
One final thing you could do to significantly increase performance is connect your Modbus devices to separate COM ports then write your code so that it communicates with all of them in parallel (i.e., at the same time) rather than being forced to communicate with them one after the other.
11-19-2025 05:30 AM
Those are great points, I didnt realise parallel reads could be done on different com ports! Could be very useful.
11-19-2025 08:06 AM - edited 11-19-2025 08:15 AM
Hi Ed,
Banksey's reply made me rethink. I would not want to leave you hanging with a code which cannot understand while you started with a code that partially worked for you.
Thank you Banksey!
So here is it, back in the flat sequence format (LabVIEW is kind, it allowed direct conversion of all the states to stacked sequences and stacked sequences to flat). Still using arrays as my last code. But I hope this one would be easy to follow. If you still struggle let me know.
P.S. Move away from flat sequences as soon as possible, they are not needed. Enforce your sequencing through dependencies.
Edit: First attachment had a mistake.
11-20-2025 06:28 PM
Hi Xonmyth,
Thats very good of you to make me another VI example, I was pursuing your first solution and got it working in all respects except that I needed to change the data process for one slave. I tried to do that with a case structure with the slave id connected to the case selector. I dont know why the loop tunnels wouldnt let me do that and the write spreadsheet string wouldnt accept the data format. Very annoying, I have posted it below "Producer consumer edit4fails"
But I am so close now with the other vi that I have posted called "Hybrid". I can get the data as required, two holding registers from the first slave, then one from the other three, then the milisecond timer after that the other timing data.
The problem is I cannot control how many rows it does before going back to the other timing data. It does four rows even thought the for loop is set to something else. Anyone has an Idea how to fix that I would be very grateful. I need to be able to set it to 3000 or so.
An example of the problem data.
53337,16531,4.621259,4.621995,4.623722,0.18203
59661,16531,4.623695,4.628009,4.682175,0.28140
60358,16531,4.616300,4.629935,4.629935,0.38135
24154,16532,4.636813,4.636813,4.695338,0.48138
00:06:56.393 21/11/2025,327.69705,00:06:56.393 21/11/2025,0.00000
61956,16534,4.709394,4.707186,4.708588,0.02530
35505,16534,4.701523,4.699564,4.699564,0.12427
32481,16534,4.704193,4.702938,4.703090,0.22513
64953,16536,4.790385,4.788021,4.788605,0.32520
00:06:56.975 21/11/2025,328.27967,00:06:56.975 21/11/2025,0.00000
853,16537,4.781062,4.781062,4.782614,0.02440
11-21-2025 07:39 AM
Hi Ed,
@EdHarris wrote:
I dont know why the loop tunnels wouldnt let me do that and the write spreadsheet string wouldnt accept the data format. Very annoying, I have posted it below "Producer consumer edit4fails"
1) You were trying to connect an element to an array, that is why you had broken array. If you will have to use a specific array node/ function to be able to connect an element wire to an array wire. In the attached example, I have used build array function to overcome the broken wire.
To troubleshoot in future, press CTRL+H to enable help windows, unless already open, then hover over the broken wire to see the problem.
@EdHarris wrote:
The problem is I cannot control how many rows it does before going back to the other timing data. It does four rows even thought the for loop is set to something else. Anyone has an Idea how to fix that I would be very grateful. I need to be able to set it to 3000 or so.
2) I did not fully understand your requirement here. Can you please add more details? Rows of what?
Check out the attached VI.
11-21-2025 08:25 AM
I ran into a similar issue with a LabVIEW VI that streams data from a COM port when the program is stopped while running, the COM‑port address box changes to something like “ASRL5::INSTR”, which makes further streaming fail. In short: what helped me was to make sure the serial port is properly closed and re‑initialized every time the VI stops (so it doesn’t get stuck in a weird state). Are you seeing the same “ASRLx::INSTR” tag after stopping your streaming loop?
11-21-2025 10:32 AM
Hi shanewrn,
I used to but have sorted that problem now, in fact I had to get my vi into that state for it to run fast enough which was wierd.