i changed my serial port program because it occasionally produced bad data. the problem is the new version is too slow.
the molding machine tells the program when it starts a new cycle by sending the shot number. then the program asks for the parameters one after the other and builds the replies into a string and adds a newline at the end. it occasionally gets the whole line and once it had two good lines consecutively, however, even with a 27 second cycle time, the new cycle usually starts before the line gets written to the textbox so two cycles get merged into one line. here is the code any suggestions appreciated.
Private Sub MSComm1_OnComm()
Static strLastCharRecieved As String
Static strRawData As String
Dim strData As String * 15
If MSComm1.CommEvent = comEvReceive Then
If strLastCharRecieved = Chr$(3) Then
strLastCharRecieved = MSComm1.Input
'format and record data
strData = Mid(strRawData, 7) 'should be 6 not 7
strRawData = ""
txtData.Text = strData 'triggers txtData_Change()
Else
strLastCharRecieved = MSComm1.Input
If strLastCharRecieved <> Chr$(3) Then
strRawData = strRawData & strLastCharRecieved
End If
End If
End If
'g_blnRecieveEvent = True
'If MSComm1.CommEvent = comEventOverrun Then
'MsgBox "Port Overrun Error"
'End If
'If MSComm1.CommEvent = comEventFrame Then
'MsgBox "Framing Error"
'End If
End Sub
Private Sub txtData_Change()
Dim strDateTime As String * 16
If m_intCount = 0 Then
strDateTime = Date
m_strRecord = strDateTime
strDateTime = Format(Time, "hh:MM:ss"
m_strRecord = m_strRecord & strDateTime
End If
m_strRecord = m_strRecord & txtData.Text
m_intCount = m_intCount + 1
Call Request(m_intCount)
End Sub
Private Sub Request(intNumber As Integer)
Select Case intNumber
Case 1
MSComm1.Output = Chr$(4) & "T300" & Chr$(5) 'Request Cycle Time
Case 2
MSComm1.Output = Chr$(4) & "T301" & Chr$(5) 'Request Filling Time
Case 3
MSComm1.Output = Chr$(4) & "T302" & Chr$(5) 'Request Plast Time
Case 4
MSComm1.Output = Chr$(4) & "T307" & Chr$(5) 'Request Screw Time
Case 5
MSComm1.Output = Chr$(4) & "T306" & Chr$(5) 'Request Filling1 Time
Case 6
MSComm1.Output = Chr$(4) & "S303" & Chr$(5) 'Request Cushion Position
Case 7
MSComm1.Output = Chr$(4) & "S304" & Chr$(5) 'Request Hold End Position
Case 8
MSComm1.Output = Chr$(4) & "S302" & Chr$(5) 'Request V-P Change Position
Case 9
MSComm1.Output = Chr$(4) & "S301" & Chr$(5) 'Request Filling Start Position
Case 10
MSComm1.Output = Chr$(4) & "P300" & Chr$(5) 'Request Filling Peak Pressure
Case 11
m_strRecord = m_strRecord & vbNewLine
txtLog.Text = txtLog.Text & m_strRecord
intNumber = 0
m_strRecord = ""
End Select
End Sub
the molding machine tells the program when it starts a new cycle by sending the shot number. then the program asks for the parameters one after the other and builds the replies into a string and adds a newline at the end. it occasionally gets the whole line and once it had two good lines consecutively, however, even with a 27 second cycle time, the new cycle usually starts before the line gets written to the textbox so two cycles get merged into one line. here is the code any suggestions appreciated.
Private Sub MSComm1_OnComm()
Static strLastCharRecieved As String
Static strRawData As String
Dim strData As String * 15
If MSComm1.CommEvent = comEvReceive Then
If strLastCharRecieved = Chr$(3) Then
strLastCharRecieved = MSComm1.Input
'format and record data
strData = Mid(strRawData, 7) 'should be 6 not 7
strRawData = ""
txtData.Text = strData 'triggers txtData_Change()
Else
strLastCharRecieved = MSComm1.Input
If strLastCharRecieved <> Chr$(3) Then
strRawData = strRawData & strLastCharRecieved
End If
End If
End If
'g_blnRecieveEvent = True
'If MSComm1.CommEvent = comEventOverrun Then
'MsgBox "Port Overrun Error"
'End If
'If MSComm1.CommEvent = comEventFrame Then
'MsgBox "Framing Error"
'End If
End Sub
Private Sub txtData_Change()
Dim strDateTime As String * 16
If m_intCount = 0 Then
strDateTime = Date
m_strRecord = strDateTime
strDateTime = Format(Time, "hh:MM:ss"
m_strRecord = m_strRecord & strDateTime
End If
m_strRecord = m_strRecord & txtData.Text
m_intCount = m_intCount + 1
Call Request(m_intCount)
End Sub
Private Sub Request(intNumber As Integer)
Select Case intNumber
Case 1
MSComm1.Output = Chr$(4) & "T300" & Chr$(5) 'Request Cycle Time
Case 2
MSComm1.Output = Chr$(4) & "T301" & Chr$(5) 'Request Filling Time
Case 3
MSComm1.Output = Chr$(4) & "T302" & Chr$(5) 'Request Plast Time
Case 4
MSComm1.Output = Chr$(4) & "T307" & Chr$(5) 'Request Screw Time
Case 5
MSComm1.Output = Chr$(4) & "T306" & Chr$(5) 'Request Filling1 Time
Case 6
MSComm1.Output = Chr$(4) & "S303" & Chr$(5) 'Request Cushion Position
Case 7
MSComm1.Output = Chr$(4) & "S304" & Chr$(5) 'Request Hold End Position
Case 8
MSComm1.Output = Chr$(4) & "S302" & Chr$(5) 'Request V-P Change Position
Case 9
MSComm1.Output = Chr$(4) & "S301" & Chr$(5) 'Request Filling Start Position
Case 10
MSComm1.Output = Chr$(4) & "P300" & Chr$(5) 'Request Filling Peak Pressure
Case 11
m_strRecord = m_strRecord & vbNewLine
txtLog.Text = txtLog.Text & m_strRecord
intNumber = 0
m_strRecord = ""
End Select
End Sub