Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mscomm.input losing data

Status
Not open for further replies.

PatrickIRL

Programmer
Jun 25, 2003
383
Hi all, I've been using the mscomm1 control in an application to interface with a scales. However there seems to be an anomoly.

In my code, in the OnComm event, I'm parsing the string in a function as follows:

Code:
Private Sub cmdRead_Click()
    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
    End If
    '''''''''''''''''''''''''''''''''
    With MSComm1
        If .PortOpen = False Then
            .CommPort = 1
            .Settings = "9600,n,8,1"
            .RThreshold = 1
            .PortOpen = True
        End If
    End With
End Sub

The OnComm event is as follows:
Code:
    Dim sBuffer
    Dim sData           As String
    '''''''''''''''''''''''''''''''''
    sBuffer = sBuffer & MSComm1.Input
    '''''''''''''''''''''''''''''''''
    sData = ParseInput(sBuffer)
    '''''''''''''''''''''''''''''''''

The ParseInput function should return the string in the proper format.

However sometimes the data in mscomm1.Input is missing, sometimes I get only 10 to 20 characters, I'm expecting over 3000. Any ideas what would cause this??? It's intermittent but unless I can get it working the whole project is kindof held up.

Thanks in advance, Patrick
 
Have a look at the InBufferCount and InBufferSize properties. The OnComm event is raised as soon as data is placed in the input buffer but it may be before all the data has been transmitted. Set the InBufferSize property to the maximum size that your data may need and monitor the InBufferCount property until there's the amount of data in the input buffer that you're expecting.

Alternatively, you may start a timer the first time OnComm is raised and then wait for some reasonable amount of time (say a quarter of a second) to be sure that the buffer has been filled before unloading it with MSComm1.Input.
 
Cool, will try that, thanks for your help,

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top