LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timed data gate function

How can I implement a timed gate function within a while loop without affecting the excution rate of the while loop. In other words, I want to make an object (VI) that has a channel that is normaly open and as soon as the first data arrives, it lets that data pass through and closes the channel for a set amount of time. Say 2000ms. I want to use this vi in a while loop without affecting the loop excution time of the while loop. IMPOSSIBLE? Any neat tricks, tips, solutions? Thanks
0 Kudos
Message 1 of 7
(3,463 Views)
Can you say a little more about what the data is like? What is the data input? Analog IO? Digital IO? Serial? GPIB? Something else? What else is going to be going on in the loop? Is the 2000 msec a realistic timeout number? How accurate does the timeout need to be?

There are certainly ways of doing this, the answers to these questions will help identify the specific technique needed.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(3,458 Views)

The data source is a VISA serial read that generates 1 character string at 5 Hz, also the while loop excution rate. When a specific character is received a corresponding statement is written to a file. The 2000ms does need to be precise, I just need to avoid multiple writes to a file for a specified period, +/- 10%. Once a certain character is detected, I am not interested in what comes to the port for the next couple of seconds and I do not want it to stay in the VISA buffer either. In other words, I want the data read and discarded during the 2000ms period.

Thanks

0 Kudos
Message 3 of 7
(3,438 Views)

Hello isaoz,

This is Dominic L. from Applications Engineering at National Instruments. If you would like to flush the buffer for two seconds after reading a value you can try the following method in the attachment.

This VI basically pulls data off the port for two seconds, with the elapsed time function, and essentially discards these values.

I hope this helps.

Thanks so much and have a great day!

 

 

Best Regards,

Dominic L.
0 Kudos
Message 4 of 7
(3,415 Views)
Here's a quick example of the type of thing you can do:

Before the loop starts the COM port and the shift-register are initialized.

Inside the timeout case the code first checks to see if there is anything at the serial port. If not, it does nothing.


Note: The 5 msec timeout value can be tweaked as needed to give the response that you need - as a point of reference 5 msec is about the approximately the time required to receive almost 5 characters at 9600 bps.

If there is data waiting at the port, the code reads it and at the same time checks the difference between the current time and the timestamp saved in the shift register. If the difference is greater than 2 sec then the gate is open, so the code looks to see of the "special" character exists in the string it read from the port. If it finds it, it set the timestamp in the shift-register to the current time, otherwise it passes the existing timestamp through unmodified.

I wasn't clear what else you wanted to do with the data that was coming from the serial port, but this should get you pointed in the right direction.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 7
(3,410 Views)
Thanks, Dominic. I will check this vi in a test vi. Should be able to make it work.
0 Kudos
Message 6 of 7
(3,366 Views)
Mike,
 
Thank you for taking the time to put together this vi. It does work. I have been working on other projects the last few days. I need to make some changes to my vi to integrate your vi in. It should be easy, if I run into problems I will yell.
0 Kudos
Message 7 of 7
(3,364 Views)