LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from serialport while Wait for events in event structure ?

How can i read data from the serial port and in the same time make an event structure to wait for som button events!!
hzz
any suggestions are acceptable
Thanks!!
HFZ
HFZ
0 Kudos
Message 1 of 20
(5,527 Views)
I am not sure you want an event structure.  Event structures cause the program to wait for user interaction.  You want to program to continue reading the serial port.  I suggest condsidering some other method of controlling the program.
0 Kudos
Message 2 of 20
(5,511 Views)
You could have two parallel loops. One handles your event structure for user interaction, and the other handles your serial port reading.

-Saverio
0 Kudos
Message 3 of 20
(5,504 Views)
Hi HFZ,
 
Before offering any advice, I'd like to learn  more about what you want to achieve with the button even, as it may dictate the approach.
You may need a While Loop which would contain the serial port read, and may very well contain some sort of structure (possibly a Case) which is triggered by the button. (Unless it is a stop button, the you can wire that to the While Loop control...  😉  )
 
Can you define or describe what you mean by "button events"?  What does the button(s) do?
 
JLV
 
Message 4 of 20
(5,499 Views)
I'll explain the program by a easy way !
i'll start the program by sending some commands to a Flowmeter by serial port. not reading the port yet.!
then i want an event structure to wait for some button actions, Data, Flow, Samplerate. When pressed their functions is to send other commands with the data change.
But the event structure may not handle the button actions, if a start/stop-switch is not switched to start.
Now if switched to start, the program reads the last data from the buttons (last time they where changed), sends the data to the Flowmeter by the serial port, and starts the read data from flowmeter, and in the same time i want the event structure to wait for some button actions (example changing the samplerate or flow for the Flowmeter).
Here i'm thinking , to stop the read from serial port, handle the events, send the new data and then start the read data again. But i'm not coming to a simple solution, i need some help here!!
 
Appreciate any help,
Thanks !!!
HFZ
Engineer  
 
 
HFZ
0 Kudos
Message 5 of 20
(5,490 Views)
here is an smaller example of my program. with stringpanel for the commands that will be sent
 
HFZ
0 Kudos
Message 6 of 20
(5,485 Views)

Hi HFZ,

I unfortunately do not have LV installed at my work PC at the moment. 

But I think you might be able to get away by creating a vi that first sends commands to the flowmeter (via serial), and then enters a while loop which has a couple of case statements. 

I will look at you vi (hopefully soon, if not tonight) and propose an example. 

So imagine the following:

a) a sub-vi to open the COM port, send the commands to flow meter, then close the port (sub-vi to keep the main vi clean).

b) another sub vi which has a while loop.  A STOP button is wired to the loop control, maybe ANDed with a certain event to trigger the end of the function.  Open COM Port just outside (before) the while loop (you only want to do this once).  Within the while loop are the following case statements:

1 Upon pressing config button (or an event occurs), set sample rate and other config.  If only done once (ie static), then you can also do this outside the while loop at the same location as the COM port open.

2. Upon even (including press button), it sets a condition for another case statement to sample data, flow, etc.  And maybe data change if this is when you want it to happen.

3.  Keep the start stop button seperate from the case statements which are to do a sepcific task for every iteration of the loop.  If you want it to take a single sample or to turn sampling on/off without exiting the loop, you can use shift registers (to pass a new value to the case statement with the appropriate logic).

4.  You can also use (seperate) shift registers to store the last data values.  You can also have a case structure to handle writing data to a file.  The nice thing with the case structures is that you can converts them to sub-vi's if they start getting large.  😉  You can then use the data from the shift register to send to the flow meter (although I am not sure why).  But following the suggestion from item 3 should keep the while loop running until you press STOP or some event stops it.  That way you can read, stop reading, start reading from the flowmeter without actually stopping the loop.  Simply set a case that says "read if true", for instance.  By having a case statement take care of configuration, you can click on it and change the samplerate, etc for the flowmeter.  The config case could be inside the read data, but you'd have to be careful that it is only triggered once per instance of read (hopefully this sentence will make sence to you)  🙂

5.  By STOPping the while loop, you could close the serial port (at the right of the loop), and process the data if necessary.  I would do things such as writing to a file from within the loop.  Basically, after the while loop, you would want to close ports, files, etc and complete the vi.

 

Hopefully the above gives you an idea on how to proceed.  As I mentionned, I will have a look at your attached example as soon as I have access to LV (working with CVI at the moment).
 
Regards,
 
Ray
 
Message 7 of 20
(5,472 Views)

I don't know how to thank you,

thank you very much for the help

I'll try to develop from your answers or points, from now on during the day.

regards

HFZ

 

HFZ
0 Kudos
Message 8 of 20
(5,463 Views)

You're welcomed.

I hope it works.  And thanks for the stars 😄

You can continue to ask questions within this thread on this topic.

Ray

Message 9 of 20
(5,457 Views)

Hi Ray,

I cant figure point three out,

What i need is, that when i press the Arrow button (go) in labview, the main vi runs with its sub vi's, and the first 'ready command ' is send to FLOWMETER(FLM)

Now when i press the start/stop-switch from my main vi to 'start', i want  to send the next command wich is the last data changed by the buttons, and then the event case is running by waiting for an action to accure (a data change by data, flow and samplerate).

The problem is,: i cant control a loop (to run /stop running) from out side the vi. mean by that, i cant control a while loop by a  start/stop switch as Global variable!

thats because, before i switch the start/stop-switch, the eventcase my not react on the button changes.

Thanks  regards

HFZ      

HFZ
0 Kudos
Message 10 of 20
(5,432 Views)