I have a program in Access that uses VBA to capture data being sent over the serial port from a Cosmo Flow Test Machine. This determines the air pressure's leak rate escaping from a muffler.
I have written several programs that send data out serially, but I am new to "listening" to receive the data.
I can setup an instance of HyperTerminal, provided the settings used in the given manual for the device and successfully retreive data results. When using the same settings in my VBA code, I never get any data; none. The data coming from HyperTerminal seems to be 'stream' based rather than packet, thus I used the code to keep adding the characters to the end until it finishes the loop.
Here's the code:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdHHP_Click()
- Dim strLeakRate As String
- Dim strUprLmt As String
- Dim strLwrLmt As String
- Dim strChar As String
- strUprLmt = 3.77
- strLwrLmt = 0
- lblStatus.Caption = "RETREIVING LEAK TEST DATA"
- MSComm0.CommPort = 1
- MSComm0.Settings = "1200,N,8,1"
- MSComm0.PortOpen = True
- Do Until strChar = ":"
- strChar = MSComm0.Input
- strLeakRate = strLeakRate & MSComm0.Input
- Loop
- MSComm0.PortOpen = False
- lblStatus.Caption = "DATA RETREIVED"
- strLeakRate = Mid(strLeakRate, 6, 11)
- lblLeakRate.Caption = strLeakRate
- If strLeakRate > strUprLmt Then
- cmdFailed
- Exit Sub
- Else
- DoCmd.RunMacro "macHHP"
- End If
- lblStatus.Caption = "PRINTING LABEL"
- '''''''''''
- cmdReset
- '''''''''''
- End Sub
- Public Sub cmdFailed()
- MsgBox "Test Failed. Please try the leak test at most 3 times for any one DPF.", vbCritical + vbOKOnly, "LEAK TEST FAILED"
- End Sub
- Public Sub cmdReset()
- strChar = ""
- strLeakRate = ""
- lblLeakRate.Caption = "-----"
- lblStatus.Caption = "READY"
- End Sub
Another concern is that it doesn't seem like the port is actually ever opening. The code currently hangs in the loop waiting to receive the ":" char to denote the end of the string. I manually break the code and debug, then go back to the form to try again and I DO NOT receive a 'port already open' error as would be expected.
One last question... The manual claims that the end of the string is denoted by carriage return, <CR>. It lists what I would think to be the hexadecimal code for that as (0DH). How would I go about using that as the delimiter to signify the end of the string?
Any info anyone could share would be most appreciated.
Thanks in advance,
dbrother.