Solved

delays with mscomm

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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