C # file and com tutorial: Page 2

Home arrow .NET Tutorials arrow C# arrow C # file and com tutorial
C # file and com tutorial Print E-mail
Contributed by Joe   
Thursday, 06 July 2006

 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 code

using 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 )

  home              contact us

 

©2006-2012 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground