Simple Example of How to Implement SerialPort Class. Visual Basic.NET Forums on Bytes. My program that data is available in the serial port buffer. Delegate that enables asynchronous calls to the window control in this case txtOutput.
P: n/a
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' <cg********@yahoo.com> wrote in message news:dDTvf.386$sa4.134@trnddc07...
See http://msdn.microsoft.com/vbasic/def...cyhardware.asp 'Ben Kim' <bk**@NOSPAMemergitech.com> wrote in message news:eg**************@TK2MSFTNGP10.phx.gbl...
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
Serial port controls for WPF
The aim of this project is to provide re usable gui elements that are often needed when working with serial ports, either physical ones or usb converters.
Serial Port Selection Combo Box
The serial port selection cmobo box lists all available serial ports and lets you choose one. There is also a refresh button that is often required when working with USB to serial adapters that are plugged in and out during the run time of the application.
Baud Rate Selection Combo Box
The baud rate selection combo box lists standard baud rates for the user to choose the required one. It is also possible to add or remove available selections during runtime.
Serial Port Control
The serial port control lets the user choose all relevant settings to open a serial port, and it includes the refresh button from the serial port selection combo box.