Input from an external device

B

Budgie

I need to read a signal from an external device into a textbox. Once the
textbox is populated a message should popup on the screen to verify that the
signal was received. The signals coming are as follows :

\901 - first device
\902 - second device
..
..
..
\910 - tenth device.

A textbox is populated directly from the external device without any
keyboard or mouse interaction. Once the code is accepted a message should
popup saying something like "Device 1 is active" for signal \901. Basically I
only need to act on the last two characters ie. 01, 02, 03 .... 10.

My question is: How do I get the message displayed without any keyboard or
mouse click? In other words once the keystroke of 4 characters is received
the message should be displayed automatically.

Maybe this issue was addressed somewhere else, I just don't know how and
what exactly to search for.


Thanking you in advance.

BvR
 
B

Budgie

I have done as you said, however the event only fires once the enter key is
pressed after the signal was received by the textbox. The application is used
for a quiz and needs to indicate which buzzer was pressed first. Obviously it
needs to automatically fire once the buzzer button is pressed.
 
S

Stuart McCall

Budgie said:
I have done as you said, however the event only fires once the enter key is
pressed after the signal was received by the textbox. The application is
used
for a quiz and needs to indicate which buzzer was pressed first. Obviously
it
needs to automatically fire once the buzzer button is pressed.
<snip>

Ok, modify the OnTimer procedure as follows:

Dim NewCode As String

Me.Textbox.SetFocus
If (Me.Textbox.Text & "") <> "" Then 'If text is present
NewCode = Right(Me.Textbox.Text, 2) 'Grab the last 2 chars
Me.TimerInterval = 0 'Switch off timer
MsgBox "Device " & Cint(NewCode) & " is active."
Me.Textbox = Null 'Reset for next input
Me.TimerInterval = 100 'Switch timer back on
End If

Because we've given Me.Textbox the focus, we can now use its .Text property
(rather than its .Value property which is only updated once Me.Textbox loses
focus - hence the Enter key necessity)

Also, now you've explained it's a Quiz buzzer, I think you'll need a shorter
timer interval, say 100ms. And you can lose the LastCode variable. Now I
understand better what you're doing, I realise you don't need it.
 
B

Budgie

Bingo!!!!! Thank you very much!!!!!

There is still however another little snag. When the buzzer is pressed bout
at the same time as the timer firing, the testbox sometimes only collects 2
characters, resulting in the buzzer having to be pressed again. This will
again result in the participant complaining about the buzzer not working
because it will need to be pressed more than onve. Will it be possible to
have the firing only once all 4 characters is received by the textbox?

Another question, if I have to collect all signals from all the buzzers in
sequence to determine the order in which the buzzers were pressed. In other
words once a question is asked all buzzers will be pressed and the order then
needs to indicate first to n-th. If no 1 answers wrong, no 2 gets an
opportunity to answer. If I can collect say at least the first three buzzers,
I would be fine.

Thanking you again.
 
S

Stuart McCall

Budgie said:
Bingo!!!!! Thank you very much!!!!!

There is still however another little snag.

Isn't there always? said:
When the buzzer is pressed bout
at the same time as the timer firing, the testbox sometimes only collects
2
characters, resulting in the buzzer having to be pressed again. This will
again result in the participant complaining about the buzzer not working
because it will need to be pressed more than onve. Will it be possible to
have the firing only once all 4 characters is received by the textbox?

I can't think of a way of doing that. The only tweaking you can do is to
play with the timer interval (you probably need to lower it some more,
although increasing it may have a beneficial effect also - you're on your
own here because only you have the hardware)
Another question, if I have to collect all signals from all the buzzers in
sequence to determine the order in which the buzzers were pressed. In
other
words once a question is asked all buzzers will be pressed and the order
then
needs to indicate first to n-th. If no 1 answers wrong, no 2 gets an
opportunity to answer. If I can collect say at least the first three
buzzers,
I would be fine.

Well presumably the electronics of your buzzer device only let one unit
transmit to the PC at once, so lowering the timer interval will probably let
you collect them all within a time period of say 2 seconds. During this time
I think you need to:

1. Collect an entry from the textbox & store it somewhere
2. Clear the textbox ready for the next entry
3. Go to 1 until all entries are "in"
4. Switch off the timer (Me.TimerInterval = 0) via a button
5. Do whatever you normally do inbetween questions
6. Clear your entry storage
6. Switch the timer back on via a button when asking next question

Remember that any polling of an external device using a timer is going to be
a bit hit and miss, so code and timer interval will probably require
adjustment using persistence & patience to get it just right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top