LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

data streaming and looping error

Hello,

I am new to labview and am working on a power distribution unit project for school. Labview receives 8 current, 1 voltage and 8 status values serialy from a 16f887 microcontroller. The values are displayed on the screen and the status of eight "outlets" are displayed. The user is able to turn on and off these "outlets" either through labview or a keypad attached to the micro. Labview sends the status of the switches and the pic turns on or off the outlets and then sends an updated status value for the switch.

We are trying to stream or data log these values over a period of time determined by the user. By clicking on a data log button the data should be streamed to a file for the desired amount of time. This file is time stamped by date, with the time in seconds. Ideally this should run for 1 – 6 hours, taking data every 5 to 8 seconds.

The problem I am having is that when the data logging starts, it exits the main loop and stops sending and receiving serially. I can also not switch the outlets on and off.

Can labview multi task these two events simultaneously? I have attached my code, but it does not run without values coming in serially. I was hoping some of you pros could have a look at it and find the issues.

Thanks for the help!!

Rennie

0 Kudos
Message 1 of 8
(3,585 Views)
Rennie,

First, typical practice among experienced LV users is to keep the size of the diagram to one screen. Use of subVIs is one way to keep the diagram from outgrowing the screen.

Second, use of property nodes (the Current data in the File loop) to pass data is the least effective way. Wires are preferred whenever possible and could be used in your program. Local variables can be used but may result in race conditions. Depending on the application queues and action engines may be appropriate.

The usual way to log to a file without stopping the control loop is use parallel loops. The data is passed via a queue or and Action Engine.

Lynn
0 Kudos
Message 2 of 8
(3,579 Views)
Check this,  it maybe useful to optimize your code.
 
0 Kudos
Message 3 of 8
(3,569 Views)
Thanks for the feedback johnsold.

I was planning on making some subVI's when I was finished debugging. It is still in a very development stage.

I have been experimenting with dual loops, but was unable to get the data inot the second loop. How do you pass data  via a queue or and Action Engine?

Rennie
0 Kudos
Message 4 of 8
(3,567 Views)
Here is a quick mock up of a q'd producer consumer.
Should give you some ideas.
Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 5 of 8
(3,548 Views)
Congratulations, part of your code made an honorary mention in our Rube Goldberg Code thread: 😄
 
 
You really should sit down and maybe start with a tutorial or similar. Your code is overly complicated and contains many problems.
  1. The way you convert the 8 booleans to a byte string is extremely convoluted. (see link above).
  2. Why do you configure the serial visa session newly with every iteration and kill the visa session right afterwards in the same iteration? Typically, you would configure once ouside the loop, repeatedly write or read inside the loop, and close the session after the loop has finished.
  3. Way too many explicit operation of the same thing. Use arrays! For example you could use an array of current indicators.
  4. Converting the first two hex characters to 8 booleans can be basically done in one step with code the size of a postage stamp (analogous to the link above) instead of code the size larger than a postcard. See if you can figure it out. (your entire program could fit in the space currently taken by these constructs ;))
  5. Learn about dataflow. When you start logging, you trap the code in an inner loop. The iteration of the outer loop cannot finish until the inner loop is done.
  6. Once you have the current as an array, just feed it inside the case structure to be logged. (no value property nodes needed!)
  7. Delete the inner loop, it serves no purpose. Open and close the file outside the main loop, and just write (or not) inside the loop, depending on the "logging" switch.
  8. ...
0 Kudos
Message 6 of 8
(3,537 Views)
Thank you for your input Christian. I have only taught myself labview in the past few weeks and appreciate all of your help.

I am still having issues with the datalogging. I tried to open and close the file outside of the main loop, yet ran into errors. Here is a print screen of what I did.....

I also used the inner loop with a delay to write so many times per second (sampling time). If I deleate the inner loop how do I still make this happen?...it is the second picture in the printscreen

Can't I just put my case structure and loop out side of the main loop and will they run together?

I am sure these are easy mistakes to fix and would appreciate a little more guidance.

Thanks for the help!

Rennie
0 Kudos
Message 7 of 8
(3,487 Views)

Please attach your actual VI, it is almost impossible to give detailed advice from a picture alone.

You have broken wires because you create loops that violate the requirements for dataflow. You cannot wire to something from inside the loop to ouside the loop and then back to the inside of the loop or your code breaks because of deadlocks. Dataflow dictates that (1) a structure cannot start executing until all inputs have data and (2) A structure only outputs data once it is finished. In your case, the "open/create/replace file" cannot execute because it relies on data from inside the loop, but the loop cannot start because it relies on outputs from "open/create/replace file".

You need to open the file outside the left side of the loop and no inputs to it can come from inside the loop if you do that. If you design your code as a state machine, you can open the file inside a special state (inside the loop) an then place the file reference inside a shift register for further use in other states.

Also NEVER use "use default if unwired" tunnels for file references  as you apparently do.

I don't understand what you are trying to do in the second picture. Makes little sense.

0 Kudos
Message 8 of 8
(3,471 Views)