Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview real time data trasfer from and to target

Hello everybody, I'm fairly new to LabVIEW Real Time.

I’m using myRIO platform with eight digital output and four analog input. I need to write a program which read a line of an Excel file (which is on my host computer) and transfer the data to the target (myRIO). These data are used to open one of the eight digital output ports at a time.

At the same time I need to acquire data from the four analog input in real-time (1 KHz), send them to host computer and save them in another Excel file.

Once the acquisition has finished the program have to read the next line of the first Excel file and start the loop again.

 

What is the best way to make the host wait until the acquisition on the target has finished before reading the next line of the file?

I’ve tried to use Case Structures and Stop Network Variables but I haven’t had good results.

 

Is it correct to use four different Network Shared Variables to transfer data from target to PC host with a frequency of 1 KHz?

 

Could I include four Analog Input and eight Digital Output in the same Timed Loop?

 

Thank you very much in advance,

 

Lorenzo

0 Kudos
Message 1 of 6
(5,310 Views)

Hi lorenzo 26,

 

well, the timed loop under real time is deterministic, so you should know exactly when to read a line from the Excel file without sending a flag to the host PC, is that correct? If you have to though, the best way is probably taking one of the output properties of the timed loop (something like Loop Done or something like that), put it in a shared variable and send it over to the host.

 

About all the things you want to do in the Timed Loop, it really depends so the best way it probably to add one input/output at a time and see if the loop starts to run late.

 

Unless you are dealing with punctual data, I suggest you use Network Streams instead of Shared Variables to transfer data from the target to the host. The connection is buffered and there is no data loss. It's more stabe and you can transfer arrays, so that you can use just one for all of your data.

 

Hope it's clear!

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

Hi Lorenzo,

Are you using myRIO Toolkit or are you programming also FPGA?

Anyway, in order to be sure that the acquisition is finished before the new reading from the excel file is executed, you can implement a state machine on your host vi. In LabVIEW you can establish which are the states of your program and pass from one to another with this program structure called "state machine".

I'll send you some documentation on this topic, with this solution you can assure to read from the excel file only when the "state: acquisition" (for example) has done what it has to do.

You should also use a flat sequence structure to give a sequencing to your code, but state machine is more efficient.

Here a usefull link:

https://www.ni.com/en/support/documentation/supplemental/16/simple-state-machine-template-documentat...

Bye

0 Kudos
Message 3 of 6
(5,284 Views)

Thank you very much.

To make the program easier I've moved the first Excell file to myRIO memory so the file is read directly from the target.

I've insered a For Loop which reads one line of the file at a time. 

I have two more questions:

How could I stop a Timed Loop after 3000 milliseconds?

How could I transfer an array with Network Stream?

 

 

0 Kudos
Message 4 of 6
(5,275 Views)

Hi Lorenzo,

in order to stop the Timed Loop I suggest you to use the express "Elapsed Time" in the Timing palette, the output of this block is a boolean value that you can put in input to an "or" function (boolean palette) together with the stop variable control; in this way your loop will stop if the time that you indicated is elapsed or if you push the stop button.

Instead of using an express (that could slow the program), you could do a control on the number of iterations of the timed loop. I think that you want 3000 samples because you acquire 1000 samples per second, so you can implement a control on "i" (number of iterations of the timed loop) using a comparison block in order to stop the loop when i=3000.

 

Regarding transferring an array with a network streams, you have to put an array (instead of a numeric) in 'data type' input to the "Create Network Stream Writer Endpoint", so that the data transferring will be an array. If you have some doubts about how using the network streams, you can read this document:

https://www.ni.com/en/shop/labview/lossless-communication-with-network-streams--components--archite....

Hope you solve the problem!

Bye

0 Kudos
Message 5 of 6
(5,267 Views)

 I have almost solved it. Thank you very much for your help!

0 Kudos
Message 6 of 6
(5,260 Views)