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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program terminates

Status
Not open for further replies.

norason

Programmer
Jan 28, 2009
139
0
0
US
This code runs fine when I run it in de-bugger, but when I run is as an .EXE it terminates the entire program after about 30 seconds when the comm port is open receiving data.

There is no "kill" statement in any of the code.

Any thoughts would be appreciated.

norason



Private Sub CmdGetCurrentPrimeStep_Click()
GetPSR
End Sub

Public Function GetPSR()
If StartScan = False Then
Unload Me
Exit Function
End If
IsStatusVisible
Dim PSRStr As String
With MSComm1
On Error Resume Next
If .PortOpen Then
.PortOpen = False
End If
Select Case COMM_BAUD
Case 0
ChartBaud = "57600"
Case 1
ChartBaud = "19200"
Case 2
ChartBaud = "38400"
Case 3
ChartBaud = "57600"
Case 4
ChartBaud = "115200"
Case Else
ChartBaud = "9600"
End Select
.InBufferSize = 32000
.CommPort = PMP_COMM_PORT + 1

.Settings = ChartBaud + ",n,8,1"
.RThreshold = 1
.SThreshold = 1
.PortOpen = True
.InputLen = 0
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PSR,LR" + XorchecksumPSR(Chr(ChecksumPSR))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSRDataStr = PSRDataStr & MSComm1.Input
If QuitStatus = True Then
Unload fmPumpStatus
Exit Function
End If
For Each frm In Forms
If frm.Name = "fmPumpStatus" Then
If frm.Visible = False Then
QuitStatus = True
Unload fmPumpStatus
Exit Function
End If
End If
Next
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PSR"
LblChartsAvailable.Caption = "FAILED"
Screen.MousePointer = vbDefault
Exit Function
End If
Loop Until InStr(PSRDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
End With
PSRDataStart = InStr(PSRDataStr, ",")
PSRDataEnd = InStrRev(PSRDataStr, ",")
LblPrimeStep.Caption = Mid$(PSRDataStr, PSRDataStart + 4, PSRDataEnd - (PSRDataStart + 4))
GetPP
End Function

Public Function XorchecksumPSR(Buffer As String) As String
Buffer = Chr$(&HAA) + Chr$(&H1) + "X,PSR,LR"
Dim PSRSerial As Integer
Dim ChecksumPSR As Byte
For PSRSerial = 1 To Len(Buffer)
ChecksumPSR = ChecksumPSR Xor (Asc(Mid$(Buffer, PSRSerial, 1)))
Next PSRSerial
XorchecksumPSR = Chr$(ChecksumPSR)
End Function

Private Sub CmdGetPressure_Click()
GetPP
End Sub

Public Function GetPP()
If StartScan = False Then
Unload Me
Exit Function
End If

IsStatusVisible
If QuitStatus = True Then
Unload Me
End If
Dim PPStr As String
With MSComm1
On Error Resume Next
.InputLen = 0
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PP,LR" + XorchecksumPP(Chr(ChecksumPP))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PPDataStr = PPDataStr & MSComm1.Input
If QuitStatus = True Then
Unload fmPumpStatus
Exit Function
End If
For Each frm In Forms
If frm.Name = "fmPumpStatus" Then
If frm.Visible = False Then
QuitStatus = True
Unload fmPumpStatus
Exit Function
End If
End If
Next
If RS232loop > 2000000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PP"
LblChartsAvailable.Caption = "FAILED"
Screen.MousePointer = vbDefault
Exit Function
End If
Loop Until InStr(PPDataStr, "LR") Or RS232COUNTER > 2000000

.InBufferCount = 0
End With
PPDataStart = InStr(PPDataStr, ",")
PPDataEnd = InStrRev(PPDataStr, ",")
LblPumpPressure.Caption = Val(Mid$(PPDataStr, PPDataStart + 4, PPDataEnd - (PPDataStart + 4)))
GetPST
End Function

Public Function XorchecksumPP(Buffer As String) As String
Buffer = Chr$(&HAA) + Chr$(&H1) + "X,PP,LR"
Dim PPSerial As Integer
Dim ChecksumPP As Byte
For PPSerial = 1 To Len(Buffer)
ChecksumPP = ChecksumPP Xor (Asc(Mid$(Buffer, PPSerial, 1)))
Next PPSerial
XorchecksumPP = Chr$(ChecksumPP)
End Function

Private Sub CmdGetStepTimeRemaining_Click()
GetPST
End Sub

Public Function GetPST()
If StartScan = False Then
Unload Me
Exit Function
End If
If QuitStatus = True Then
Unload Me
End If

IsStatusVisible
Dim PSTStr As String
With MSComm1
On Error Resume Next
.InputLen = 0
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PST,LR" + XorchecksumPST(Chr(ChecksumPST))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSTDataStr = PSTDataStr & MSComm1.Input
If QuitStatus = True Then
Unload fmPumpStatus
Exit Function
End If
For Each frm In Forms
If frm.Name = "fmPumpStatus" Then
If frm.Visible = False Then
QuitStatus = True
Unload fmPumpStatus
Exit Function
End If
End If
Next
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PST"
LblChartsAvailable.Caption = "FAILED"
Screen.MousePointer = vbDefault
Exit Function
End If
Loop Until InStr(PSTDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
End With
PSTDataStart = InStr(PSTDataStr, ",")
PSTDataEnd = InStrRev(PSTDataStr, ",")
LblStepTimeRemaning.Caption = Mid$(PSTDataStr, PSTDataStart + 4, PSTDataEnd - (PSTDataStart + 4))
GetPTT
End Function

Public Function XorchecksumPST(Buffer As String) As String
Buffer = Chr$(&HAA) + Chr$(&H1) + "X,PST,LR"
Dim PSTSerial As Integer
Dim ChecksumPST As Byte
For PSTSerial = 1 To Len(Buffer)
ChecksumPST = ChecksumPST Xor (Asc(Mid$(Buffer, PSTSerial, 1)))
Next PSTSerial
XorchecksumPST = Chr$(ChecksumPST)
End Function

Private Sub CmdGetTotalTimeRemaining_Click()
GetPTT
End Sub

Public Function GetPTT()
If StartScan = False Then
Unload Me
Exit Function
End If
If QuitStatus = True Then
Unload Me
End If

IsStatusVisible
Dim PTTStr As String
With MSComm1
On Error Resume Next
.InputLen = 0
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PTT,LR" + XorchecksumPTT(Chr(ChecksumPTT))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PTTDataStr = PTTDataStr & MSComm1.Input
If QuitStatus = True Then
Unload fmPumpStatus
Exit Function
End If

For Each frm In Forms
If frm.Name = "fmPumpStatus" Then
If frm.Visible = False Then
QuitStatus = True
Unload fmPumpStatus
Exit Function
End If
End If
Next
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PTT"
LblChartsAvailable.Caption = "FAILED"
Screen.MousePointer = vbDefault
Exit Function
End If
Loop Until InStr(PTTDataStr, "LR") Or RS232COUNTER > 25000
.PortOpen = False
.InBufferCount = 0
End With
PTTDataStart = InStr(PTTDataStr, ",")
PTTDataEnd = InStrRev(PTTDataStr, ",")
LblTotalTimeRemaining.Caption = Mid$(PTTDataStr, PTTDataStart + 4, PTTDataEnd - (PTTDataStart + 4))
GetPSR
End Function

Public Function XorchecksumPTT(Buffer As String) As String
Buffer = Chr$(&HAA) + Chr$(&H1) + "X,PTT,LR"
Dim PTRSerial As Integer
Dim ChecksumPTT As Byte
For PTTSerial = 1 To Len(Buffer)
ChecksumPTT = ChecksumPTT Xor (Asc(Mid$(Buffer, PTTSerial, 1)))
Next PTTSerial
XorchecksumPTT = Chr$(ChecksumPTT)
End Function

Public Sub CmdStartStatus_Click()
StartScan = True
GetPSR
End Sub

Public Sub CmdStatusClose_Click()
StartScan = False
QuitStatus = True
Unload Me
fmMain.Show
End Sub

Private Sub Form_Load()
If QuitStatus = True Then
Unload Me
Exit Sub
End If
With MSComm1
If .PortOpen Then
.PortOpen = False
End If
End With
fmPumpStatus.Show

End Sub

Public Function XorchecksumSBD(Buffer As String) As String
Buffer = Chr$(&HAA) + Chr$(&H1) + "X,SBD,LR"
Dim SBDSerial As Integer
Dim ChecksumSBD As Byte
For SBDSerial = 1 To Len(Buffer)
ChecksumSBD = ChecksumSBD Xor (Asc(Mid$(Buffer, SBDSerial, 1)))
Next SBDSerial
XorchecksumSBD = Chr$(ChecksumSBD)
End Function

Private Sub IsStatusVisible()
Dim frm As Form
For Each frm In Forms
If frm.Name = "fmPumpStatus" Then
If frm.Visible = False Then
Unload Me
End If
Exit For
End If
Next
If QuitStatus = True Then
Unload Me
End If
End Sub

 
Have you stepped through your code in the debug? I know you said it isn't doing it in the debugger, but it is always best to step through and watch what is happening. You may end up finding something that is indeed wrong that way.

If that does't work, we code in either messageboxes or write into a log file steps along the way in the code (essenitially doing the same and accomplishing it in the exe). We have done this many times when it comes to com ports, because timing is always different when an exe vs. in development.

Hope you have some luck.

Creator of - Movie Reviews, Movie Lists, and much more!
 
Going through your code in debug mode is completely different to running it as an EXE, for starters it runs at a fraction of the speed and that's a crucial difference when dealing with ports that might have timeouts that fire long before you reach them in debug mode as opposed to firing long after you've done something else in runtime mode.

Instead of using your RS232COUNTER to go round a loop a fixed number of times (the speed of which, you must bear in mind, will differ depending on the processor speed), try using a 'timed' approach instead, for example:

Code:
T# = Timer + 5   ' 5 seconds into the future
Do While (Timer < T#)

Loop

This loop will keep trying to do something for five seconds instead of 25,000 times like your loop is at present.




- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
barryna, AndyGroom

I stumbled on adding a delay inbetween each comm output, and that seems to have solved the problem. I'm playing now with trying to find out what the threshhold is so I can have it as fast as possible, without crashing. I still don't know why it just terminates the entire probram - pretty scarry.

norason
 
Also, depending on the type of output you are receiving from the com port, you can also write a loop that watches the inbuffersize. When it stops growing, you can continue on and pull the data. We do that all over and it works well with different speeds of computers, and helps the program run the fastest.

Creator of - Movie Reviews, Movie Lists, and much more!
 
I'm trying to add comm error traps, but when I run this, it immediately jumps to errorhandler, reports event 892, and skips all the comm events. So I still don't know what is causing the error. If I use On Error Resume Next, it runs for about 2 hours, then stops.

norason



Public Function GetPSR()
If QuitStatus = True Then
Exit Function
End If
Dim PSRStr As String
With MSComm1
'On Error Resume Next
On Error GoTo ErrorHandler
.InBufferSize = 1024
.CommPort = PMP_COMM_PORT + 1
'.CommPort = 1
.Settings = "57600,n,8,1"
.RThreshold = 1
.SThreshold = 1
.InputLen = 20
.InputMode = 0
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PSR,LR" + XorchecksumPSR(Chr(ChecksumPSR))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSRDataStr = PSRDataStr & MSComm1.Input
PSRDataStrLen = Len(PSRDataStr)
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PSR"
Exit Function
End If
Loop Until InStr(PSRDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
PSRDataStart = InStr(PSRDataStr, ",")
PSRDataEnd = InStrRev(PSRDataStr, ",")
LblPrimeStep.Caption = Mid$(PSRDataStr, PSRDataStart + 4, PSRDataEnd - (PSRDataStart + 4))
If QuitStatus = True Then
Exit Function
End If
Dim PPStr As String
On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PP,LR" + XorchecksumPP(Chr(ChecksumPP))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PPDataStr = PPDataStr & MSComm1.Input
PPDataStrLen = Len(PPDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PP"
Exit Function
End If
Loop Until InStr(PPDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
PPDataStart = InStr(PPDataStr, ",")
PPDataEnd = InStrRev(PPDataStr, ",")
LblPumpPressure.Caption = (Mid$(PPDataStr, PPDataStart + 3, PPDataEnd - (PPDataStart + 3)))
If QuitStatus = True Then
Exit Function
End If
Dim PSTStr As String
On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PST,LR" + XorchecksumPST(Chr(ChecksumPST))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSTDataStr = PSTDataStr & MSComm1.Input
PSTDataStrLen = Len(PSTDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PST"
Exit Function
End If
Loop Until InStr(PSTDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
PSTDataStart = InStr(PSTDataStr, ",")
PSTDataEnd = InStrRev(PSTDataStr, ",")
LblStepTimeRemaning.Caption = Mid$(PSTDataStr, PSTDataStart + 4, PSTDataEnd - (PSTDataStart + 4))
If QuitStatus = True Then
Exit Function
End If
Dim PTTStr As String
On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PTT,LR" + XorchecksumPTT(Chr(ChecksumPTT))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PTTDataStr = PTTDataStr & MSComm1.Input
PTTDataStrLen = Len(PTTDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PTT"
Exit Function
End If
Loop Until InStr(PTTDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
End With
PTTDataStart = InStr(PTTDataStr, ",")
PTTDataEnd = InStrRev(PTTDataStr, ",")
LblTotalTimeRemaining.Caption = Mid$(PTTDataStr, PTTDataStart + 4, PTTDataEnd - (PTTDataStart + 4))
GetTheData
ErrorHandler:
MsgBox MSComm1.CommEvent

Select Case MSComm1.CommEvent
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
MsgBox "RLSD Timeout"
Case comEventCTSTO ' CTS Timeout.
MsgBox "CTS Timeout"
Case comEventDSRTO ' DSR Timeout.
MsgBox "DSR Timeout"
Case comEventFrame ' Framing Error.
MsgBox "Framing Error"
Case comEventOverrun ' Data Lost.
MsgBox "Data Lost"
Case comEventRxOver ' Receive buffer overflow.
MsgBox "Receive buffer overflow"
Case comEventRxParity ' Parity Error.
MsgBox "Parity Error"
Case comEventTxFull ' Transmit buffer full.
MsgBox "Transmit buffer full"
Case comEventDCB ' Unexpected error retrieving DCB]
MsgBox "Unexpected error retreiving DCB"
' Events
Case comEvCD ' Change in the CD line.
MsgBox "Change in CD line"
Case comEvCTS ' Change in the CTS line.
MsgBox "Change in CTS line"
Case comEvDSR ' Change in the DSR line.
MsgBox "Change in DSR line"
Case comEvRing ' Change in the Ring Indicator.
MsgBox "Change in Ring Indicator"
Case comEvReceive ' Received RThreshold # of chars.
MsgBox "Received Threshold # of Chars."
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
MsgBox "Transmit Butter Error"
Case comEvEOF ' An EOF character was found in the
' input stream.
MsgBox "EOF in input stream"
End Select
MsgBox "An error has occured"
With MSComm1
.PortOpen = False
End With
End Function
 
Are you able to tell us definitively which line causes the error, and what the error message is?

If you're not sure which line is causing the error, add line numbers to each line of code and then in your error handling code show a message box showing Erl (this will be the line that caused the error).

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 

About your error handlers.....
Code:
Public Function GetPSR()
[blue]On Error GoTo ErrorHandler[/blue]

...

GetTheData
[red]Exit Function[/red]
[blue]ErrorHandler:[/blue]
MsgBox MSComm1.CommEvent

[blue]End Function[/blue]
You have to have [tt]Exit Function[/tt] before [tt]ErrorHandler:[/tt] label, otherwise you will always go into the logic of your error handler.

Have fun.

---- Andy
 
thanks, I made the mods and started another check - we'll see what happens after about 2 hours.

norason
 
I got the error handler to work. After I run the program for about 2 hours, constantly sending and receiving data, it crashes with:
comEvReceive.

The input buffer shows exactly the data it should, and it is not too long.

I've tried constantly opening and closing the comm port after the four conversations take place, and that seems to blow up faster.

I read a thread that said if you are communicating faster than 9600 (we're at 57600) without flow control, you're just asking for problems.

We can't add flow control to this project - am I pounding my head against a problem I can't fix?

norason
 
I think you might be confusing things slightly. comEvReceive isn't an error, so your program is crashing but it's not returning comEvReceive as the error.

Instead of saying MsgBox MSComm1.CommEvent in your error handler, put something that will explain the error such as MsgBox Error$(Err).

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
I used the Error$(Err) and after about 20 minutes I got:

Automation Error
The object involved has disconnected from its clients.

norason
 
Bingo!

OK so when you get that error, just reset your connection and use Resume to carry on from where it left off.

Eg:

Code:
ErrorHandler:
If (Err = 12345) Then sub_Reconnect
Resume

Write a Sub to reset your connection and reconnect, and change 12345 to the actual error number that occurs when you get the error.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
I put this in hoping that it would re-start no matter what the error was. But I got a msgbox:

Runtime Error #13
Type mismatch

and then it terminated when I said OK.

norason

ErrorHandler:
If Error$(Err) Then
With MSComm1
If .PortOpen Then
.PortOpen = False
End If
End With
End If
Reconnect
Resume
End Function
 
I think the Type Mismatch error must be occuring in your Reconnect subroutine. You could also simplify your error handling code if you want to reconnect on any error:

Code:
ErrorHandler:
Reconnect
Resume

I would definitely put MSComm1.PortOpen = False in the Reconnect subroutine because if for some reason it causes an error your program will get stuck in an endless loop of errors. You can then also add more error handling in Reconnect to see why you're getting Type Mismatch.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
In debug mode, when this runs for about 30 minutes, I get an Error 28 - Stack Overflow, but it keeps running. When it runs in .exe mode, it just quits the program after about 22 minutes. What do I need to do to eliminate the stack overflow?
GetTheData just calls GetPSR and also looks to see if the STOP button was pressed so I can stop processing.

Public Function GetPSR()
If QuitStatus = True Then
Exit Function
End If
With MSComm1
Sleep 250 'waits
On Error GoTo ErrorHandler
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PSR,LR" + XorchecksumPSR(Chr(ChecksumPSR))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSRDataStr = PSRDataStr & MSComm1.Input
PSRDataStrLen = Len(PSRDataStr)
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PSR"
Exit Function
End If
Loop Until InStr(PSRDataStr, "LR") Or RS232COUNTER > 25000 'Or QuitStatus
.InBufferCount = 0
PSRDataStart = InStr(PSRDataStr, ",")
PSRDataEnd = InStrRev(PSRDataStr, ",")
LblPrimeStep.Caption = Mid$(PSRDataStr, PSRDataStart + 4, PSRDataEnd - (PSRDataStart + 4))
If QuitStatus = True Then
Exit Function
End If


Public Sub CmdStatusStopClose_Click()
StartScan = False
QuitStatus = True
' MsgBox "unload click"
With MSComm1
If .PortOpen = True Then
.PortOpen = False
End If
End With
' Unload fmPumpStatus
'fmMainBP5.Show
CmdExit.Enabled = True
End Sub

On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PP,LR" + XorchecksumPP(Chr(ChecksumPP))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PPDataStr = PPDataStr & MSComm1.Input
PPDataStrLen = Len(PPDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PP"
Exit Function
End If
Loop Until InStr(PPDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
PPDataStart = InStr(PPDataStr, ",")
PPDataEnd = InStrRev(PPDataStr, ",")
LblPumpPressure.Caption = (Mid$(PPDataStr, PPDataStart + 3, PPDataEnd - (PPDataStart + 3)))
If QuitStatus = True Then
Exit Function
End If
On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PST,LR" + XorchecksumPST(Chr(ChecksumPST))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PSTDataStr = PSTDataStr & MSComm1.Input
PSTDataStrLen = Len(PSTDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PST"
Exit Function
End If
Loop Until InStr(PSTDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
PSTDataStart = InStr(PSTDataStr, ",")
PSTDataEnd = InStrRev(PSTDataStr, ",")
LblStepTimeRemaning.Caption = Mid$(PSTDataStr, PSTDataStart + 4, PSTDataEnd - (PSTDataStart + 4))
If QuitStatus = True Then
Exit Function
End If
On Error GoTo ErrorHandler
Sleep 250 'waits
.Output = Chr$(&HAA) + Chr$(&H1) + "X,PTT,LR" + XorchecksumPTT(Chr(ChecksumPTT))
RS232loop = 0
Do
DoEvents
RS232loop = RS232loop + 1
PTTDataStr = PTTDataStr & MSComm1.Input
PTTDataStrLen = Len(PTTDataStr)
If QuitStatus = True Then
Exit Function
End If
If RS232loop > 25000 Then
MsgBox "COMM ERROR - ABORT", vbExclamation, "PTT"
Exit Function
End If
Loop Until InStr(PTTDataStr, "LR") Or RS232COUNTER > 25000
.InBufferCount = 0
End With
PTTDataStart = InStr(PTTDataStr, ",")
PTTDataEnd = InStrRev(PTTDataStr, ",")
LblTotalTimeRemaining.Caption = Mid$(PTTDataStr, PTTDataStart + 4, PTTDataEnd - (PTTDataStart + 4))
GetTheData
Exit Function
ErrorHandler:
If Err <> 0 Then
With MSComm1
If .PortOpen Then
.PortOpen = False
End If
End With
Err.Clear
Reconnect
Resume
StartScan = False
fmStatus.Hide
fmMain.Show
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top