D
Dave Harry
I found the RS232 class from MS's 101 VB samples.
Writing to the port works fine. (I've got hyperterminal on the other comm
port and a crossover cable between COM1 and COM2)
The port is opened with:
Public switchcom As New Rs232
switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 512)
But reading is giving me no end of trouble. Since there are no com port
events anymore in dot NET, I wish to run a timer and read the entire input
buffer as a string. I found some sample code and interpreted it like this:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim j As Integer
Dim i As Integer
Dim strDataIn As String
Dim DataIn As Array
Try
j = 0
While switchcom.Read(1) <> -1
DataIn(j) = Asc(switchcom.InputStreamString.Chars(0))
j += 1
strDataIn = ""
For i = 0 To DataIn.Length - 1
strDataIn &= DataIn(i)
Next
End While
Catch
' // "Switcher buffer empty"
End Try
TextBox1.Text = strDataIn
End Sub
But I can't get anything in the port. Furthermore, when option strict is on,
the compiler complains about "late binding" on DataIn(j). I'm still pretty
new to this stuff: Should I just turn Option Strict off, or do I need to fix
something?
Any help appreciated, thanks.
Writing to the port works fine. (I've got hyperterminal on the other comm
port and a crossover cable between COM1 and COM2)
The port is opened with:
Public switchcom As New Rs232
switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 512)
But reading is giving me no end of trouble. Since there are no com port
events anymore in dot NET, I wish to run a timer and read the entire input
buffer as a string. I found some sample code and interpreted it like this:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim j As Integer
Dim i As Integer
Dim strDataIn As String
Dim DataIn As Array
Try
j = 0
While switchcom.Read(1) <> -1
DataIn(j) = Asc(switchcom.InputStreamString.Chars(0))
j += 1
strDataIn = ""
For i = 0 To DataIn.Length - 1
strDataIn &= DataIn(i)
Next
End While
Catch
' // "Switcher buffer empty"
End Try
TextBox1.Text = strDataIn
End Sub
But I can't get anything in the port. Furthermore, when option strict is on,
the compiler complains about "late binding" on DataIn(j). I'm still pretty
new to this stuff: Should I just turn Option Strict off, or do I need to fix
something?
Any help appreciated, thanks.