IJALAB
10/5/2010 5:03:00 PM
I am new to VB coding, I have been asked to print the raw bytes that
comes to a serial port on to the form. i added the following four
lines and used existing RxDisplay function. The output on the form is
hex bytes. they are asking me to print ASCII/raw by tes on to the
form. I dont know how to achieve the same. please help with this
rxdisplay function itself thanks a lot.
Do While TempLong <> -1
TempLong = MyPort.ReadByte
TempStr2 = TempStr2 & CStr(TempLong)
Loop
TempStr2 = vbCrLf & vbCrLf & "Received:" & TempStr2
RxDisplay False, TempStr2
Public Sub RxDisplay(Filter As Boolean, StringToDisplay As String)
Dim StringLength As Integer
Dim CRPosition As Integer
Dim RecordPosition As Integer
Dim StrPosition As Integer
Dim CommaPassPosition As Integer
Dim LogString As String
Dim NumScroll As Long
Dim TimeWithMsec As String
Dim PerlLine As Boolean
'Perl script output lines always start with: vbcrlf & vbcrlf & "$"
PerlLine = False
If Mid(StringToDisplay, 5, 1) = "$" Then
PerlLine = True
End If
TimeWithMsec = TimeToMillisecondString
'Put time tag on first display line for received data
If Left(StringToDisplay, 2) = vbCrLf Then
If Mid(StringToDisplay, 3, 2) = vbCrLf Then
StringLength = Len(StringToDisplay)
StringToDisplay = vbCrLf & vbCrLf & "(" & TimeWithMsec & ") " &
Right(StringToDisplay, StringLength - 4)
End If
End If
'Is message logging turned on?
If LogStatus = True Then
'Write this string to the log file, but delete leading CR/LF
If Left(StringToDisplay, 2) = vbCrLf Then
StringLength = Len(StringToDisplay)
Print #LogFileNumber, Right(StringToDisplay, StringLength - 2)
Else
Print #LogFileNumber, StringToDisplay
End If
End If
'Is auto logging turned on?
If FileOpened(AutoLogFileNumber) = True Then
'Write this string to the log file, but delete leading CR/LF
If Left(StringToDisplay, 2) = vbCrLf Then
StringLength = Len(StringToDisplay)
Print #AutoLogFileNumber, Right(StringToDisplay, StringLength -
2)
Else
Print #AutoLogFileNumber, StringToDisplay
End If
End If
'Perl sciprt output goes to log (above) but not to screen
If PerlLine Then
Exit Sub
End If
'Send data to composite display
CompositeDisplay (StringToDisplay)
'Should the display be filtered?
If Filter = True Then
'Don't display the data when the calling
'routine says it should be filtered
Exit Sub
End If
'Is this a "record pass" message, seen only during download?
RecordPosition = InStr(StringToDisplay, "Record ")
If RecordPosition <> 0 Then
CommaPassPosition = InStr(StringToDisplay, ", pass")
If CommaPassPosition <> 0 Then
'This is a "record pass" message
If Right(TotalRxDisplay, 6) = ", pass" Then
'The previous message on the screen is a "record pass"
message,
'delete it before displaying the new message
StringLength = Len(StringToDisplay)
TotalRxDisplay = Left(TotalRxDisplay, (Len(TotalRxDisplay) -
StringLength))
End If
End If
End If
'Append new string to what is already in the display window
TotalRxDisplay = TotalRxDisplay & StringToDisplay
'If we have displayed more than 20000 characters,
'delete the first half of them - starting with
'the next message (carriage return)
StringLength = Len(TotalRxDisplay)
If StringLength >= 20000 Then
CRPosition = InStr(10000, TotalRxDisplay, Chr(13))
TotalRxDisplay = Right(TotalRxDisplay, (StringLength - CRPosition
- 1))
End If
'Display the new info
Form1.RxWindow.Text = TotalRxDisplay
'Scroll 1
'Set cursor to end of data so that the end
'is displayed instead of the start
'StringLength = Len(TotalRxDisplay)
'Form1.RxWindow.SelStart = StringLength
'Scroll 2
'Scroll down the display to put the newest line on the screen
NumScroll = SendMessage(Form1.RxWindow.hWnd, EM_LINESCROLL, 0,
10000)
End Sub