473,406 Members | 2,707 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,406 software developers and data experts.

MSComm initialization

Using C# .NET

I've implemented serial com with MSComm. My application works with a
few errors. Most importantly, could someone tell me why the OnComm
event fires twice. Let me explain:

I have a data file that is sent across the serial port. The OnComm
event fires indicating activity. With a file of let's say 4 records.
Stepping through my app I noticed that in my com.Input variable, the
first and only the first record is visible. That record is processed,
but then the app continues to the same method (no while loop, just an
if) only this time the variable contains the remaining records in my
file.

Threshold is set to 75 wanting the event to fire at that number,
InputLen set to 0. I've included a snippet of code to help clarify.

Help me see what I'm missing.

FORM LOAD
private void Form1_Load(object sender, System.EventArgs e)
{
com.CommPort = 1;
if (com.PortOpen) com.PortOpen = false;
com.EOFEnable = true;
com.RThreshold = 75;
com.Settings = "9600,n,8,1";
com.DTREnable = true;
com.Handshaking = MSCommLib.HandshakeConstants.comNone;
com.InputMode = MSCommLib.InputModeConstants.comInputModeText;
com.InputLen = 0;
com.NullDiscard = false;
com.OnComm += new System.EventHandler(this.OnComm);
com.PortOpen = true;

}

ONCOMM EVENT

private void OnComm(object sender, System.EventArgs e)
{
if (com.InBufferCount > 0)
{
ProcessComData((string) com.Input);
}

}

PROCESS DATA ****** OCCURS TWICE *******

private void ProcessComData(string input)
{
lstData.Items.Add(input);
StreamWriter listwriter = new StreamWriter("C:\\Interrogator.txt",
false);
listwriter.Write(input);
listwriter.Close();
//Delay or breakpoint is necessary for accurate output.
MessageBox.Show ("New information available", "TITLE",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
Nov 15 '05 #1
0 1959

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

Similar topics

1
by: jinoy | last post by:
how can i detect an incoming caller's telephone keystroke using modem, using mscomm or other? how can i detect an outgoing call using mscomm? how can i get a caller id using mscomm?
0
by: Chris | last post by:
I'm using MSComm only reading data from a serial port (OnComm even). When the event is fired I have the data loading in a listbox. No problem except that the data being transferred is not always...
1
by: Peter Krikelis | last post by:
Hi, I am trying to develope a User Control Library that features MScomm control. I test my user control in a test application. When I run the application I receive the following: An...
0
by: morgal | last post by:
That is one reason I quit using MS custom controls, you have to buy the license. In VB 6 they give you a try it license and then you develop a huge application or small one and find out you don't...
4
by: AA | last post by:
Hi I am developing an app in which I have used a MSComm object. I have opened the port, performed the transactions, and then closed the port. But when I check in the task mamager, the memory...
9
by: Carl Gilbert | last post by:
Hi I'm trying to open a vb6 project in vb.net which uses the mscomm component. When running the vb upgrade wizard in vb.net, an error is raised: Upgrade failed, unable to load reerenced...
0
by: swati2106 | last post by:
HI, I have develop a apllication , To store the GPS data in database, for that , to read GPS data I have used the Mscomm port, In which I create the object of class RS232 n open that port,...
0
by: cmdolcet69 | last post by:
I get the following error message when I output to the mscomm: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in COM.exe Additional information: Exception...
0
by: daveman | last post by:
Hello, I'm encountering a "Blue Screen of Death" when I try to send data to a bluetooth sensor via a serial port, using the MSCOMM ActiveX object. I was wondering if anyone has any ideas how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.