P
Pete
Hello,
Have just started using VB.Net and have been trying to work on some
updates to a very old piece of code. Currently we send messages via
the serial port in the following formate
i176.8005 <CR>
i176.800555.44 <CR>
o176.8005.222 <CR>
The <CR> showing the end of a message arriving on the comm port. For
some reason the handle input routine that I've written recognises
every other character and outputs it correctly to the text box I'm
using. But always seems to fail when it comes to the <CR> character.
Displaying a weird box instead.
I've tried several different ways of looking at the data and have cut
and pasted the text outputted into notepad where the weird black boxes
remain, but then in MSWord it happily starts a newline.
Not at all sure where I'm going wrong. Am I using the wrong comparison
to detect the <CR>? It never seems to make it into this part of the if
statement. All other characters are being displayed fine but this
isn't!
Hope someone can help?
Pete
Private Sub SUComm1_OnComm(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SUComm1.OnComm
Static SUBuff As String
Dim NewChar As Char
SUBuff = SUComm1.Input()
Call HandleInput(SUBuff)
End Sub
Sub HandleInput(ByVal SUBuff As String)
' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the TextBox.
Dim BufferSize, Counter As Integer
Dim NextChar, Buffer As String
Dim ENQInt, ETXInt, STXInt, ACKInt, CRInt As Integer
Dim ENQStr, STXStr, ACKStr, ETXStr, CRStr As String
Dim CommStr, IDStr, ProStr, ValStr As String
STXStr = Chr(2)
ETXStr = Chr(3)
ENQStr = Chr(5)
ACKStr = Chr(6)
CRStr = Chr(13)
CommStr = Chr(111)
IDStr = Chr(105)
ProStr = Chr(112)
ValStr = Chr(118)
Buffer = SUBuff
If Buffer = ENQStr Then
'ENQ Received from SU send ENQ back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "5" + Chr(13) + Chr(10)
SUComm1.Output() = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "2" + Chr(13) + Chr(10)
SUComm1.Output() = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Buffer
Else
'output asc value to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer))
End If
End If
End Sub
Have just started using VB.Net and have been trying to work on some
updates to a very old piece of code. Currently we send messages via
the serial port in the following formate
i176.8005 <CR>
i176.800555.44 <CR>
o176.8005.222 <CR>
The <CR> showing the end of a message arriving on the comm port. For
some reason the handle input routine that I've written recognises
every other character and outputs it correctly to the text box I'm
using. But always seems to fail when it comes to the <CR> character.
Displaying a weird box instead.
I've tried several different ways of looking at the data and have cut
and pasted the text outputted into notepad where the weird black boxes
remain, but then in MSWord it happily starts a newline.
Not at all sure where I'm going wrong. Am I using the wrong comparison
to detect the <CR>? It never seems to make it into this part of the if
statement. All other characters are being displayed fine but this
isn't!
Hope someone can help?
Pete
Private Sub SUComm1_OnComm(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SUComm1.OnComm
Static SUBuff As String
Dim NewChar As Char
SUBuff = SUComm1.Input()
Call HandleInput(SUBuff)
End Sub
Sub HandleInput(ByVal SUBuff As String)
' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the TextBox.
Dim BufferSize, Counter As Integer
Dim NextChar, Buffer As String
Dim ENQInt, ETXInt, STXInt, ACKInt, CRInt As Integer
Dim ENQStr, STXStr, ACKStr, ETXStr, CRStr As String
Dim CommStr, IDStr, ProStr, ValStr As String
STXStr = Chr(2)
ETXStr = Chr(3)
ENQStr = Chr(5)
ACKStr = Chr(6)
CRStr = Chr(13)
CommStr = Chr(111)
IDStr = Chr(105)
ProStr = Chr(112)
ValStr = Chr(118)
Buffer = SUBuff
If Buffer = ENQStr Then
'ENQ Received from SU send ENQ back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "5" + Chr(13) + Chr(10)
SUComm1.Output() = ENQStr
ElseIf Buffer = ETXStr Then
'ETX Received from SU send STX back. Not waiting for CR.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer)) + Chr(13) +
Chr(10)
PCOutput.SelectionStart = Len(PCOutput.Text)
PCOutput.SelectedText = "2" + Chr(13) + Chr(10)
SUComm1.Output() = STXStr
ElseIf Buffer = CRStr Then
'CR Received from SU output to screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Chr(13) + Chr(10)
Else
If Asc(Buffer) > 32 Then
'Output buffer to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Buffer
Else
'output asc value to the screen.
SUOutput.SelectionStart = Len(SUOutput.Text)
SUOutput.SelectedText = Str(Asc(Buffer))
End If
End If
End Sub