473,788 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Byt esToRead;

string data = com.thePort.Rea dExisting();

// Make sure we are aligned on the <STXcharacter

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

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

com.DataReceive d(data);
com.thePort.Dis cardInBuffer(); // 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 2925
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
2287
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 groups knows a solution. I'm using code (roughly like): using System; using System.Management; public class Foo {
4
7470
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: Use P/Invoke to Develop a ..NET Base Class Library for Serial Device Communications John Hind - MSDN Magazine - October 2002) it works fine except for one problem. i cannot address any port higher than COM9. I am using an equinox multi-serial...
3
9331
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. VB.net literature does not provide any coverage on either the serial ports or the USB ports.
1
10919
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 errors 2) My Nokia 6600 prompted me the message "Accept Connection request from DEMON?" note: DEMON is my computers name. 3) Using my Nokia 6600, I hit the button that refers to the "Yes"
3
2995
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 works nicely. Then I put the app on on a virtual Windows machine running inside of vmware on the same Linux box. Vmware only lets me have four serial ports so I run the app against four serial ports using four threads. The app did not respond...
5
9498
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 to opening the Serial Port and catching the associated exception? Thanks If there isn't a way to determine the Serial Port within .NET I would be willing, I guess, to use a WinAPI is that was the only way.
3
15461
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 with starting with CNCA0 <-CNCB0 CNCA1<-CNCB1 etc., When I created a port with this name and try to open it using SerialPort.Open,
2
3962
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 development computer I don't have ay problem with my application.
3
14825
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
2001
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 worked well in XP, but under Vista (now with SP1) the Bluetooth ports don't show correctly. We have half a dozen different brands and types of Bluetooth on various
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10175
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.