?
Solved

MSComm OCX - buffering

Posted on 2003-02-23
9
Medium Priority
?
595 Views
Last Modified: 2011-09-20
I am reading data (ASCII string ) from the serial port that often gets broekn up. What I mean is this -

The sting has a start and end character to deliminate the entire string -
<sasrwaskdmswriuwriwrwer> where there is a fixed number of charcters.

However, the string often arrives in pieces. There may be <sasrwask that arrives, followed soon
after by the rest (i.e. dmswriuwriwrwer>).

I need to assemble the string back together and then bring it into my app. (VB).  I assume I need to keep the parts
in a buffer and then assemble them to make up the proper string.

Can anyone provide me with some hints on how to do this. I have examined the VBTerm sample
but not sure if it can assemble the parts of the string.

Thanks
0
Comment
Question by:Malek103197
[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
9 Comments
 

Expert Comment

by:mujahid_ikram
ID: 8006500
add an api in ur project of sleep

Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

in oncomm of communication control

Private Sub MSComm1_OnComm()
sleep (50)
' here ur code
End Sub

you will get complete data
0
 

Author Comment

by:Malek103197
ID: 8006622
Thanks, I'll try it and get back to you on the results. Might be a few days before I respond.

Cheers
0
 
LVL 2

Accepted Solution

by:
JSMCM earned 200 total points
ID: 8006867
You can also create a loop in your mscomm_oncomm event:

Private Sub MSComm1_OnComm()

 Do
 DoEvents ' allows the program to continue other processes
 Loop until MsComm1.InbufferCount >= 10 ' or whatever value you choose

 'Your Code

End Sub
0
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.

 

Author Comment

by:Malek103197
ID: 8006933
Are you familiar with the VBTerm sample program?

0
 

Author Comment

by:Malek103197
ID: 8007397
OK, I've done some tests using the VBTerm sample and here's what is happening -

I've got one instance of the VBTerm sending out text -
MSComm1.Output = ">R84999805315723040202A0308269N10141581E000198<"

On the second instance of VBTerm I've got -

In the OnComm sub there is -

Select Case MSComm1.CommEvent
        ' Event messages.
        Case comEvReceive
            Dim Buffer As Variant
            Buffer = MSComm1.Input
            Debug.Print "Receive - " & StrConv(Buffer, vbUnicode)
            ShowData txtTerm, (StrConv(Buffer, vbUnicode))


Private Static Sub ShowData(Term As Control, Data As String)

The Data variable ends up broken into parts -

">R849998"
"05315723"
"040202A0"
"308269N1"
"0141581E"
"000198<"
">R849998"
"05315723"
"040202A0"
"308269N1"
"0141581E

For testing I am saving the Data to a text file for analysis and I get the above in the text file. Is there a way to avoid re-assemling the string?
0
 

Author Comment

by:Malek103197
ID: 8007781
OK, I think I have figured out half my problem.

In the onComm Sub I now have -

Case comEvReceive
           
            Dim thePos1, thePos2 As Integer
            Buffer = Buffer & MSComm1.Input 'Buffer is declared on top of Form
            thePos1 = InStr(StrConv(Buffer, vbUnicode), ">")
            thePos2 = InStr(StrConv(Buffer, vbUnicode), "<")
            If thePos1 And thePos2 Then
              Debug.Print "Receive - " & StrConv(Buffer, vbUnicode)
              ShowData txtTerm, (StrConv(Buffer, vbUnicode))
              MSComm1.InBufferCount = 0
              Buffer = ""
            End If

So far this seem to work. Sometimes a part of the string is delayed in arriving at the comm port. Therefore, I'll need a timer as a 'Time Out" timer. If the timer exceeds the thresh hold then throw the buffor away.
0
 

Author Comment

by:Malek103197
ID: 8051343
To those who contributed: I sort of figured out my own problem once I was familiar with the VBTerm code, and so far it is working fine.

So what do I do now?I hate to leave questions hanging!
0
 

Author Comment

by:Malek103197
ID: 8051344
To those who contributed: I sort of figured out my own problem once I was familiar with the VBTerm code, and so far it is working fine.

So what do I do now?I hate to leave questions hanging!
0
 

Expert Comment

by:CleanupPing
ID: 8901234
Malek:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
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…
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
Course of the Month11 days, 2 hours left to enroll

770 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