Solved

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

Posted on 2003-10-31
4
582 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now