// Name of the SerialPort
Using system. Io. ports;
SerialPort comm;
// Open the serial port
Public void opencommp ORT ()
{
Try
{
// Instantiate the Serial Communication Class
This. Comm = new SerialPort ();
// Serial port name
This. Comm. portname = "COM1 ";
// Baud rate
This. Comm. baudrate = 9600;
// Start with the RTS signal
This. Comm. rtsenable = true;
// Stop bit, which adopts the enumeration type and enumerates none, one, onepointfive, and two
This. Comm. stopbits = stopbits. One;
// Data bit
This. Comm. databits = 8;
// Number of event bytes
This. Comm. receivedbytesthreshold = 1;
// Receives events
This. Comm. datareceived + = new serialdatareceivedeventhandler (comm_datareceived );
// Open the serial port
This. Comm. open ();
}
Catch (exception ex)
{
Throw ex;
}
}
Private void comm_datareceived (Object sender, serialdatareceivedeventargs E)
{
Switch (E. eventtype)
{
Case serialdata. Chars:
Break;
}
}