Attribute VB_Name = "Comunication"
Option Explicit
Public Const Comma As String = ","
Public Const Asterisk As String = "*"   'string termination
Declare Function timeGetTime& Lib "WINMM.DLL" ()

Public Function RX1()
Dim Timeout As Label
Dim A, B As String
Dim START As Integer
A = ""
START = 0
If frmMARSPortTestGui.MARSSerComm.PortOpen = True Then
frmMARSPortTestGui.MARSSerComm.InputLen = 1
    Wait 40
    On Error GoTo Timeout
    Do While START < 6  '6 data items, exit loop once all have been parsed
        B = Chr(Asc(frmMARSPortTestGui.MARSSerComm.Input))  ' get the characters
        If (B = Asterisk) Then  '* is the last character in the string find it
            A = A + B           'add * to string
            If START = 5 Then   'the string is complete
                RX1 = Left(A, Len(A) - 1) 'send the string
            End If
            START = 6           'reset the item count
            A = ""              'clear the buffer
        End If
        If (B = Comma) Then     'get chars till a , then ^ item count
            START = START + 1
            A = A + B           'add comma to string
        Else
            A = A + B           'build string
        End If
    Loop
End If
Exit Function
Timeout:
    RX1 = "?"
    frmMARSPortTestGui.MARSSerComm.PortOpen = False
    frmMARSPortTestGui.MARSSerComm.PortOpen = True
End Function
Public Function RX2()
Dim Timeout As Label
Dim A, B As String
Dim START As Integer
A = ""
START = 0
If frmMARSPortTestGui.MARSSerComm.PortOpen = True Then
    frmMARSPortTestGui.MARSSerComm.InputLen = 1
        Wait 40
        On Error GoTo Timeout
        Do While B <> Asterisk  'parse till asterisk found
            B = Chr(Asc(frmMARSPortTestGui.MARSSerComm.Input))  ' get the characters
            A = A + B           'add * to string
        Loop
    RX2 = Left(A, Len(A)) 'send the string
End If
Exit Function
Timeout:
    RX2 = "?"
    frmMARSPortTestGui.MARSSerComm.PortOpen = False
    frmMARSPortTestGui.MARSSerComm.PortOpen = True
End Function
Public Sub Wait(Timeout As Single)
    Dim WaitTime As Long
    WaitTime = Int(Timeout) + timeGetTime()
    Do Until timeGetTime() >= WaitTime
    Loop
End Sub
Public Sub LogData(filePath As String, logString As String)
'On Error GoTo FileError
Open filePath For Append As #1
        Print #1, logString
        Close #1
Exit Sub
FileError:
End Sub
