LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding fixed and realtime data to a plot

Drew,
Whew, I never would have figured that out.  I got as far as creating the active plot property but didn't see how to get to the color.  Thanks.. again!   I am reading some of your recommended NI articles on how to create state machines in LV.  I will try that when I have all the pieces working. 
Thanks,
Phil
0 Kudos
Message 11 of 19
(1,476 Views)
OK, just one more and I will stop pestering you.  Can I read a switch from the DAQ hardware and create an event like a front panel event that can be used to activate an event loop?
Phil
0 Kudos
Message 12 of 19
(1,464 Views)

yes.  Create a control or indicator for the switch value.  Create a property node for that control or indicator and wire the value read from the daq to the "value(signaling)" property and not the "value" property.  The difference between the two is the "value(signaling)" changes the value and generates a change value event where as the "value" property only changes the value.

cheers,

Drew

0 Kudos
Message 13 of 19
(1,460 Views)
Drew,
Thanks for the help.  I am now going to create a state machine with some event loops and see how it works.  You have been a huge help.
Regards,
Phil
0 Kudos
Message 14 of 19
(1,454 Views)
I have recast the program using case and event structures and it is much easier to follow and mostly works.  I ran into a couple of problems.  First, when I read an external switch and use it to push a front panel button through a reference, the event gets through but  I get an error if the button is set up as latching.  If I set the button as a switch, the panel freezes when I push the  button.

Second, the color change part works but not the way I wanted.  What I was hoping for was to change the plot segments to different colors not the whole plot.  In other words to have the first n points of the plot one color and the next m points of the same channel be a second color to indicate the state of an external switch.  The only way I can think of doing this is to use a different plot channel for each color and switch to an xy plot so different channels could be strung together to make one final mulitcolored plot.

I also get an end of file error if I try to read the same profile file twice in a row.  If I read one file then a second and then the first again, I don't have a problem. Is this caused by the file not being closed?  I am also not sure how to release the com port.  I sometimes get framing errors the first time I run the program, or can't open the com port from another program after stopping this vi.

Finally, I am using the timeout in the Run event structure to time the data acquisition.  I noticed that if I set the sample period to 1 second, the time between samples is about 1.1 to 1.2 seconds.  I assume that the extra is the time to execute the instructions to get, plot and store the data. I could not figure out how to put a timed loop into this structure to take the data and still have the event loop that looks for the stop button.

0 Kudos
Message 15 of 19
(1,433 Views)
Oops, and here's the latest code.
0 Kudos
Message 16 of 19
(1,431 Views)

Strategic use of "NaN" with multiple plots will let you define unique colors for segments of a plot.

See here.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 17 of 19
(1,417 Views)

Hi perge,

I agree that the current code is much easier to follow and I think this type of architecture will allow greater flexibility down the road.  I was not expecting you to use queues but rather enum constants passed from each state to a shift register on the while loop, but I think they are doing the same thing.  There might be an added benefit to using queues but I have very limited experience with them.

Related to the event structure, read this http://zone.ni.com/reference/en-XX/help/371361B-01/lvhowto/caveatsrecmndtnsevnts/  I think the second and third bullet will clear up confusion about the latched booleans and panel locking.

Hopefully Ben answered your question related to the plot color.

I have had the end of file error when consecutively reading a file twice.  I was using more native file read functions and the problem was the read marker moved to the end of the file on the first read so the second read caused a end of file error.  To get around this, after every read I reset the read marker back to the beginning of the file.  It looks like you are using an express vi for the read and I don't know if this vi opens-reads-and closes the file which should not cause this problem.  However, if you have a refnum for a file try using the set file position vi located in the advanced file functions on the file I/O palette.  Set the start to zero and offset to zero to reset the file marker to the beginning.  Also, you can use the get file position vi (located in the same palette) to see if this is indeed the problem.

For the analog read and plotting, you might want to consider combining the read and plot states so you can use the timed loop structure.  The read loop can be stopped with a simple boolean wired directly to the loop exit terminal.  After the AI, the data can the still be saved in the store data state.  This should give better timing of your AI and puts the file I/O to a lower priority.  If you do this, be careful about the state of the stop boolean after the read loop finishes, ie you might have to reinitialize it after the loop so when you plot again the loop doesn't quit after the 1st iteration.

Hope this helps.  I also recommend writing small test vi's to test certain functionality of your code.  For instance, you are unsure about closing the com port.  You could write a small vi to test this apart from the main code.  It appears you are doing serial communication so you may find that you need to flush all the buffers (on the advanced serial palette) before closing the VISA session.

Regards,

Drew

 

0 Kudos
Message 18 of 19
(1,404 Views)
Thanks for the help.  I put case structures in the event structures to handle the buttons and programmatically reset the buttons.  Now the mechanical action of the buttons is to stay in their true state until the true case executes and sets them to false.  The external switches now work as well as the front panel switches.  The color plots seem to be pretty complicated especially if you want more than two colors.  I may leave that to a future feature.  I think the program is almost ready for prime time.  I will try it with all the DAQ stuff hooked up and see what happens.  It is much more stable now than at any time in the last week or two.  Again, thanks!
Regards,
Phil
0 Kudos
Message 19 of 19
(1,377 Views)