1、VisualStudio2005中serialPort控件访问串口实例点评:这个例子包括了这个控件几乎所有的操作,非常有参考价值.serialPort是在.netframework2.0中才有的东西,感觉这个东西和MSCOMM很相似.这里给出的例子是基于vb.net和C-SHAPE的,相应的可以在Cshape和c++中使用,基本上都是一样的.VisualStudio2005中serialPort控件访问串口实例[转载]Imports System Imports System.IO.Ports Imports System.Threading Publ
2、ic Class PortChatClass PortChat Shared _continue As Boolean Shared _serialPort As SerialPort Public Shared Sub Main()Sub Main() Dim name As String Dim message As String Dim sComparer As StringComparer = StringComparer.OrdinalIgnoreCase
3、 Dim readThread As Thread = New Thread(AddressOf Read) ' Create a new SerialPort object with default settings. _serialPort = New SerialPort() ' Allow the user to set the appropriate properties. _serialPort.PortName = SetPortName(_seria
5、StopBits) _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake) ' Set the read/write timeouts _serialPort.ReadTimeout = 500 _serialPort.WriteTimeout = 500 _serialPort.Open() _continue = True readThread.Sta
6、rt() Console.Write("Name: ") name = Console.ReadLine() Console.WriteLine("Type QUIT to exit") While (_continue) message = Console.ReadLine() If sComparer.Equals("quit", message) Then _continue = Fa
7、lse Else _serialPort.WriteLine( _ String.Format("<{0}>: {1}", name, message)) End If end while readThread.Join() _serialPort.Close() End Sub Public Shared Sub Read()Sub Read()