
Function TComm_Read(Opcode As Integer, ByRef Response As Integer) As String

  Dim Timeout As Integer
  Dim InpVal As Integer
  Dim InpByt() As Byte

  'Set the DTR and RTS lines to select test box processor
  MSComm.DTREnable = False
  MSComm.RTSEnable = False
  Sleep (5)

  'Purge all existing port input
  MSComm.InputLen = 1      'char at a time on input
  MSComm.InputMode = comInputModeBinary 'read as binary data
  
  MSComm.InBufferCount = 0  'Flush the input buffer
  
  'Assemble and output the two character READ function
  MSComm.Output = Chr$(27) + Chr$(Opcode)
  
  'Poll for the single byte reply from the remote end
  Timeout = 100             '100 msec total timeout
  While Timeout > 0
    Sleep (1)
    If MSComm.InBufferCount >= 1 Then
      InpByt = MSComm.Input
      InpVal = InpByt(0)
      TComm_Read = ""
      Response = InpVal
      Exit Function
    End If
    Timeout = Timeout - 1
  Wend
  
  TComm_Read = "Read Function Timeout"
  
End Function
