LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of event structures.

Hello,

We have developed a reaction time program for our laboratory but are experiencing ongoing problems with a bug in the program. The program requires you to hit the run arrow then it will prompt the user to select a position data file. The position data file tells the program where the arrow will stop on the dial if it is not stopped by the subject. Once this has been done the user must hit �Start Program� and then the experiment begins. When the status reads �Waiting for User to Press the Key� the subject can depress any key and the dial begins to spin around with the object of the exercise being for the subject to stop the dial as close to the �8� value as possible by taking their finger off the key they have depressed (the key press and key lift are controlled using event structures). When the key is lifted a dialog box appears that gives the subject feedback about the trial (this is generated in frame four of the sequence structure). The program works fine if all the subject does is depress and release the key and then respond to the dialog box using a mouse press.

There are two conditions in which the program falls over. Firstly, if the subject depresses and releases the button several times after the �Waiting for User to Press the Key� prompt then the program seemingly holds the erroneous responses in memory. The next trial/s (depending on how many times the key has been depressed and released) the subject is not able to respond, the program skips over the �Waiting for User to Press the Key� prompt, and the dial just moves by itself. Secondly, if the subject responds to the dialog box by hitting �Enter� instead of using a mouse press then the program �hangs� and needs to be hard stopped and then restarted. I suspect this has something to do with our use of event structures (especially because they are used inside a sequence structure) but am unsure of how to solve the problem. Is there any way to get LabVIEW to just search for one key press and release then not register subsequent key presses and/or releases until the appropriate time?

I have included a copy of the program, a text file containing position data, and a �test� file to write the output parameters to. Please note that the program calls a counter in order to get more precise timing. Any help much appreciated.

Regards,
Shane Warbrooke.
0 Kudos
Message 1 of 8
(3,795 Views)
I only looked for a second but your event structure doesn't seem to have a time out. The default is -1 which implies never timeout(vi appears frozen).

Also using two different event structures is dangerous. Both events should be in the same structure. The structure should also be in the while loop and not the sequence structure.

For not detecting all other key presses, maybe just use a local boolean to tell your program to not execute the code in question when key presses you don't want are entered.
0 Kudos
Message 2 of 8
(3,795 Views)
Hi Shane,

What you are experiencing is one of the standard behaviors of how Event Structures work. When you run your VI which includes the Event Structure, all the events specified inside this structure will be registered from the moment you run the VI. This means that all events occurring before you actually get to the loop with the Event Structure will be stored in memory � since they were registered from the beginning of the VI.

To make sure that you are not registering the events before a certain time, you should use Dynamic Events. This will make you able to choose when in your program you want to register and when you want to un-register the events. See 0020E74861&p_node=DZ52054&p_submitted=Y&p_rank=5>this Dynamic Event Registration example.

I hope this will enlighten you.

Best regards,
Philip C.
Applications Engineer
National Instruments
www.ni.com/ask
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
Message 3 of 8
(3,795 Views)
Hi Philip,

I can see the potential of the Dynamic Event Registration function but have had no success in trying to wire up a key down or key up event to the dynamic event register. I am unsure how to do this as the Dynamic Event Registration example that you sent me seemed to require a specific boolean to be allocated to the "Register For Events" within the Event Structure. This is not possible in the program that I am currently trying to debug as the key down or key up events are registered on whichever button is depressed at the time (this is often not one of the buttons that is an option with Key Navigation so I am not able to assign a key/s to a specific boolean). Is it at all possible to use Dynamic Events to register a key down or key up event on a
ny key on the keyboard?

Thank you for your time.

Regards,
Shane W.
0 Kudos
Message 4 of 8
(3,795 Views)
Hi Shane,

You can register for ANY key action by using the �Keyboard Event� in the Event Structure (see the attached KeyEvent.gif). The events with question marks can even discard the action of the key that is pressed depending on your code.

Would this make your application work?


Best regards,
Philip C.
Applications Engineer
National Instruments
www.ni.com/ask
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 5 of 8
(3,796 Views)
This interesting behaviour is illustrated in the attached vi, where the blinking of a led is stored in memory, before running the while loop containing the event structure.
Have fun !

CC
Chilly Charly    (aka CC)
0 Kudos
Message 6 of 8
(3,795 Views)
Howdy...

Im not too sure on what loop or structure to use in my program. Currently Im having two separate while loops but I actually want my program to first able to open a communication with another computer which in this case serial communication using LAN. I already have the program inserted.

My objective is to first link to another computer.
Secondly, when linked I want to capture the data that is coming in and display it into my program.

Any help will be appreciated!
Thank you in advance!

(Attached is my program...)
0 Kudos
Message 7 of 8
(3,725 Views)
Hi.
Your program seems basically to do exactly what you want - connect to another computer and recieve data from another program running on that computer. it needs some refining and if you want to send data, you need to use the Write TCP VI as well as the Read TCP VI.
If you want your communication loop to be connected to your other loop, there are various ways, the simplest being local variables. There are examples in the example finder (Click Help>>Find Examples) that do this and there are tutorials on this site which explain it (search for "TCP + tutorial"). These examples and tutorials can be modified to suit your needs. If you still have a problem after using them, I suggest you open a new thread and ask the question there with more details. There will be a higher chance of someone answering your question.
And by the way, your communication over the LAN isn't serial, but ethernet (TCP/IP).

___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(3,714 Views)