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

rs232 synchronization issues at 115200

Hi,

I developed two applications to test a flush() method in my application, but I am having some problems when running it at high baud rates (115200)

I connected two computers using a cross-talk cable and wanted to test if all data sent from application 1 was correctly received by application 2 (test the flush method).

The first application is the receiver - basically it opens the serial port and loops infinitely. Inside the loop, it reads from the port and sleeps for 1 seconds (simulating a very slow connection). It also counts the number of bytes received so that I can compare if all data sent was received

The second application is the transmitter - It opens the serial port for a SYNCHRONOUS connection, and uses the WriteFile method to write a certain small buffer (26 bytes) N times. It consists of several loops, where right after writing the data it calls my flush() method which checks if the TX buffer is empty (checks if all data sent were received).
If TX buffer has any bytes on it, them the application sleeps for some while, waiting till all data is transmitted. Otherwise, it goes to the next iteration of the loop, to write more data

The program runs fine if I do not open the serial port at 115200. When running it at this specific bit rate, most of the data sent is lost (the transmitter sends everything, but not all data is received by the received application)

The TX buffer is always empty, which - according to MS documentation - is correct because I am using a synchronous connection. However, I don't understand how couldn't the data be sent! Why am I loosing data? Shouldn't it be supposed to be synchronized?? It there anything else I should do after writing the data (after calling WriteFile) to guarantee that the data was received

Both machines are running Windows 2000
Software was developed using Visual C++ 6.0 - pure win32 application (no .NET use - yet)

Any help would be greatly appreciated

Regard

Pete
Nov 17 '05 #1
6 3113
Just a small note. I have retested the application, and it also fails for 57600 bps.
Nov 17 '05 #2

"Peter Hans" <an*******@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...

The second application is the transmitter - It opens the serial port for a SYNCHRONOUS connection,

I don't know what you mean here, but you don't mean SYNCHRONOUS. Are you
talking about flow control?
The program runs fine if I do not open the serial port at 115200. When running it at this specific bit rate, most of the data sent is lost (the
transmitter sends everything, but not all data is received by the received
application).

You need to call ClearCommError to find out what kind of error you're
getting. I strongly suspect you'll be seeing overflows, because you have no
flow control.
The TX buffer is always empty, which - according to MS documentation - is

correct because I am using a synchronous connection. However, I don't
understand how couldn't the data be sent! Why am I loosing data? Shouldn't
it be supposed to be synchronized?? It there anything else I should do after
writing the data (after calling WriteFile) to guarantee that the data was
received?

You need to make sure you've called the following things on the serial port
before you start anything else, and understood what they all mean:
SetupComm, Get/SetCommState, SetCommTimeouts.

If you've missed-out one of these, then you're using completely unknown
settings, and you'll struggle to get anything working.

It's not at all easy to get serial comms right, so you need to be careful at
every stage.
Will

Nov 17 '05 #3
Thanks for answering

I tested the overflow condition you stated and you are correct. The Transmitter application is causing an overflow! It is writting more data than the Receiver's application can consume. Is there anyway to solve this without using flow control mechanisms? The kind of devices that my application will be using may not support any FLOW control

I was trying to use the COMSTAT.CbOutQue structure, returned by the method ClearCommError method to check the number of byte that are still on the transmitter's buffer, but it always returns 0 for serial devices. The idea was to force the Transmitter application to sleep while this value was greater than zero.

Regarding the SYNCHRONOUS, I was refering to the way the CreateFile is being called in my application to open the serial port - I am no using the OVERLAPPED flag.

regard

Peter
Nov 17 '05 #4
Peter Hans wrote:
Thanks for answering!

I tested the overflow condition you stated and you are correct. The
Transmitter application is causing an overflow! It is writting more
data than the Receiver's application can consume. Is there anyway to
solve this without using flow control mechanisms? The kind of devices
that my application will be using may not support any FLOW control.


I can't give you a worked-example, since I don't have one lying about, but
in order to receive without dropping characters, you need to use overlapped
I/O and asynchronous reads.

The general pattern is to start two (or more) async read requests, and each
time a request completes, process the received data and then start another
read request. You need to have enough read requests queued to cover
whatever processing time your applicaion needs (you may need to do some
experimentation varying buffer sizes and number of outstanding reads).
Using overlapped I/O, your program can easily receive data at rates of
megabytes per second without dropping any data on a modern PC.

-cd

Nov 17 '05 #5

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:u7**************@TK2MSFTNGP10.phx.gbl...

I can't give you a worked-example, since I don't have one lying about, but
in order to receive without dropping characters, you need to use overlapped I/O and asynchronous reads.
I'm not 100% convinced that going overlapped is necessarily *essential*. If
you set a big receive buffer with SetupComm, then be appropriate behaviour
with ReadFile and SetCommTimeouts, you should be able to keep up with
ordinary serial port rates.
Using overlapped I/O, your program can easily receive data at rates of
megabytes per second without dropping any data on a modern PC.


This multi-read/buffering scheme is definitely the ultimate, but it's not
trivial to implement, and might be more than the OP needs or wants at this
stage. I'd reckon he should play around with RX buffer sizes a bit first.

Will


Nov 17 '05 #6
Will Dean wrote:
"Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospam > wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...

I can't give you a worked-example, since I don't have one lying
about, but in order to receive without dropping characters, you need
to use overlapped I/O and asynchronous reads.


I'm not 100% convinced that going overlapped is necessarily
*essential*. If you set a big receive buffer with SetupComm, then be
appropriate behaviour with ReadFile and SetCommTimeouts, you should
be able to keep up with ordinary serial port rates.
Using overlapped I/O, your program can easily receive data at rates
of megabytes per second without dropping any data on a modern PC.


This multi-read/buffering scheme is definitely the ultimate, but it's
not trivial to implement, and might be more than the OP needs or
wants at this stage. I'd reckon he should play around with RX buffer
sizes a bit first.


True in both regards. Multi-buffered overlapped I/O is tricky at best - but
there's no doubt that any PC runing Windows (let alone a modern one) can
handle 115200 baud with overlapped reads.

-cd
Nov 17 '05 #7

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

Similar topics

1
by: Dan | last post by:
I wnat to see in browser an status from an device connected on rs232 port The java class for read from serial port is: //Serial.java import java.io.*; import java.util.*; import...
4
by: nchap99 | last post by:
hello, Does anybody know if Microsoft Dot Net supports the RS232 type of connection. As far as I know Visual basic 6 supports RS232 connection format. Thanks,
6
by: Przemo | last post by:
Hi, Do you know some good RS232C class? There is one in VB.NET 101 Examples, but I think it is poor. 1. I can't for e.g. read into my application all data received. I must tell how many...
0
by: JDR | last post by:
I am trying to implement an abstract query factory in .NET. My solution uses a Factory that creates a concrete command class using reflection and caches an instance of it in a HashTable. Each...
5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
4
by: Amjad | last post by:
I was looking at the MSCOMM32.OCX help when I found that it supports only up to 256000 bps baud rate. Is there another .NET COM that supports higher baud rates (e.g. 460800 and 921600 bps) Thanks...
8
by: Terry Olsen | last post by:
I'm trying to use the RS232 class that was in the Platform SDK (i think). Has anyone else used this with events successfully? Here's what i've got: ====================== Public WithEvents...
3
by: dast | last post by:
Hi, I'm successfully using Richard Grier's NETCommOCX software (www.hardandsoftware.com) to communicate with a device over the USB-port (with a USB-serial-converter) at 115200 bps. Now the...
7
by: Robert | last post by:
Hi, I have noticed some synchronization issues when using javascript. I'll give you an example. It is easy to reproduce the problem if you can cause some delay in the webserver before sending...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: 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...
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...

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.