10-27-2008 11:26 AM
Hello,
I'm writing an app that uses a state machine. It is a data acquisition system that uses custom USB hardware. Under normal circumstances, it runs just fine. Data are read from the USB device and processed in time to prevent backing up and overflowing the USB device buffer. The problem is, when I start streaming data to the hard drive. It backs up and overflows the buffer. This is not constant, but only at the start. After the start, the buffer is immediately read back down to minimum, so I know the code that streams to the hard drive is not executing too slow. Also, I already have the file open, so it isn't that. With some experimentation, I've been able to determine that the problem is the time the computer takes up when I click on the 'record' button. The longer I hold the left mouse button down, the more the buffer backs up. If I link a hot key to it, it does the same thing when I press the hot key. I'm relatively inexperienced with LabVIEW, and I was wondering if there might be a trick to get around this.
Thanks.
10-27-2008 11:43 AM
Hi Rickford66,
How are you handling the events associated with the record button? Are you continuously polling the button or using an event structure?
From your description it seems like the “mechanical action” property of the record button may not be properly set. The “switch/latch when pressed” and “switch/latch when released” settings work differently. Right-click the control to set the “mechanical action” property. Can you upload a copy of your code?
10-27-2008 11:45 AM
Hi,
Thanks for the post!
How are you testing the state of the button, polling or event structure?
I guess it would help to see your code if possible.
Kind Regards,
10-27-2008 11:50 AM
At this point, the code is very complex, so I'd rather not post it. If I have to, I'll make a simple version, but I'll cross that bridge if I have to. Anyway, I am polling the buttons in state '-1', (again, it's a state machine), building an array, then searching the array for the T button. The acquisition T/F is at the end of the array, so its case executes if nothing else does. All buttons are set to latch until pressed again, so that no states are ever missed. I manually set them to false in the case that services them.
10-27-2008 11:53 AM - edited 10-27-2008 11:54 AM
Hi,
Thanks for the reply.
I would suggest looking into event structures (see examples in the example finder), as these are less processor intensive.
They handle registoring the button press for you - and then you can excute the relavent code related to the button press.
Kind Regards,
10-27-2008 12:03 PM
There is no "Latch until pressed". Perhaps you have Latched until released?
Try latched when released..
10-27-2008 12:05 PM
10-27-2008 12:07 PM
Sorry, I wasn't clear. The state is 'switch when pressed' which stays in the active state until the button is pressed again, or until the local variable is set to false, as in my case.
10-27-2008 12:17 PM
Ideally your code should be structured so that you handle all (most) the events in one event structure. A producer/consumer arcitecture will help you achieve this. The producer loop handles the user interface and the consumer can implement a state machine. LabVIEW ships a template of the producer/consumer (events) architecture. Select "File>>New..." and then expand the "From Template" node in the "New" dialog.
10-27-2008 12:26 PM
I think I'm getting the picture. I'll look into this a bit deeper to see if this will solve my problem.
Thanks.