07-08-2025
07:46 AM
- last edited on
07-08-2025
10:00 AM
by
markwni
Hi, I'm new to labview and I'm working on a project: I need to read data such as power, voltage, current and frequency from a DSC-electronics controller. This data needs to be captured every 0.5 seconds via rs232 to USB. When the power is greater than 0W, all data would be saved to the SQL server, when it drops to 0W, it would stop saving.
I used VISA functions in the program. You send the controller power data in the form (?MPOW), voltage (?MVOL), current (?MCUR), frequency (?MFRE) and the controller responds with the actual value (e.g. 1500.00).
Now I have some problems with loops and case structures and reading data constantly.
The procedure should look like this: First, the controller needs to be sent a request for POWER (e.g. ?MPOW) and if it is greater than 0 W, it would be necessary to send the other values (voltage, current, frequency) in order, every 0.5 s, and save the data to sql. But you only need to send 1 command to the controller, for example for power, then wait for it to respond and only then for example voltage and wait for the response again and so on. You cannot send for all values at once. Can someone give me some advice or fix the VI file. But I am using labview version 2022
[moderation note: Edited to remove extra html tags]
Solved! Go to Solution.
07-08-2025 08:14 AM
1. Start by making a driver for this device. Have a VI for each query. This will help a lot in keeping things straight.
2. Your queries cannot be in parallel with each other. The order in which you reach from where will be completely random. For instance, you could easily be reading the voltage back where you expect to be reading the power. This is a common race condition. Serialize your instrument communications. This will be a lot easier if you follow #1.
3. I would separate this code into 2 loops: Instrument Communications and Database. Use a Queue to pass the instrument data to the database loop and it can react as needed.
07-08-2025 03:03 PM
What you have here is a giant race condition...
How do you know what order the commands will be sent and data received?
I suggest you start by watching this video: Proper way to communicate over serial
07-09-2025 02:11 AM
What should the sequence of loops be then and which ones would i use?
Does anyone have a similar program or video for beginers?
I am really new to this and this is my first time encoutering it so i'm out of ideas.
Than you for all replies.
07-09-2025 02:20 AM
yes at first i thought that the order in which i send it to the controller doesn't matter, but then i realized that the value you send to it first is the one that responds. And only 1 value can respond at that moment when you send it.
i have problem because my loops are fighting each other and the program is not running consistently.
I need hints how the correct sequence should be and where to use it for example reading data, then writing to sql and so on. And also for which things i woiuld make VI's and seperate them.
Thank you very much.
07-09-2025 02:26 AM - edited 07-09-2025 02:29 AM
Hi tominsek,
@tominsek wrote:
What should the sequence of loops be then and which ones would i use?
Nobody mentioned "sequences"…
The term DATAFLOW is explained in the LabVIEW help, and it is fundamental to LabVIEW!
Suggestions:
07-15-2025 06:15 AM
Does anyone have time to repair me VI. I dont know how to do it, im am doing first time with labview...
It would be enough if someone could correct me for just sending commands and reading values from visa like you all guys say with for loop.
for saving in sql i will do it by myself.
I would be very happy if someone would be willing to help me and fix the program.
thank you
07-15-2025 06:15 AM
here is the vi i am working on
07-15-2025 08:12 AM
Hello tominsek,
so you followed GerdWs advices. Step in the right direction...
If you read the principle of Dataflow you will see that the code inside the for-loop is executed independently in parallel if it's not connected with wires. So the wait- node is executed in parallel to:
So 1, 2, 3 should be executed very fast, but nevertheless the for loop execution will finish after 100 ms, because of your wait node. And if you think it over you will understand, that the received answer of command 1 (1st loop iteration) will be in the VISA- receive buffer on loop-execution 2.
Please have a look at the Youtube- video mentioned above, there is explained how to configure the termination character at VISA Init and what it means to wire a timeout value to the VISA read- node. This will push you in the right direction.
07-15-2025 09:06 AM
I would do something like this. It gives you a way to make your code more flexible.