CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2014

    Vb6 serial communication

    I am doing a project on vb6. I need to take some data from serial port and display it using a text box and label in vb6. But the problem is that the while loop does not run. It just executes every time on command click instead of changing continuously on itself. In my project the input to the serial port keeps changing continuously so how do I modify this code so that i can continuously read the input and change the display.
    Private Sub Command_Click()
    Dim sbuffer As String
    while (1)
    If MSComm1.CommEvent=comEvReceive then sbuffer=sbuffer & MSComm1.Input
    End Sub

    Private Sub Form_Load()
    End Sub

    Private Sub MSComm1_OnComm()
    With MSComm1
    If MSComm.PortOpen=True Then MSComm1.PortOpen=False
    End With
    End Sub

    Please help...

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008

    Re: Vb6 serial communication

    You should not be using a loop

    MSComm control fires an event when something happens and it is there you should place your code for reading data
    Typically you would use a select case in this event to see what the event is and take the proper action Like what you did with your if statement above

    Alternately you can use a timer and check the buffer to see if any data is there and read it if so but the event is the recommended method here.
    There should be an example in your online help and there are many on the net

    btw you also should not have the code in the on comm event that is closing and reopening the port as that would throw away anything that is received
    You should not be calling the On_Comm event from code either

    The code to open the port should go in the command click
    The code to read from the port should be in the on_comm
    On_comm fires automatically when data is received provided you have the RThreshold set properly. I think the default is 1 which would be fine
    Last edited by DataMiser; March 29th, 2014 at 01:26 AM.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.