LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change the boolean status at the start and end of a process

Hi, first time post here, a simple question.

I wanna record the data received from the Serial port to a text file, the algorithm is shown in alg.pngalg.png (some port connections are not shown, Serial.read keeps reading the terminal), and I have a boolean button(switch when pressed) to start and end recording whenever I press it.

I also have a part to send some commands through the Serial port to request some data (I2C read register values), the button in red circle in command_send.png command_send.pngis latch when released because I only wanna send the commands once when I press the button.

Now what I want is, when I press the control button to send the commands (i.e. read 100 register values), I also wanna start recording, and end recording when there's no more data coming in (all 100 values are recorded).

So it's like use a latch when released button to start a "switch when pressed", and some other signal (maybe nothing in Serial.read?) to trigger the switch again.

 

Any suggestions to implement this? or better algorithm to control the recording?

Thanks in advance

Download All
0 Kudos
Message 1 of 8
(3,359 Views)

Search for "State Machine".

Message 2 of 8
(3,343 Views)

Something like this might do what I think you want:

Example_VI_BD.png

Here a circular buffer of initially "false" values is passed to Replace Array Subset with the pointer to the index moving around (Remainder when divided by 100). I use Or Array Elements to find out if in the last 100 iterations, the button has been true. Since it latches, it is true just once, but the output is true for the following 99 iterations.


GCentral
0 Kudos
Message 3 of 8
(3,316 Views)

@RavensFan wrote:

Search for "State Machine".


What he said...

 

Also read my sig-line...

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 8
(3,303 Views)

Minor critique/question about cbutcher's suggestion (and RTSLVU's signature).  I believe that the OP wants exactly 100 reads when the "Read 100" button is pressed.  I suspect that the suggested code gives at least 100 reads (consider a second button push while the 100 reads are taking place).

 

Who said "State Machine"?  [I'm guessing GerdW or RavensFan ...].

 

Bob Schor

0 Kudos
Message 5 of 8
(3,274 Views)

If the desired response is to increase the number of samples to take by 100 each time the button is clicked (and not to measure the next 100 samples, regardless of when the previous button was clicked) then perhaps the following is a better option:

Example_VI_BD.png

Of course, effectively this is a 2 state State Machine...

 

If instead, the user wishes to prevent button clicks during an acquisition, then the button should be disabled using a property node (perhaps a Case Structure with the Latch Button as a selector).


GCentral
0 Kudos
Message 6 of 8
(3,265 Views)

@RavensFan wrote:

Search for "State Machine".


I would go one farther and look specifically at "Event Driven State Machine," or "Event Driven Producer Consumer,"

 

Here's a presentation on design patterns. It might be a bit too much for you right now, but it's good to take a look at.

0 Kudos
Message 7 of 8
(3,251 Views)

@JScherer wrote:

@RavensFan wrote:

Search for "State Machine".


I would go one farther and look specifically at "Event Driven State Machine," or "Event Driven Producer Consumer,"

 

Here's a presentation on design patterns. It might be a bit too much for you right now, but it's good to take a look at.


Honestly for new programmers I never suggest anything Event Driven.

 

As (IMHO) the Event Structure breaks the data flow paradigm that new programmers really need to grasp.

 

Event Driven programs look like little chunks of unrelated code that get executed whenever an event occurs, instead of a cohesive program you can follow from beginning to end.

========================
=== Engineer Ambiguously ===
========================
Message 8 of 8
(3,225 Views)