06-27-2025 06:26 PM
Hi All,
I am currently working on building a simple interface for a Modbus device we will be monitoring and sending commands to. Since we are uploading device configuration from a csv, I am using clusters to hold device's register info: register name, address, data type, etc... The idea is to iterate through the array of register clusters, from the register name identify the register address to read from, read register address, and store the value in the corresponding register cluster for reference.
How can I optimize the for loops. What are best practices for this? I have a similar implementation on python, and its execution if much faster.
06-27-2025 06:56 PM
06-27-2025 08:43 PM
As has been said, your code is extremely inefficient and convoluted.
I have no idea how you are measuring execution time, but done right this should all complete in an instant.
Attach your VI and describe the code requirements in detail.
06-30-2025 06:46 AM - edited 06-30-2025 06:49 AM
A Boolean going into a while loop and then used as a stop criterium is fishy (too).
It does something, of course: the while loop loops either once or forever (that's really slow 🙄).
Since we can't see the rest of the code, my guess is it's a bug. Or is this for testing?
06-30-2025 01:02 PM
The goal is to interface with our load inverter using Modbus. The overall project is a system control application for our dyno setup. We've created a python application following MVC framework, and we'd like to follow a similar framework on LabVIEW.
For the AC890 interface, we want to load a configuration file containing register metadata (name, address, access type, value, etc..). In our python implementation, this information is stored as a list of data objects assigned to the variable self.data. In LabVIEW, I am using clusters to represent this data structure, AC890 Regsisters.
When reading registers, certain registers require unique interpretation. In python, we iterate through the list of data objects (self.data), and based on the register name, we read the corresponding register address and update self.data[i].value with the interpreted value. We then place the updated self.data list into the device's read queue. Which the controller class then gets and sends to the Viewer class.
In LabVIEW, I am currently using a for loop to iterate through the AC890 Registers cluster array and directly displaying each register's value.
For writing to registers, we have a write queue that holds the register name and the value the user wants to command. Similarly, we iterate through self.data to find the data object with the target register name and write the desired value to its corresponding address.
I have attached the relevant python functions as comments in the VI as reference.
Thank you for your feedback !
06-30-2025 01:21 PM
Hi Purple15,
Thank you for posting your code. Can you save it for LV version 2019 ?
Many of the Forum members are still in the old versions.
06-30-2025 01:53 PM
This should be LV version 2019
06-30-2025 05:29 PM
I assume we are only interested in this part of the code, so all we needs is a tiny example VI and the corresponding file. Can we assume that is "AC890 Registers.csv"?
On a side note, most of your code is completely dysfunctional and violates all rules of dataflow. There is no toplevel loop and none of your inner while loops can ever be stopped because the "stop 2" (I am sure you can come up with a better name!) terminal is outside the loop and the value inside the loops can never change.
06-30-2025 05:52 PM
06-30-2025 06:11 PM
You can try to get contiguous blocks of data from your device. Some devices will let you, some will not.
(You may need to tweak with the array sizes, I'm not 100% sure I got them resized correctly)