MSComm and parsing the input buffer 
Author Message
 MSComm and parsing the input buffer

Ok, here it goes.
I have to communicate with a device which I send Ascii values and it returns
ascii values.  I can send a recieve everything ok.  The problem is that i
cannot parse the buffer.  I worked with the MSComm1.RThreshold = 1
I assume from what i read that it triggers the receive event after every
character.  I also messed with the input buffer.
My problem is that when I receive data in the form:
233.45,99.889Asc(13)
  (I think it's ascii(13) it is a block character on the screen)
I want to send the 233.45 to one text box of a form
and the 99.889 to another text box on the same form.
I need to parse the string.  Are there any character types?  Do I need a
variable declared as a char?
When I debug the intput buffer from the comm port it lloks like this:
233.45,99.88(then some unknown ascii, a block) and on the next line,
9
Or the buffer is packed with strings!  Not just a char?
What is the deal?
hmm???
here is my code

----------------------------------------------------------------------------
--------------------

Public Sub MSComm1_OnComm()

Dim s As String
Dim OutputMode As String

' When a comm event occurs.

' Was it a "receive" event? If so, add the received character
' to the Text Box and set the insertion point at the end of
' the text. Other events are ignored.

Select Case MSComm1.CommEvent
    Case comEvReceive
        s = MSComm1.Input
        If Asc(s) = 13 Then s = vbCrLf

'setting which text ouput to send results

        ' Looking for a comma
        If Asc(s) = 44 Then OutputMode = "MeasureMode"

        ' looking for a return char
        If Asc(s) = 13 Then OutputMode = "WavelengthMode"

        Select Case OutputMode
            Case "MeasureMode"
                frmScanSpectrumMode.txtMeasureMode.Text =
frmScanSpectrumMode.txtMeasureMode.Text & s

                frmScanSpectrumMode.txtMeasureMode.SelStart =
Len(frmScanSpectrumMode.txtMeasureMode.Text)

            Case "WavelengthMode"
                frmScanSpectrumMode.txtWavelength.Text = txtJenway.Text & s

                frmScanSpectrumMode.txtWavelength.SelStart =
Len(txtJenway.Text)

        End Select

End Select

End Sub



Wed, 18 Apr 2001 03:00:00 GMT  
 MSComm and parsing the input buffer
I presume that you have the MSComm set to comInputModeText.

I would guess that when you set >         If Asc(s) = 13 Then s = vbCrLf

that this is screwing up the rest of the code.  vbCrLF is a two character
string.  And then your case statement doesn't seem to have a case "else"
for all the other characters.  Since Output mode is local, there is no way
that the output mode is known for the rest of the characters from each of
the comm events.

You probably should set the text boxes to multiline else the chr$(13) will
{*filter*}things up.  Better yet, don't print the chr$(13).

--
Mike



Quote:
> Ok, here it goes.
> I have to communicate with a device which I send Ascii values and it
returns
> ascii values.  I can send a recieve everything ok.  The problem is that i
> cannot parse the buffer.  I worked with the MSComm1.RThreshold = 1
> I assume from what i read that it triggers the receive event after every
> character.  I also messed with the input buffer.
> My problem is that when I receive data in the form:
> 233.45,99.889Asc(13)
>   (I think it's ascii(13) it is a block character on the screen)
> I want to send the 233.45 to one text box of a form
> and the 99.889 to another text box on the same form.
> I need to parse the string.  Are there any character types?  Do I need a
> variable declared as a char?
> When I debug the intput buffer from the comm port it lloks like this:
> 233.45,99.88(then some unknown ascii, a block) and on the next line,
> 9
> Or the buffer is packed with strings!  Not just a char?
> What is the deal?
> hmm???
> here is my code

----------------------------------------------------------------------------

- Show quoted text -

Quote:
> --------------------

> Public Sub MSComm1_OnComm()

> Dim s As String
> Dim OutputMode As String

> ' When a comm event occurs.

> ' Was it a "receive" event? If so, add the received character
> ' to the Text Box and set the insertion point at the end of
> ' the text. Other events are ignored.

> Select Case MSComm1.CommEvent
>     Case comEvReceive
>         s = MSComm1.Input
>         If Asc(s) = 13 Then s = vbCrLf

> 'setting which text ouput to send results

>         ' Looking for a comma
>         If Asc(s) = 44 Then OutputMode = "MeasureMode"

>         ' looking for a return char
>         If Asc(s) = 13 Then OutputMode = "WavelengthMode"

>         Select Case OutputMode
>             Case "MeasureMode"
>                 frmScanSpectrumMode.txtMeasureMode.Text =
> frmScanSpectrumMode.txtMeasureMode.Text & s

>                 frmScanSpectrumMode.txtMeasureMode.SelStart =
> Len(frmScanSpectrumMode.txtMeasureMode.Text)

>             Case "WavelengthMode"
>                 frmScanSpectrumMode.txtWavelength.Text = txtJenway.Text &
s

>                 frmScanSpectrumMode.txtWavelength.SelStart =
> Len(txtJenway.Text)

>         End Select

> End Select

> End Sub



Mon, 23 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need help reading the MSComm input buffer

2. MSComm input/output buffers

3. help on MSCOMM, do es not read from input buffer

4. Need Help on MSComm input buffer

5. MScomm, MSComm.Input

6. Parsing A Buffer of Lines

7. Parsing formatted buffer into recordset

8. mscomm buffer + delay

9. MSComm buffers

10. How To Know when MSCOMM transmit buffer empty?

11. Problem setting the MSCOMM transmit buffer size.

12. MSCOMM problem: buffer string is getting too big.

 

 
Powered by phpBB® Forum Software