Link to home
Start Free TrialLog in
Avatar of VB_newer
VB_newer

asked on

Something wrong with receiving and displaying hex format data by using MsComm

The following program is basic communication between PC and MCU by using MsComm. I send a "hex 35" to MCU, then MCU will return 22 bytes hex one time . I have already tested my MCU(8031) programe by LookRS232(serial com debuger). It's OK.
The question is the following program has sent "hex 35" successfully, but it can not display all 22 bytes in the Text1.Text . Only the first byte display in that.  How can I do?  Thank you in advance!


Private Sub Command2_Click()
   ' Buffer to hold input string
   Dim Instring As String
   Dim Buffer1 As String
   ' Use COM1.
   MSComm1.CommPort = 1
   ' 600 baud, no parity, 8 data, and 1 stop bit.
   MSComm1.Settings = "600,N,8,1"
   ' Tell the control to read entire buffer when Input
   ' is used.
   MSComm1.InBufferCount = 0 ' Clear Input Buffer
   MSComm1.InputLen = 0
   MSComm1.InBufferSize = 1024
   ' Open the port.
   MSComm1.PortOpen = True
   ' Send the attention command to the modem.
   MSComm1.Output = Chr$(&H35) ' Ensure that
   ' the modem responds with "OK".
   ' Wait for data to come back to the serial port.

   Do While MSComm1.InBufferCount <> 0
       DoEvents
        Buffer1 = Buffer1 + MSComm1.Input
         Text1.Text = Text1.Text & (Hex(Asc(Buffer1)))
   Loop


   ' Read the "OK" response data in the serial port.
   ' Close the serial port.
   MSComm1.PortOpen = False
   

End Sub
ASKER CERTIFIED SOLUTION
Avatar of fantasy1001
fantasy1001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial