.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataReceived event not triggered in vb.Net until serial port is closed & opened again

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :.NET Framework
I am developing an application which sends multiple AT commands to a modem in VB.Net. After writing an AT command to the modem, I see the dataReceived event is not getting triggered until I close the port & open it again & write the next AT command. This behavior is consistent. As soon as I write the next AT command the response of previous AT command is read. Even adding a delay between the two write operations does not work. I also added a readData between the two writes so that data is read if it exist in buffer or stream but is not triggering datareceived event because bytestoread is non-zero, but that does not hep too. Because of insufficient read operations the data in readbuffer grows(accumulating) & after sometime the modem stops receiving the AT commands. Please suggest a solution code for data received handler & read data function   While comPort.BytesToRead > 0     Dim msgCharArray(255) As Char       If comPort.BytesToRead >= 256 Then     comPort.Read(msgCharArray, 0, 256)   Else    comPort.Read(msgCharArray, 0, comPort.BytesToRead)   End If   End While

View Complete Post

More Related Resource Links

bluetooth print via serial port PDA

Print via BlueTooth using PDA

Serial Port Communication Read and Write using C#.net

In this simple article you will learn that how you can Open and read COM port data using System.IO.Ports Namespace.
Simply just create New Project of windows application in C#.

Import ServiceProcess APIs
using System.IO.Ports

Imports System.IO.Ports

Write Parsing functions which parse port data according to attached device

Serial Port with portable data terminal

Hi,I am making application with portable data terminal which connected to serial port. User will go with portable data terminal and scan data with it than we will connect it to PC and read all the data from it. Kindly somebody help me how to do that.Thanx

How to wait for a Serial Port to respond

Hi Is it to possible to wait for a serialPort component to complete it's response?  I have a device connected to the serial port of my PC. I use the serialPort component in order to communicate with the device. I have to send 2 different strings of data to the serial port but the trick is that after sending the first string of data I have to wait for the serial port to respond. Then I have to check the response and decide whether I must send the second string or not. Also after sending the second string, I have to check also the response of the serial port. I tried to use an arbitrary amount of wait time between the sending of the two strings. Something like SerialPort.Write(...) ; Thread.Sleep(2000); SerialPort.Write(...); But the software failed when I tried it in a slower PC. So is there a way to replace the Thread.Sleep(2000) with a command that will wait until the serial port complete its response? Although, the response of the serial port is different between the two sending strings, I do know that the first response is only one byte and I know the ending byte of the second response. Also, the second response is no more than 30 bytes in length. Regards Dimitris

Windows Keyup event is routed to next form even if the current form is closed

In a form (say FormA) i have 2 events "Keyup" for the form and button_click event for the button. I call FormA from the main form with a showDialog, after this i call another form (say FormB), it also has the 2 events. In both the form the button_click event has the logic to close the form (this.close()). Now when the FormA is opened the focus is on button, if the user presses "enter" button the button_click event is called which closes the form, the logic returns to the main form and the next line i.e. to open the FormB is executed. Now here is the wierd part, in FormB because there is a KeyUp event handler; just after instantiation of the form directly this event handler is called. I guess this is being routed from FormA. Shouldnt the FormA's keyup event be closed as soon as the form is closed?

Serial Port Conflict

Hi.... I have an issue related to serial port opening. when i run my software it gives me an error "serial port does not exit or already opened". I have two questions. 1.can i check which program is using com port. And how can i close serial port that is already being used.Using Windows7  

TextBox TextChanged event not triggered


I have a textbox, under a specific circumstance, its textchanged event doesn't fired.

the keydown and previewkeydown do fired.

I assume there are other control intercept the keydown event and fool around it, probably did something over it.

but what can caused the textchanged event being cut off?

or any debugging approach for this?

i tried the AddHandler to the textchanged, in case its handled prop set to true that caused the cut off. but same, the event still don't get triggered under that special circumstance.

.NET Serial/COM Port Communication over Terminal Services



I hope I'll be able to clearly formulate my question.

Scenario: we have an application that integrates with several type of scanners (i.e. credit card, barcode, passport) using serial port interface.
It's the desktop application and can be deployed to run either in stand-alone environment or can be published over terminal services layer (citrix, TS, etc).
In the preferences of the application users are able to specify which scanner is assigned to which COM port.
For example: bar code scanner = COM1, credit card scanner = COM5.
To a user, names of the COM ports don't really make much sense and they won't know that the bar code scanner needs to be assigned to COM1 unless they go to Device Manager and look up the device name associated with the COM port under Ports (COM & LPT) section.

SerialPort class in .NET Framework has the function GetPortNames that returns the list of available COM ports: COM1, COM3, COM5, COM6, etc.
After doing a little research I found a way to get the descriptive names of each COM port device using WMI.

Here is the code for this:

  Public Shared Function GetAvailableSerialPorts(

Getting the name of the process that is using a serial port or file


Sometimes it happens that opening one file or serial port fails because it is used by another process.

Is there a way to get the name of the process that is using it ? 

Thank you

Serial Port plug/unplug detection with callback


Is there a way to register a callback or delegate that gets invoked by the system every time a new virtual COM port is connected to a USB interface ?

This function would be very useful to keep serial port enumeration up to date without polling.

Thank you

Serial Port Application Leaks Handle After Exit Forcing Reboot to Clear


The application (C# .Net 3.5) available at www.redondowa.com/porttest demonstrates a problem encountered with a Sony VAIO multimedia laptop related to use of its serial modem port.  A discussion with MS support is included in a doc with the VS solution.

If the base stream or port is not closed before nulling the port, the port cannot be recreated and the application leaves the port inaccessible.  The machine requires a reboot to clear the error.  Other machines clear the error without requiring a reboot.

<!-- /* Font Definitions */ @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:"Arial Unicode MS"; mso-font-charset:134; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"\@SimSun"; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:134; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch

Timer onTick event not being triggered... why?


Hi all,

I am trying to modify the Interval and Enabled properties via ViewState but it is not working.
Here is my code:

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
//set the default Refresh Interval to 3 seconds and enable Timer to TRUE
ViewState["TimerEnable"] = true;
ViewState["RefreshInterval"] = 3000;


    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">     

         <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server"
            Enabled  = <%# Convert.ToBoolean(ViewState["TimerEnable"].ToString()) %>
            Interval = <%# Convert.ToInt32(ViewState["RefreshInterval"].ToString()) %> >

USB Serial Port, baude rate limited by Overrun errors



I need to dump a huge number of characters per second to a PC from a simple micro controlled device rs232 port at the least for debugging purposes.

I can select and sucesfully transmit/receive at speeds up to 3M baud without significant data coruption on short packets, however for sustained data I get too many overrun errors for it to be usefull, even at 230K buad it is too much.

I am using a usb serial cable, on windows 7 (64) on an I7 system, so it should have plenty of cpu power to keep up. it only needs to service it twice per millisecond at 230kBaud to keep up.

I am programming with C# and have 3 threads, one for the UI, one for the port, and one for decoding the data.

I have a large data buffer, and I am calling read fast enough so that I get about 100 characters on average, the SerialPort object port buffer is set to "very big" (64k), with byte threshold set to 100, setting it to 1 makes no difference.

The 16 byte Fifo on the usb serial cable is set to 1, but this makes little diference.

From what I have read it is the device driver not reading the usb port fast enough, and the usb serial cable "chip" runs out of buffer.

I have tried different usb serial cables, but they have the same 16 byte buffer and the same problem.

Is there any way I can speed this up ? I would of th

Serial port



I'm try to read a RFID tag ID with a RFID reader.

I want to see ID tag in a text box.

1-Reader, once every 1 second read tag, Therefore I want to see ID tag in a text box Continuous.

2-Reader send a hex/string code to serial port such as    (␠b%) , however I should see  E2 00 90 20 14 19 01 62 25 00 18 1F

would you please help me ; how I can develop a C# code in windows application?

DataGridView - Event triggered when row change while SelectionMode is DataGridViewSelectionMode.Full



I have a data grid view with SelectionMode == DataGridViewSelectionMode.FullRowSelect.  I was wondering if there is an event triggered when the row selected is changed?  I have tried SelectionChanged, CurrentCellChanged, RowEnter, CellClick but none of these events get triggered when the row selected is changed while SelectionMode == DataGridViewSelectionMode.FullRowSelect.  

TextChange event on textbox not getting triggered




I have a textbox which is read only and there is a calendar besides the textbox. When the user selects the date in the calendar pop up, the text in the textbox is populated but it doesn't trigger the text change event. Can anyone tell me how to trigger an event when the text is changed on the textbox?


How improve the serial port reception and analisys?


Hello everyone

I'm building a system that communicates with multiple sensors with RS-232 serial interface. I build "user controls" for each sensor which is responsible for displaying the information received by the serial port, and each control has its own serial and works independent of the main application.

the problem is my app is not fast enough to clean the serial buffer and my analysis function cannot finish, making the serial buffer grows continuously. This function is called inside the serial event handling. (I read in an article that processing should be make in other threads and never in event handlers)

I thought to use a BeginInvoke delegate() to do this analysis, but I would like to know if there are no other possibilities.

another problem can be the draw function that I use to draw the signal (like a ECG), maybe my draw box is not fast enough and it is creating a lag between the serial reception and the drawing.


private void SpO2_SerialPort_DataReceived (object sender, System.IO SerialDataReceivedEventArgs method and)


  if (SpO2_SerialPort. BytesToRead > 72)


    SpO2_SerialPort INFs.read (SerialBuffer, 0, 72);

     for (int I = 0; I < SerialBuffer. Length; I ++)



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend