Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / June 2008



Tip: Looking for answers? Try searching our database.

RS232 flowcontrol

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 17 Jun 2008 08:44 GMT
Dear all
I have written a communication app. in VB6 that uses the Winapi functions to
access the serial Interface(createfile,etc).
In general my app works OK but occassionally I get bufferoverruns and
therefore I loose some data ALTHOUGH I use RTS/CTS flowcontrol.
All the wiring is OK and I can also see that my app deactivates the RTS
signal periodically in case the buffer gets full.
I made some investigations and found out that my communication device still
can send upto 256databytes once it detects a deactivated RTS signal.
On the device there is no way to prevent this. These additional 256bytes
seem to be the cause for the bufferoverrun.
I tried to adjust the parameters Xonlim and Xofflim of the structure DCB to
have enough room for these additional databytes in the RXbuffer this didn't
help and I still get CE_overrun error. Increasing the buffersize(I use
2048bytes) to 4096 also didn't help.
Has anyone ever run into that problem and knows how I can prevent the
overrun error?
Regards
Peter
Peter - 17 Jun 2008 10:39 GMT
I think I have already found the reason for this problem: The usb-V.24
converter I use seems to add a hugh delay to the RTS line which will fill up
my rxbuffer.
The flowcontrol mechanism works fine on a native RS232 comport in my PC.
Regards
Peter

> Dear all
> I have written a communication app. in VB6 that uses the Winapi functions
[quoted text clipped - 15 lines]
> Regards
> Peter
Dick Grier - 17 Jun 2008 17:30 GMT
Hi,

What you are seeing is two-fold.

First, the USB driiver software (virtual serial port) UART probably
implements a 96-byte (or possible deeper) transmit FIFO.  This FIFO is
emptied, even if CTS is lowered.  There isn't anything that you can do in
your application code if this is, in fact, the case -- except to work around
it yourself (see below).

Second, the FIFO in your PC UART is only 16-bytes in depth, so it sounds
like the receiving hardware can handle 16-bytes, but not the larger number.

So, what's the work-around?  The obvious.  Leave CTS/RTS flow control in
place, then... Write a routine that breaks transmit data into small chunks,
of less than 16-bytes.  Check the status of CTS in your transmit routine.
If CTSHolding = True, then send 16-bytes.  Add a small delay between each
16-byte "chunk" to allow CTS to propogate from hardware to your software.
If CTSHolding = False, then stay in a delay loop until it goes back to True.
Continue until all data have been sent.   I'd start with about a 1 mS or so
delay between each "chunk," but a much larger delay inside the loop (perhaps
50 mS).  Keep decreasing the large delay until you encounter a problem, then
bump it back up some, until it is reliable.

Signature

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.

Peter - 19 Jun 2008 07:07 GMT
Thanks for your answer.
But I have problems to understand it.
I don't have any possibilities to modify the sending behaviour of my serial
device(a GPRS modem).
It is specified that after my VB6 app has lowered signal RTS it my still
send additional 256bytes until it stops sending data.
Inbetween I think that these additional 256bytes are not the main cause of
my problem because if I use the native COM-Port of my PC(instead of a
USB-Comm converter) everything works fine.
Instead, I think that either the USB driver or the USB hardware adds a
certain delay to signal RTS.
In case the PC's receive buffer gets full the "serial driver" instructs RTS
to go low but due to the additional delay(coming from the USB converter)
much more data can still access the receive buffer which gets overflown.
Now I try to play with the two parameters Xonlim and Xofflim of the DCB
structure because it seems that they also define the levels when RTS should
be lowered.
I hope I can adjust the flowcontrol mechanism(also by increasing the size of
the receive buffer) to accept the additional delay of signal RTS on the USB
converter.
Regards
Peter

> Hi,
>
[quoted text clipped - 21 lines]
> until you encounter a problem, then bump it back up some, until it is
> reliable.
Peter - 19 Jun 2008 14:23 GMT
Hi
Should XoffLim and XonLim of the DCB structure work in case I use RTS/CTS
flowcontrol(fRtsControl=RTS_CONTROL_HANDSHAKE and fOutxCtsFlow=true)?
Or does XoffLim and XonLim only work with Xon/Xoff Flowcontrol?
What ever value I set for XoffLim and XonLim, the app does not set/reset RTS
earlier or later in case the receive buffer gets full.
Could it be that these values are ignored for RTS/CTS flowcontrol?
Any other reason why it is not working?

In MSDN the following discriptuion con be found:
*****************************************************
XoffLim
Maximum number of bytes allowed in the input buffer before flow control is
activated to allow transmission by the sender. This assumes that either
XON/XOFF, RTS, or DTR input flow control is specified in fInX, fRtsControl,
or fDtrControl. The maximum number of bytes allowed is calculated by
subtracting this value from the size, in bytes, of the input buffer.
*****************************************************

Regards
Peter

> Hi,
>
[quoted text clipped - 21 lines]
> until you encounter a problem, then bump it back up some, until it is
> reliable.
Dick Grier - 20 Jun 2008 17:27 GMT
Hi,

These settings do not affect the operation of the FIFO.  They only control
the standard Windows serial driver -- some drivers for USB devices may use
them, others may not.

Unfortunately, MSDN says only what the article author thinks "should be
true," and has no control over the reality of what really is true.
Experience (and experimentation) are the only real world guides.

Without "hands-on" the actuall hardware and drivers, I can only offer
advice.

Dick

Signature

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.

Peter - 23 Jun 2008 07:02 GMT
Thanks, Dick

But XoffLim and XonLim also do not work on my native serial Commports(no
USB)?
Do you have any experience whether these parameters should work with RTS/CTS
flowcontrol at all?
Regards
Peter

> Hi,
>
[quoted text clipped - 10 lines]
>
> Dick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.