MSCOMM handshaking problem! 
Author Message
 MSCOMM handshaking problem!

We are using the MSComm control to send large amount of data
to a specialized printer. This printer uses Xon/Xoff and RTS/CTS
flow control.

The problem we have is that, on a hold condition (Xoff), after
an approximate delay of 2 sec. the internal MSComm transmit
buffer is flushed!

The result is that we have partial lines to the printer.

The problem has been track down to the following code:

- Form with two buttons (btnOpen and btnSendText) and the MSComm control

Private Sub btnOpen_Click()

        comVJ.CommPort = 1
        comVJ.Settings = "9600,N,8,1"
        comVJ.Handshaking = comRTS
        comVJ.InputLen = 1
        comVJ.SThreshold = 1
        comVJ.PortOpen = True
End Sub

Private Sub btnSendText_Click()

        comVJ.Output = "ABCDEFGHIJKLMNOP"

End Sub

Private Sub comVJ_OnComm()

   Select Case comVJ.CommEvent
      Case comEventCTSTO
      Case comEventBreak
      Debug.Print "A Break was received."
      Case comEventFrame
      Debug.Print " Framing Error"
      Case comEventOverrun
      Debug.Print " Data Lost."
      Case comEventRxOver
      Debug.Print " Receive buffer overflow."
      Case comEventRxParity
      Debug.Print " Parity Error."
      Case comEventTxFull
      Debug.Print " Transmit buffer full."
      Case comEventDCB
      Debug.Print " Unexpected error retrieving DCB]   Events"
      Case comEvCD
      Debug.Print " Change in the CD line."
      Case comEvCTS
      Debug.Print " Change in the CTS line."
      Case comEvDSR
      Debug.Print " Change in the DSR line."
      Case comEvRing
      Debug.Print " Change in the Ring Indicator."
      Case comEvReceive
      Debug.Print " Received RThreshold # of chars."
      Case comEvSend
      Debug.Print " There are SThreshold number of characters in the
transmit buffer."
      Case comEvEOF
      Debug.Print " An EOF charater was found in the input stream"
      Case Else
      Debug.Print " Else..."
   End Select
End Sub

'------------------------------------------------------------
The resulting trace we have is:

"There are SThreshold number of characters in the transmit buffer."

and the buffer is flushed.

QUESTION:

Why is the buffer flushed?
It seems that there is a timout but there is no property to set it
How do we distinguish if the buffer is empty because it has been sent
or because it has been flushed?

Any help would be greatly appreciated

Francois Boulanger



Tue, 08 May 2001 03:00:00 GMT  
 MSCOMM handshaking problem!
Hi,

Actually, the timeout is 5 seconds, not 2.  None-the-less, it is a problem.
You can use the Windows API to override the timeout that MSComm sets.  I
present this code, and other versions for related issues in my book.  See
below for information.

Here is one version:

Type COMMTIMEOUTS
 ReadIntervalTimeout As Long
 ReadTotalTimeoutMultiplier As Long
 ReadTotalTimeoutConstant As Long
 WriteTotalTimeoutMultiplier As Long
 WriteTotalTimeoutConstant As Long
End Type

Declare Function SetCommTimeouts Lib "Kernel32" (ByVal _
 hFile As Long, lpCommTimeouts As COMMTIMEOUTS) As Long
Declare Function GetCommTimeouts Lib "Kernel32" (ByVal _
 hFile As Long, lpCommTimeouts As COMMTIMEOUTS) As Long

Then, in your code:

Dim timeouts As COMMTIMEOUTS
Dim Ret As Long
 If Comm1.PortOpen = False Then
  Comm1.PortOpen = True
 End If
 Ret = GetCommTimeouts(Comm1.CommID, timeouts)
 ' Set some default timeouts
 timeouts.ReadIntervalTimeout = 1
 timeouts.ReadTotalTimeoutMultiplier = 1
 timeouts.ReadTotalTimeoutConstant = 1
 timeouts.WriteTotalTimeoutMultiplier = 1
 timeouts.WriteTotalTimeoutConstant = _
  (Comm1.OutBufferSize \ Val(Comm1.Settings)) _
  * 10000 + 1000
 Ret = SetCommTimeouts(Comm1.CommID, timeouts)

This code will set the WriteTotalTimeoutConstant, based on the
OutBufferSize, and the bitrate.  Make an appropriate change to this code to
allow extended timeouts to handle the potential problem with flow control.
For example, you might want to change the code fragment to:

Dim timeouts As COMMTIMEOUTS
Dim Ret As Long
 If Comm1.PortOpen = False Then
  Comm1.PortOpen = True
 End If
 Ret = GetCommTimeouts(Comm1.CommID, timeouts)
 ' Set some default timeouts
 timeouts.ReadIntervalTimeout = 1
 timeouts.ReadTotalTimeoutMultiplier = 1
 timeouts.ReadTotalTimeoutConstant = 1
 timeouts.WriteTotalTimeoutMultiplier = 1000
 timeouts.WriteTotalTimeoutConstant = 3600_
 Ret = SetCommTimeouts(Comm1.CommID, timeouts

This fragment specifies a WriteTotalTimeout of 3600 seconds (one hour).
This should be sufficient for almost any laggardly flow control situation.

--
Richard Grier
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition (355 pages).
For information look on my homepage at
http://ourworld.compuserve.com/homepages/richard_grier.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Tue, 08 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. help - how do I implement XonXoff Handshaking with MSComm

2. MSComm handshaking?

3. Handshaking and MSCOMM.VBX

4. MSComm handshaking trouble

5. MsComm Control for Using Xon/Xoff HandShaking

6. Serial Port Handshaking

7. Handshaking With Serial Ports In Mac QuickBASIC

8. Help needed for RS232 ENQ/ACK handshaking

9. HOW to handshaking two modem's

10. Software Handshaking

11. Q: MS Internet Control Pack - TCP Handshaking

12. Can MSCOMM32 handle RTS handshaking at 115K ???

 

 
Powered by phpBB® Forum Software