Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm tied up computer

Status
Not open for further replies.

lakojeff

Technical User
Nov 3, 2006
4
US
Hi,

I have a VB6 program controller a temperature controller.

Here is the connection: Serial Comm2 --- RS232 --- RS485 --- temperature controller.

Every time I close the program, it sends a STOP signal to the temperature controller, then close the program. However, after the program is closed, and waits for a couple of seconds, the computer ties up. I can still operate it but super slow. When I open another program to use the same comm port, the computer is back to be normal.

So I am thinking if there is something left in the Comm port or the RS-232 buffer that I need to clear it up. But how can I do that? Any ideas? Please see additional information below.

In the VB program I have:

MSComm control properties:

Handshaking - comNone
InBufferSize - 1024
OutBufferSize - 512
InputLen - 0
InputMode - 0 - comInputModeText
ParityReplace - ?
RThreshold - 0
RTSEnalbe - False
Settings - 19200,n,8,1
SThreshold - 0

Coding:

Open Port:

MSComm1.CommPort = 2
MSComm1.Handshaking = comRTS
MSComm1.Settings = "19200,N,8,1"
MSComm1.InputMode = comInputModeText
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
MSComm1.PortOpen = True

=======================================================

MSComm1_OnComm

Dim sBuffer As String
Dim sHeader As String
Dim sTemp As String
Dim iCounter As Integer
Dim fTemp As Single

Select Case MSComm1.CommEvent
' Handle each event or error by placing
Case comEvReceive ' Received RThreshold # of chars.
sBuffer = MSComm1.Input
If sBuffer = Chr$(3) Then 'we have found the end of the line
sHeader = Right$(f_strInString, 22)
If Left$(sHeader, 14) = "01000001010000" Then 'we have the upper temperature reading
fTemp = Val("&h" & Mid$(sHeader, 15, 8))
g_sUpperTemp = fTemp / 10
If Not bMetric Then fTemp = (fTemp / 10 * 1.8 + 32) * 10
frmSeal.lblResults(1).Caption = Format(Val(fTemp) / 10, g_strTempFormat)
ElseIf Left$(sHeader, 14) = "02000001010000" Then 'we have the lower temperature reading
fTemp = Val("&h" & Mid$(sHeader, 15, 8))
g_sLowerTemp = fTemp / 10
If Not bMetric Then fTemp = (fTemp / 10 * 1.8 + 32) * 10
frmSeal.lblResults(2).Caption = Format(Val(fTemp) / 10, g_strTempFormat)
End If
f_strInString = ""
Else ' we are not at the end so keep building the string
f_strInString = f_strInString & sBuffer
End If
End Select

===========================================================

Close program

OutString = Chr$(2) & "01000" 'Command Frame
OutString = OutString & "30050101" & Chr$(3) 'send the STOP Command to the temperature controllers
OutString = OutString & Chr$(CalcBCC(OutString))
If Not bNoComms Then MSComm1.output = OutString
MSComm1.PortOpen = False

Unload Me
End

Please help ASAP 'cause I need to fix it by tomorrow.
 
Oh I forgot to mention. I used to use the same program in an older computer using Win 2000. Then upgrade to XP in a new machine and the issue starts happen. Faster computer is not better but worse!
 
You're probably closing the port before it has emptied the output buffer.
Code:
If Not bNoComms Then 
   With MSComm1
      .InBufferCount = 0
      .Output = OutString
      Do Until .OutBufferCount = 0
         DoEvents
      Loop
      .PortOpen = False
   End With
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top