Visual Basic: MSComm Control

InputMode Property Example

This example reads 10 bytes of binary data from the communications port and assigns it to a byte array.

  Private Sub Command1_Click()
Dim Buffer as Variant
Dim Arr() as Byte

' Set and open port
MSComm1.CommPort = 1
MSComm1.PortOpen = True

' Set InputMode to read binary data
MSComm1.InputMode = comInputModeBinary

' Wait until 10 bytes are in the input buffer
Do Until MSComm1.InBufferCount < 10
  DoEvents
Loop

' Assign to byte array for processing
Arr = MSComm1.Input

End Sub