Thank you Chuck. Exactly what I was looking for. However this has brought
up a different issue.
Here is the code I created based on the example you gave. However I get an
exception error whenever the remote port responds with text:
"InvalidOperationException was unhandled", Cross-thread operation not valid:
Control 'txtOutput' accessed from a thread other than the thread it was
created on.
Code:
--------------------------------
Imports System.IO.Ports
Public Class Form1
Dim WithEvents mySerialPort As SerialPort = New
System.IO.Ports.SerialPort
Private Sub btnOpenPort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOpenPort.Click
With mySerialPort
.PortName = "COM" & txtPortNum.Text
.BaudRate = 57600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
mySerialPort.Open()
End Sub
Private Sub btnSendText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSendText.Click
mySerialPort.Write(txtSendText.Text)
End Sub
Private Sub btnClosePort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClosePort.Click
mySerialPort.Close()
End Sub
Private Sub mySerialPort_DataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles mySerialPort.DataReceived
txtOutput.Text = txtOutput.Text + mySerialPort.ReadExisting()
'Console.Write(mySerialPort.ReadExisting())
End Sub
End Class
--------------------------------
After reading the help about this specific error I am not sure I understand
why mySerialPort is running on another thread since it is part of my form
class.
Any ideas?
Ben Kim
"Chuck Gantz" <cgantz2000@yahoo.com> wrote in message
news:dDTvf.386$sa4.134@trnddc07...[color=blue]
> See
>
http://msdn.microsoft.com/vbasic/def...cyhardware.asp
>
>
> "Ben Kim" <bkim@NOSPAMemergitech.com> wrote in message
> news:egp2OVuEGHA.3608@TK2MSFTNGP10.phx.gbl...[color=green]
>> Hello all,
>>
>> Does anyone have an example on how to implement the new SerialPort Class
>> in VB.NET? I have been able to create the class, send (.WriteLine) to
>> the port and Read from the port but cannot figure out how to use the
>> Events to tell my program that data is available in the serial port
>> buffer.
>>
>> I have searched the internet and MSDN and there doesn't appear to be any
>> full example on how to do this simple task.
>>
>> Any help would be greatly appreciated!
>>
>> Ben Kim
>>[/color]
>
>[/color]