Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

MSComm OCX - buffering

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
Malek103197
Asked:
Malek103197
1 Solution
 
mujahid_ikramCommented:
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
 
Malek103197Author Commented:
Thanks, I'll try it and get back to you on the results. Might be a few days before I respond.

Cheers
0
 
JSMCMCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Malek103197Author Commented:
Are you familiar with the VBTerm sample program?

0
 
Malek103197Author Commented:
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
 
Malek103197Author Commented:
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
 
Malek103197Author Commented:
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
 
Malek103197Author Commented:
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
 
CleanupPingCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now