using System.IO.Ports;
public static SerialPort _serialPort;
public Form1()
{
_serialPort = new SerialPort();
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.PortName = COM1;
try
{
_serialPort.Open();
}
catch (Exception ex)
{
MessageBox.Show(this
, "Error while attempting to open the serial port.\r\n" + ex.Message
, "Open Serial Port Error"
, MessageBoxButtons.OK
, MessageBoxIcon.Error);
}
if (_serialPort.IsOpen)
{
_serialPort.WriteLine("Hello World\r");
}
}