Solved

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

Posted on 2003-10-31
4
593 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:VB_newer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
ID: 9667849
try this:
'mscomm1.inputlen = 0
loop until mscomm1.inbuffercount >= 22
text1.text = val(mscomm1.input)

thanks,
~ fantasy ~




0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question