473,387 Members | 1,549 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,387 software developers and data experts.

SerialPort

Using SerialPort
ReceivedBytesThreshold = 1

Handling DataReceived event as:
int noOfBytesInBuffer = myPort.BytesToRead;
byte[] myBuffer = new byte[noOfBytesInBuffer];
myPort.Read(myBuffer, 0, noOfBytesInBuffer)

noOfBytesInBuffer is always set to 8 in my case (the transmissions on the
line are chunks of 8 bytes).

Why this behaviour ?
It seems like the OS (XP SP2) waits (approx. 16 ms) to see if more bytes are
coming (FIFO buffer is disabled).
I had a similar problem a couple of years ago, but by using W2k I did not
have the problem, now I do not have any W2k available anymore.

Some registry setting ?
Oct 7 '06 #1
3 1668
Hi,
>>
It seems like the OS (XP SP2) waits (approx. 16 ms) to see if more bytes are
coming (FIFO buffer is disabled).
<<

Do NOT disable the FIFO receive buffer. This will reduce your performance.
You should leave it a 14 (High), IMO. There are very few good reasons to
set the FIFO size to a lower value.

There is no way to know how many bytes will be delivered in a "chunk." 16
mS seems unreasonable to me, though. What is the serial speed? What else
is going on at the same time? Ususally, 1-2 mS will be what you expect.
However, system latency is totally unpredicatable.

How are you measuring 16 mS? Perhaps you are not seeing what you think you
are seeing.

No, there is no Registry setting to contol any part of the Windows serial
processing behavior.

BTW, you are creating a new buffer each time you want to read data. Your
code will be slightly faster if you change the scope of myBuffer so that it
isn't created each time, but is reused.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Oct 7 '06 #2
Thanks for reply

My code is not my real code, only to show principles (I do not create array
every time).
Speed is 9600
I can see because I report the time of each "arrival" (or at least what
seems to be the arrival, perhaps some .net latency or something), and these
"always" comes with 16 ms intervals.

By the way, now (SP 2 ?) diabling of FIFO has indeed effect (I didn'r
realize that machine restart was neccessary).
With e.g. FIFO set to 14, is it then possible to detect "silent line" of
approx 4-5 ms ?

"Nothing" else is going on at the same time (but of course some background
services)

"Dick Grier" <dick_grierNOSPAM@.msn.comwrote in message
news:em****************@TK2MSFTNGP05.phx.gbl...
Hi,
>>>
It seems like the OS (XP SP2) waits (approx. 16 ms) to see if more bytes
are
coming (FIFO buffer is disabled).
<<

Do NOT disable the FIFO receive buffer. This will reduce your
performance. You should leave it a 14 (High), IMO. There are very few
good reasons to set the FIFO size to a lower value.

There is no way to know how many bytes will be delivered in a "chunk." 16
mS seems unreasonable to me, though. What is the serial speed? What else
is going on at the same time? Ususally, 1-2 mS will be what you expect.
However, system latency is totally unpredicatable.

How are you measuring 16 mS? Perhaps you are not seeing what you think
you are seeing.

No, there is no Registry setting to contol any part of the Windows serial
processing behavior.

BTW, you are creating a new buffer each time you want to read data. Your
code will be slightly faster if you change the scope of myBuffer so that
it isn't created each time, but is reused.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.

Oct 8 '06 #3
Hi,

Sorry, I have been out of the country, so my reply has been delayed.
>>
With e.g. FIFO set to 14, is it then possible to detect "silent line" of
approx 4-5 ms ?
<<

Perhaps... Perhaps not. There are no real-time assurances in Windows. If
you have a really fast processor and nothing much else is going on then,
perhaps becomes "probably, most of the time."
>>
"Nothing" else is going on at the same time (but of course some background
services)
<<

There are lots of things going on "behind the scenes" so killing any
services that aren't needed will improve real-time performance. And, it is
possible to fiddle the process Priorities for your application, too. Your
actual experience will vary from Good to OK (maybe) to "you simply cannot do
it," depending on too many variable to say. So, you will have to deploy a
test to see.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Oct 20 '06 #4

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

Similar topics

2
by: Andrea Judge | last post by:
Hi there, I'm developing an application to catch OBD sensors' data from my car. I connect it via a RS232 interface. Now. with HyperTerminal I can connect and send/receive data, but I'd like to...
0
by: Joshua Moore | last post by:
I'm trying to convert from a lot of invoked code to c# 2.0 SerialPort code. I can't find a way to set fOutxCtsFlow to true (maybe CTSEnable?) and fRtsControl = RTS_CONTROL_HANDSHAKE (RtsEnable?). ...
13
by: Jean Paul Mertens | last post by:
Hello, Someone can tell me why I dont get serial port events in a Service, I created a separate Thread to open the port but no events are coming up (the same happens when I use the timer...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
0
by: ricolee99 | last post by:
Hi Everyone, I'm using the System.IO.Ports.SerialPort component to attempt to kill an existing component opened by another application. I use the following code: SerialPort serialPort = new...
2
by: Jay | last post by:
Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx... public static void Main() { string name; string message; StringComparer stringComparer =...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
6
by: Keith Lee | last post by:
All: I am attempting to compile the perl module Device::SerialPort and get this error during make -- Manifying blib/man3/Device::SerialPort.3pm Can't open blib/man3/Device::SerialPort.3pm for...
10
by: sklett | last post by:
I'm trying to send some printer commands (ZPLII) to an attached USB printer using the SerialPort component. I didn't get very far at all. In fact I haven't gotten anywhere. The first problem I...
0
by: cronusf | last post by:
I set up two virtual COM ports 3 and 4 using com0com. I tried to test it with the following program. However, the DataReceived event handlers never get called. Can anyone with SerialPort class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.