Home > Net >  C # to open COM5 serial port
C # to open COM5 serial port

Time:10-12

C # open the serial port appear such mistakes do

CodePudding user response:

Com5 is the name of your objects, its how the port Settings, com1 on your computer

CodePudding user response:

SerialPort Comport=new SerialPort ();

//serial port
Comport. PortName="COM5";
//serial port baud rate
Comport. BaudRate=9600;
//serial data bits
Comport. DataBits=8;

CodePudding user response:

Nicknamed "brother chun" woman,

Nickname is a nickname, you can't from the nickname for determining troat elder brother must be a man

CodePudding user response:

You first use the
 

SerialPort. GetPortNames ();
To get inside the machine all the COM

The specific method is introduced as follows,

//
//abstract:
//get the current array of computer serial port name,
//
//return the result:
//array of current computer serial port name,
//
//exception:
//T:System.Com ponentModel. Win32Exception:
//can't query serial port name,
Public static string [] GetPortNames ();



CodePudding user response:

A serial port parameters configured, including serial port, with SerialPort. GetPortNames () to obtain the machine all available serial ports,
COM5 the SerialPort instantiation?

CodePudding user response:

Refer to the following code:

Using System. Linq;


 string [] cOMPorts=System. IO. Ports. SerialPort. GetPortNames (); 
If (cOMPorts. FirstOrDefault (w=& gt; W.E quals (" COM5 "))!=null)
{
System. IO. Ports. SerialPort SerialPort=new System. IO. Ports. SerialPort (" COM5 ", 9600);//constructor can set other parameters
if (! SerialPort. IsOpen)
{
SerialPort. The Open ();
}

}
  •  Tags:  
  • C #
  • Related