Solved

delays with mscomm

Posted on 2003-12-12
4
446 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now