Serial Port Question

J

John Wright

I am reading data from a serial port using the DataReceived event from the
COM control. I need to check which text box has the focus on the form so I
can call the right function. As you can see in my code below I want to
check for the focus. The problem I have is I get a cross thread error when
trying to do this. Is there any way to modify this code so I can check
which control has focus so I can call the right function? Since it is
possible on the form to have move than one item receive data from COM 1 (a
digital scale), I need to know which weight they are sending. Any help is
much appreciated.

John Wright

Code:
Private Sub SerialTare_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialTare.DataReceived

'check which textbox has the focus and then call the right method

If txtTareWeight.Focus = True Then

'check the tare weight field. If there is something there than add the data
to the run weight

txtTareWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))

ElseIf txtEvalWeight.Focus = True Then

txtEvalWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))

End If

End Sub
 

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

Similar Threads

Check focus of text box 1
Serial Port Help 8
Help with a delegate 2
Dual Serial Ports 3
Serial Port / RS232 5
Reading from a Serial Port Part II 6
Q: Vb.net serial port help 1
Serial Ports 3

Top