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

system.io.ports.serial


I have an application that uses the system.io.ports.serial class to
receive data from a serial device. The device is sending a data stream
of stx then 15 readable ascii characters then a cr. My datareceived
event looks like:

int iBytesToRead = com.thePort.BytesToRead;

string data = com.thePort.ReadExisting();

// Make sure we are aligned on the <STXcharacter

if (data[0] != STX)
{
com.thePort.DiscardInBuffer();
return;
}

//if (iBytesToRead != 17)
// return;

com.DataReceived(data);
com.thePort.DiscardInBuffer(); // discard the checksum

When I run the application in the debugger I 17 characters read but when
I do not run with the debugger I get a variable number of characters -
most often 8 and being the first n characters sent.

It is almost like something is interrupting the ReadExisting.

Any ideas on what is going on?

thanks

pete
Jun 27 '08 #1
1 2913
On Mon, 21 Apr 2008 21:00:23 -0700, Peter Huish <hu***@ozemail.com.au>
wrote:
[...]
When I run the application in the debugger I 17 characters read but when
I do not run with the debugger I get a variable number of characters -
most often 8 and being the first n characters sent.

It is almost like something is interrupting the ReadExisting.
I'm no expert on the SerialPort class, but my reading of the
ReadExisting() method is that it returns immediately, with whatever data
is present. You should not expect it to wait until the end of the
transmission.

Of course this also means it's an error for you to call the
DiscardInBuffer() method, since that will throw away whatever bytes might
have come in after ReadExisting() returned but before you call
DiscardInBuffer(). That sounds like a great recipe for losing data.

So, instead you need to change your logic, so that there's a layer between
the reading of the port and the consumption of the data that handles
delimiting the data.

Pete
Jun 27 '08 #2

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

Similar topics

0
by: Helge Jensen | last post by:
Having posted in microsoft.public.dotnet.framework.sdk and microsoft.public.dotnet.framework.wmi without receiving any response, I posthere on the off-chance that someone who isn't following those...
4
by: M. Raab | last post by:
i have written an application that utilizes serail ports. In order not to have to reinvent code, I decided to use John Hind's sample code that he presented in MSDN magazine last year (Serial Comm:...
3
by: andyI | last post by:
Where do I find information on how to address and pass data to and from the serial ports and USB ports in VB. VB6 supports the serial ports easily but I see no reference to using the USB ports....
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
3
by: Tom Brown | last post by:
Hey people, I've written a python app that r/w eight serial ports to control eight devices using eight threads. This all works very nicely in Linux. I even put a GUI on it using PyQt4. Still...
5
by: LongBow | last post by:
Hello, Is there a way, in .NET, to determine what are the avialable Serial (Communications) Ports on a Windows OS and is there a way to determine that port isn't being use other than attempting...
3
by: Mugunth | last post by:
Hi, I've a strange problem with serial port class of .NET Framework 2.0 I use com0com (Null Modem COM Port emulator) to emulate a virtual port. This application creates virtual com port pairs...
2
by: joaquimfpinto | last post by:
Dear All, I made an app in c# that uses several serial ports. For the serial ports I use a pnp Sunix board, some with 8 serial ports other with 4 or even 2 serial ports. Whenever I use the...
3
by: Bandu | last post by:
hi, i'm using serial port functionality provided by .net framework 2.0 using system.io.ports. Is there anyway that i can set DTR/DSR handshaking? Regards, Bandu
2
by: Dave Harry | last post by:
I'm using the following code to determine the available serial ports: ComboBoxPort.Items.Clear() For Each sp As String In My.Computer.Ports.SerialPortNames ComboBoxPort.Items.Add(sp) Next It...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.