LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with reading data with visa

Solved!
Go to solution

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]

0 Kudos
Message 1 of 28
(546 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 28
(522 Views)

What you have here is a giant race condition...

 

race.PNG

 

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

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 28
(453 Views)

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.

0 Kudos
Message 4 of 28
(422 Views)

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.

0 Kudos
Message 5 of 28
(420 Views)

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:

  • Show the display style indicator on ALL your string constants, especially when you don't use the default display style.
  • As you use a TermChar (as configured at the VISAInit function - read its help!) you should read more than just 2-4 bytes with VISARead. This is explained in this video
  • Create an array of your command string. Place one VISAWrite and VISARead inside a FOR loop. Feed that loop with your command array using an autoindexing input tunnel and output the received strings in an array (also by using an autoindexing tunnel). THIS will enforce DATAFLOW and EXECUTION ORDER…
  • What's the point in closing the SAME VISA reference four (4) times even though you opened it just once???
  • What's the baud rate of your serial communication? You can easily determine the time you need for sending commands and reading responses by multiplying the number of bytes with 10 and dividing by the baud rate. This will limit the loop iteration rate to higher freqencies (or lower "wait for multiple" input values)…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 28
(413 Views)

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

0 Kudos
Message 7 of 28
(326 Views)

here is the vi i am working on

0 Kudos
Message 8 of 28
(325 Views)

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:

  1. writing the command to the device
  2. immediately checking the number of received bytes in the input buffer (should be 0 after a few microseconds of executing the write node)
  3. reading nothing

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.

 

 

Greets, Dave
0 Kudos
Message 9 of 28
(295 Views)

I would do something like this. It gives you a way to make your code more flexible.

 

aeastet_0-1752588341056.png

 

Tim
GHSP
0 Kudos
Message 10 of 28
(275 Views)