473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Serial Port Question

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
Jun 27 '08 #1
1 811
Nevermind. I got it.

"John Wright" wrote:
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

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rusttree | last post by:
Many moons ago, I took a class in embedded control at school. The course focused on a micro-controller mounted on a small electric car that was programmed using simple C code. The...
2
by: salsipius | last post by:
I can't figure this out, Please Help!!!! I would appreciate any remarks or opinions or help about the code below. A you can see I am writing and reading from the serial port, that is going OK...
21
by: The Man With The Harmonica | last post by:
Hi All, What kind of commands can I use to control the serial and parallel port of my pc. I want to use my laptop instead of microcontrollers and write my software in ANSI C to be used for...
1
by: Mike | last post by:
Sorry, don't know if this is the correct board for my question. I'm a novice so I guess I have a valid excuse My question : I'm using Visual C++ and I need to collect data from a serial port. ...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
4
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
5
by: Fiesta | last post by:
Hi All, I am working on a project regarding the serial COM port. I have to design my own protocol for the serial communication. In the protocol there are some bits for Read/Write, address(bank,...
38
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
9
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.