Question on MSCOMM

Posted on 2005-04-06
Medium Priority
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
ID: 13720869

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



Accepted Solution

JigglyD earned 2000 total points
ID: 13724586
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 ! ! !

Expert Comment

ID: 13750874

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

839 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