我在尝试打开串行端口时遇到问题,但是会发生什么:
当我告诉系统打开端口时,Try 函数没有捕获任何错误但是当我询问串行端口是否打开时,它说它不是
我正在使用带有 .NET 3.9 Compact 框架的 Visual Studio 2015 来调试 WCE2013
try
{
string porta = "COM2";
new frmcomunic().serialPort1.PortName = porta;
new frmcomunic().serialPort1.BaudRate = 38400;
new frmcomunic().serialPort1.DataBits = 8;
new frmcomunic().serialPort1.Parity = System.IO.Ports.Parity.Even;
new frmcomunic().serialPort1.StopBits = System.IO.Ports.StopBits.One;
new frmcomunic().serialPort1.Handshake = System.IO.Ports.Handshake.XOnXOff;
new frmcomunic().serialPort1.ReadTimeout = 500;
new frmcomunic().serialPort1.WriteTimeout = 500;
new frmcomunic().serialPort1.Open();
new frmcomunic().ProgressBar1.Value = 100;
new frmcomunic().btcl.Enabled = true;
new frmcomunic().cbport.Enabled = false;
new frmcomunic().cbrate.Enabled = false;
new frmcomunic().btop.Enabled = false;
new frmcomunic().btcl.Enabled = true;
new frmcomunic().cbport.Enabled = true;
new frmcomunic().cbrate.Enabled = true;
new frmcomunic().ler = true;
}
catch (Exception err)
{
MessageBox.Show("Erro de Comunicação", "Aviso", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
if (new frmcomunic().serialPort1.IsOpen)
MessageBox.Show("Porta aberta", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
else MessageBox.Show("ERRO", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);