.NET v2.0: Serial Port Communications Finally Arrives

System.IO.Ports.SerialPort (derives from System.ComponentModel.Component) -- Whidbey's MSDN:

Use this class to control a serial port file resource. It provides synchronous and event-driven IO, access to pin and break states, and access to serial driver properties. In addition, its functionality can be wrapped in an internal Stream object, accessible through the BaseStream property, and passed to classes that wrap or utilize streams.

Public Constructors
      SerialPort Initializes a new instance of the SerialPort class.

Public Events
      Disposed (inherited from Component)Adds an event handler to listen to the Disposed event on the component.
      ErrorEvent Represents the method that handles the error event of a SerialPort object.
      PinChangedEvent Represents the method that will handle the serial pin changed event of a SerialPort object.
      ReceivedEvent Represents the method that will handle the serial received event of a SerialPort object.

Public Fields
      InfiniteTimeout Value indicates that no timeout should occur.

Public Methods
      Close Closes the port connection, sets System.IO.Ports.IsOpen to false and disposes of the internal Stream object.
      CreateObjRef (inherited from MarshalByRefObject)Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
      DiscardInBuffer Discards data from the serial driver's receive buffer.
      DiscardOutBuffer Discards data from the serial driver's transmit buffer.
      Dispose (inherited from Component)Releases the resources used by the Component.
      Equals (inherited from Object)Determines whether the specified Object is equal to the current Object.
      GetHashCode (inherited from Object)Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.
      GetLifetimeService (inherited from MarshalByRefObject)Retrieves the current lifetime service object that controls the lifetime policy for this instance.
      GetType (inherited from Object)Gets the Type of the current instance.
      InitializeLifetimeService (inherited from MarshalByRefObject)Obtains a lifetime service object to control the lifetime policy for this instance.
      Open Opens a new serial port connection.
      Read Reads from the SerialPort input buffer.
      ReadByte Synchronously reads one byte from the SerialPort input buffer.
      ReadChar Synchronously reads one character from the SerialPort input buffer.
      ReadExisting Reads all immediately available characters (based on the Encoding) in the stream and internal buffer of the SerialPort object.
      ReadLine Reads up to the NewLine value in the input buffer.
      ReadTo Reads up to the specified value in the input buffer.
      ToString (inherited from Component)Returns a String containing the name of the Component , if any. This method should not be overridden. For internal use only.
      Write Writes data to serial port output.
      WriteLine Writes the specified string and the NewLine value to the output buffer.

Public Properties
      BaseStream Gets the internal Stream object, if it exists, for a SerialPort object .
      BaudRate Gets or sets the serial baud rate.
      BreakState Gets or sets the break signal state.
      BytesToRead Gets the number of bytes of data in the receive buffer.
      BytesToWrite
      CDHolding Gets the state of the carrier detect line for the port.
      Container (inherited from Component)Gets the IContainer that contains the Component.
      CtsHolding Gets the state of the clear-to-send line.
      DataBits Gets or sets the standard length of databits per byte.
      DiscardNull Gets or sets whether null characters are ignored when transmitted between the port and the receive buffer.
      DsrHolding Gets the state of the data set ready (DSR) signal.
      DtrEnable Gets or sets the enabling of DTR during serial communication.
      Encoding Gets or sets the character encoding for pre- and post-transmission conversion of text.
      Handshake Gets or sets the handshaking protocol for serial port transmission of data.
      IsOpen Gets the open or closed status of the SerialPort object.
      NewLine Gets or sets the value used to interpret the end of a call to the ReadLine and WriteLine methods.
      Parity Gets or sets the parity checking protocol.
      ParityReplace Gets or sets the 8-bit character that is used to replace invalid characters in a data stream when a parity error occurs.
      PortName Gets or sets the port for communications, including but not limited to all available com ports.
      ReadBufferSize
      ReadTimeout Gets or sets the number of milliseconds before a timeout occurs when a read operation does not finish.
      ReceivedBytes Threshold Gets or sets the number of bytes in the internal input buffer before a ReceivedEvent is fired.
      RtsEnable Gets or sets the enabling of RTS during serial communication.
      Site (inherited from Component)Gets or sets the ISite of the Component.
      StopBits Gets or sets the standard number of stopbits per byte.
      WriteBufferSize
      WriteTimeout Gets or sets the number of milliseconds before a timeout occurs when a write operation does not finish.

Published Tuesday, October 28, 2003 3:52 PM by PaulWilson

Comments

# re: .NET v2.0: Serial Port Communications Finally Arrives

Does it support USB as well or just plain ol' RS-232?

Wednesday, October 29, 2003 3:07 AM by Richard Tallent

# re: .NET v2.0: Serial Port Communications Finally Arrives

See the following post for USB information:
http://groups.google.com/groups?selm=eFyFozm1CHA.2188%40TK2MSFTNGP10

Wednesday, October 29, 2003 8:15 AM by Paul Wilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

This is somewhat bad for me :). I just finished working on a library that I am planning on selling soon that contains a SerialPort class, an underlying stream, as well as integrated ZModem file transfer (and maybe some of the other ones if i have time to include them). Whidbey keeps implementing technology I've been working on for the past 2 years and have been planning on selling. I guess I have about a year of viability now.

Saturday, November 01, 2003 8:38 AM by Ron Buckton

# re: .NET v2.0: Serial Port Communications Finally Arrives

There are several free libraries for .NET already, including one on GotDotNet that is supposedly the basis for what will be added to Whidbey, so I'm not sure you have much of a market even now. :(

Saturday, November 01, 2003 10:58 AM by Paul Wilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

Does anyone know where the full definition of this class can be found.

Thursday, November 13, 2003 10:15 AM by Curtis Nielson

# re: .NET v2.0: Serial Port Communications Finally Arrives

.NET v2.0: http://asp.net/whidbey/

Full definition? What do you mean?

Thursday, November 13, 2003 10:23 AM by Paul Wilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

How can I get this class?

Tuesday, December 23, 2003 3:02 AM by olive

# re: .NET v2.0: Serial Port Communications Finally Arrives

is the class downloadable somewhere?

Thursday, January 22, 2004 1:32 PM by ray

# re: .NET v2.0: Serial Port Communications Finally Arrives

.NET v2.0 is in private alpha right now, it will be in public beta this spring. The docs for the SerialPort class can be found here:
http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.io.ports/c/serialport/serialport.aspx

Thursday, January 22, 2004 2:39 PM by Paul Wilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

can this work in VS 2002,where can i download this

Friday, January 30, 2004 2:44 PM by sibish

# re: .NET v2.0: Serial Port Communications Finally Arrives

Once again, this is part of .NET v2.0, which is not publicly available yet, and no it will not work in VS2002 anymore than .NET v1.1 will. There are third party serial port libraries, both free and commercial, if you google on them.

Friday, January 30, 2004 2:56 PM by Paul Wilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

This class is based on the work done documented @ http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b06e30f9-1301-4cc6-ac14-dfe325097c69

that will work with VS2002 & VS2003 after some tweaks!

Monday, February 02, 2004 9:54 PM by Nguyen Ly

# re: .NET v2.0: Serial Port Communications Finally Arrives

Microsoft's improving. Usually they're 10 years late and 100 dollars short. Now they're only 1 year late and 10 dollars short.

Monday, April 26, 2004 12:32 AM by NiceHairpieceFrank

# re: .NET v2.0: Serial Port Communications Finally Arrives

The funny thing was that I was just investigating this because I was having the dickens of a time figuring out how to talk to the serial port with VB.NET 2003, which I now really regret shelling out $100 for. Best to wait and download the .NET 2.0 framework and write the code in C# entirely from friggin notepad.exe. Or better yet, use Mono/Java on Unix. MS doesn't piss me off nearly as much when I don't have to pay for their perpetually half-baked software.

Monday, April 26, 2004 12:43 AM by NiceHairpieceFrank

# re: .NET v2.0: Serial Port Communications Finally Arrives

Cool work. :)

Monday, May 17, 2004 11:18 PM by yhhuang

# re: .NET v2.0: Serial Port Communications Finally Arrives

Is this available on the Compact Framework??

Monday, June 07, 2004 8:52 PM by Mike

# re: .NET v2.0: Serial Port Communications Finally Arrives

I honestly have no clue, and since we're talking about a product not even in beta yet I'm also not sure its really possible to know yet anyhow. It would makes sense though!

Monday, June 07, 2004 9:01 PM by Paul Wilson

# .NET RS232 Serial Port communication with RS232.dll

A lot of people are coming to this site searching for .NET Serial communications on Google. And while Paul Wilson made it known that System.IO.Ports.SerialPort will arrive in .NET Framework 2.0, that fact is not really useful to you if...

Sunday, June 13, 2004 4:13 PM by TrackBack

# re: .NET v2.0: Serial Port Communications Finally Arrives

Is there any way to connect to a serial port from a web page using client side scripting.
I'm using VS2003.


Tuesday, June 13, 2006 6:57 AM by Sriram

# re: .NET v2.0: Serial Port Communications Finally Arrives

I believe you'll have to create an ActiveX control (or equivalent .NET control).

Tuesday, June 13, 2006 7:57 AM by PaulWilson

# re: .NET v2.0: Serial Port Communications Finally Arrives

Teh SerialPort class is wrong by design, its documentation is misleading.

A serialport class should transparently move 8bit bytes in/out of the PC. Without codepage interpretation, stream interface etc.

Have you MSFT guys ever worked in factory floor automation ?

A trace and debug utility displaying the status of RS-232 pins is missing.

Microsoft: pls just give us TRUE transparent ReadByte() and WriteByte() methods.

Wednesday, June 14, 2006 2:14 AM by Herbert Feichtinger

Leave a Comment

(required) 
(required) 
(optional)
(required)