Question on MSCOMM

Posted on 2005-04-06
Last Modified: 2013-12-26
I am using mscomm to receive a string of data via rs232 port using mscomm.

I can view the string using multi-line text box. I need split the string into fixed length characters and insert them into a list box. I have tried EOF but does not work. I receive a rectangle shaped character at the beginning of each line, could I use this to create a loop.

Question by:MERVINOC
    LVL 14

    Expert Comment

    by:Shiju Sasidharan

    can u place the code u r using  ?
    do u know the pattern of the string u r expecting from port ?

    RThreshold Property
     Sets and returns the number of characters to receive before the MSComm control sets the CommEvent property to comEvReceive and generates the OnComm event.
    try to set  RThreshold  property to a no which u want to retireve the no of characters at a time

    here is a sample code which demonstrates basic methods;EN-US;Q262883&ID=KB;EN-US;Q262883


    LVL 3

    Accepted Solution

    My suggestion would be to look at the ASCII value of that first character (since it is unique to the beginning of each line) using the asc() function.  Once you know what character is delimiting your data stream, it is a simple matter of using the split function to force your input into an array, or you can even parse through it manually to fil your list box.

    To answer your question, yes... once you have ascertained the value of that prefix character you can easily create and process through a loop.  My guess is that the character is a simple carriage return (not a carriage return/line feed); however, using your ASC() function will reveal all.

    If you need any further help, feel free to post your code, and we will help you work it out.

    Jiggle On ! ! !
    LVL 5

    Expert Comment


    Can u try this.

    set up your port and ever thing

    Private Sub Command1_Click()

    If cmm = 0 Or setb = "" Then        'check and make sure settings are ok
        MsgBox "Please Enter Comm settings to make your connection!", 46, "Comm"
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
        Call settings_Click    'if not give'em a chance to fill it out
        Exit Sub
    End If
    On Error GoTo err
    MSComm1.CommPort = cmm          'set the settins  and comm
    MSComm1.settings = setb

    If MSComm1.PortOpen = False Then
        MSComm1.PortOpen = True
            Call waitscan             'open port and keep look for data arrival
            Call showinput              'once data arrives go to it
        Loop Until MSComm1.PortOpen = False
    End If
    err:        'error trap
        MsgBox Error$, 48
        MsgBox "Please check your comm settings", 48, "ERROR"
        Unload Form1
        Load Form1
        Exit Sub
    End Sub

    Public Sub waitscan()
    Do While MSComm1.InBufferCount = 0         'wait for the buffer to start filling
    End Sub

    Dim strdata as string

    Public Sub showinput()
    MSComm1.InputLen = 1
    strdata = MSComm1.Input
    End sub

    In  the MSComm1.InputLen put your length to as a fixed character.

    Then store it in strdata then insert the strdata in to the List box.

    Try this out. if you have anything related to this ask me

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    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…
    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…

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now