|
C # file and com tutorial |
|
|
|
Contributed by Joe
|
|
Thursday, 06 July 2006 |
|
Page 2 of 2 Access a COM Port in C#Use the System.IO.Ports.SerialPort class. This class represents a serial port resource and defines methods that enable communication through it. Example source codeusing System; using System.IO.Ports; namespace biz.hotdir { static class COmDemo { static void Main(string[] args) { using (SerialPort port = new SerialPort("COM1")) { // Set the properties. port.BaudRate = 9600; port.Parity = Parity.None; port.ReadTimeout = 5; port.StopBits = StopBits.One; // Write a message into the port. port.Open(); port.Write("Hello world!"); Console.WriteLine("Wrote to the port."); } // Wait to continue. Console.WriteLine(Environment.NewLine); Console.WriteLine("Main method complete. Press Enter."); Console.ReadLine(); } } }
|
|
Last Updated ( Thursday, 06 July 2006 )
|