Solved

delays with mscomm

Posted on 2003-12-12
4
448 Views
Last Modified: 2010-05-01
I'm using the MSComm OCX to communicate with a robot. I send a command out and the robot sends back a response. The problem I'm having is it takes a couple seconds round trip for the VB program to receive the data. I know it's not the robots fault because I have a similar program in C++ and if I send the same data then it comes back with the results within milliseconds. I don't see any kind of priority setting on the OCX, any ideas here?
I'm using win 98 and VB6. My ReceivePacket function is modeled directly after sample code.

Here it is.
Public Sub ReceivePacket(InByte As Byte)
Static Serial_Buffer(255) As Byte
Static PacketLen As Integer
Static Index As Byte 'stores index point in comm buffer. Serial bytes
                     'are placed in Serial_Buffer[index], then [index]
                      ' is incremented.
Static begin_flag As Byte ' If begin_flag = 0 and index = 0, look for
                        ' 0x54 on serial stream.Otherwise,
                        ' place byte in Serial_Buffer[index] and wait
                        ' until PacketLen is equal to index.

Serial_Buffer(Index) = InByte
Hex$(Serial_Buffer(Index))
If begin_flag = 0 Then
    If InByte <> &H54 Then
        GoTo EndReceivePacket
    Else:
        begin_flag = 1
    End If
End If


If Index >= 2 Then
    PacketLen = (Serial_Buffer(2) + 6)
    If PacketLen > 254 Then
        Index = 0
        begin_flag = 0
        GoTo EndReceivePacket
    End If
    If Index = PacketLen Then ' process packet
        Index = 0
        begin_flag = 0
        Call Process_Packet(Serial_Buffer)
        GoTo EndReceivePacket
    End If 'end of process packet

End If

Index = Index + 1 ' get ready to receive next byte
EndReceivePacket:
End Sub

Thanks Ringo
0
Comment
Question by:ringo42
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
Sector10 earned 250 total points
ID: 9930331
Hi Ringo,

Just a tought using the MSComm1_OnComm Event:

If MSComm1.CommEvent = MSCOMM_EV_RECIEVE Then
0
 
LVL 1

Expert Comment

by:Sector10
ID: 9930387
Hi Ringo,

Pressed the submit button to quick, but here is the rest.

Just a tought using the MSComm1_OnComm Event try to print the input to a textfield by rewriting the bufferarray:

Dim temp1 AS String
Dim BufferArray() AS Byte

If MSComm1.CommEvent = MSCOMM_EV_RECIEVE Then

BufferArray = MSComm1.Input
For I = 0 To UBound(BufferArray)
    temp1 = temp1 & BufferArray(i)
Next I



Regards,

Paul
0
 
LVL 27

Expert Comment

by:planocz
ID: 10289665
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from ringo42 from 12/12/2003 comment
Award points to Sector10 is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now