Hi there. I made a program that reads data from a device through a serial port which then displays it in a textbox. As the data comes out in ASCII form, I have to filter out the unnecessary parts for it to be useful. Example is shown below.
:8+3423,
to
3423
I have managed to to find the necessary code to perform this filtering. But when used in the program I made I get an error that says "NullReferenceE xception was unhandled" and that "Object reference not set to an instance of an object". It then suggest that I use the "new" keyword to create an object instance. The codes I use for the filtering is:
steps = output_data.Sub string(4)
steps = steps.Substring (0, steps.Length - 2)
I use these as since the position of the ASCII is fixed.
Please advice
Codes for program are as shown below:
[code=vbnet]
Public Class Form1
Dim s As String
Dim output_data As String
Dim steps As String
Dim colon8 As String = "Chr(4) & Chr(49) & Chr(49) & Chr(58) & Chr(56) & Chr(5)"
'code in hex is 04 31 31 3A 38 05
'code in ASCII is 11:8
Private Sub Activate_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Activate.Click
COMPort1.Open()
End Sub
Private Sub Deactivate_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Deactivate.Clic k
COMPort1.Close( )
End Sub
Private Sub COMPort1_DataRe ceived(ByVal sender As System.Object, ByVal e As System.IO.Ports .SerialDataRece ivedEventArgs) Handles COMPort1.DataRe ceived
output_data &= COMPort1.ReadEx isting
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
COMPort1.Write( Chr(4) & Chr(49) & Chr(49) & Chr(58) & Chr(56) & Chr(5))
steps = output_data.Sub string(4)
steps = steps.Substring (0, steps.Length - 2)
TextBox1.Text() = steps
steps = ""
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
End Sub
End Class
[/code]
:8+3423,
to
3423
I have managed to to find the necessary code to perform this filtering. But when used in the program I made I get an error that says "NullReferenceE xception was unhandled" and that "Object reference not set to an instance of an object". It then suggest that I use the "new" keyword to create an object instance. The codes I use for the filtering is:
steps = output_data.Sub string(4)
steps = steps.Substring (0, steps.Length - 2)
I use these as since the position of the ASCII is fixed.
Please advice
Codes for program are as shown below:
[code=vbnet]
Public Class Form1
Dim s As String
Dim output_data As String
Dim steps As String
Dim colon8 As String = "Chr(4) & Chr(49) & Chr(49) & Chr(58) & Chr(56) & Chr(5)"
'code in hex is 04 31 31 3A 38 05
'code in ASCII is 11:8
Private Sub Activate_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Activate.Click
COMPort1.Open()
End Sub
Private Sub Deactivate_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Deactivate.Clic k
COMPort1.Close( )
End Sub
Private Sub COMPort1_DataRe ceived(ByVal sender As System.Object, ByVal e As System.IO.Ports .SerialDataRece ivedEventArgs) Handles COMPort1.DataRe ceived
output_data &= COMPort1.ReadEx isting
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
COMPort1.Write( Chr(4) & Chr(49) & Chr(49) & Chr(58) & Chr(56) & Chr(5))
steps = output_data.Sub string(4)
steps = steps.Substring (0, steps.Length - 2)
TextBox1.Text() = steps
steps = ""
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
End Sub
End Class
[/code]
Comment