Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-10-31
4
Medium Priority
?
610 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 500 total points
ID: 9667849
try this:
'mscomm1.inputlen = 0
loop until mscomm1.inbuffercount >= 22
text1.text = val(mscomm1.input)

thanks,
~ fantasy ~




0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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