How to deal with, just want to read a serial port...
Hardware must be no problem, use Google's open source API serial port tried, online search for a long time still no results, only to ask everyone, help...
Below is the code:
void SerialPortInit (string com)
{
String portName;
If (com==null)
PortName="COM0";
The else
PortName=com;
Int baudRate=115200;
Parity Parity=Parity. None;
Int dataBits=8;
StopBits StopBits=StopBits. One;
Int ReadTimeOut=400;
SerialPort sp=null;
Sp=new SerialPort (portName baudRate, parity, dataBits, stopBits);
Sp. ReadTimeout=ReadTimeout;
Try
{
If (sp. IsOpen)
{
Sp. The Close ();
Sp. The Open ();
}
The else
{
Sp. The Open ();
}
}
The catch (Exception ex)
{
The Debug Log (" error: "+ ex. Message);
}
}
CodePudding user response:
Help, everyone...CodePudding user response:
I also in the as a serial port development