Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Listening the serial port

Hello,

I have a vb.net 2008 application. I am sending the following data to serial port: 01, AA, 02, 03, 09, CS. After sending 01 I wait for nearly 1 ms and then send AA, again wait for 1 ms and then send other set of data and so on. Now following is my query:
After I send the last data CS, I want to wait for 4 ms and then go into listen mode to listen and read any data that comes to serial port. How do I achieve this?
0
vj_mi
Asked:
vj_mi
1 Solution
 
ChloesDadCommented:
The serial port control has a datareceived event, so you can do one of two things

1 Have the event handler always connected, and use a timer to ignore andything received before the 4ma are up, or
2 add the handler programmatically after the 4ms are up
option 1
 
private serialport_dataReceived(sender as object, e as eventargs) handles serialport.datareceived
 
if i'm_ready_for_data then
' read data from port
endif
 
end sub
 
option 2
 
after the 4ms wait add
 
addhandler serialport.datareceived, addressof serialport_dataReceived
 
the code for the eventhandler becomes
 
private serialport_dataReceived(sender as object, e as eventargs) 
 
' read data from port
 
end sub

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now