最近写了个程序,在通过编译执行时没有问题,但发布出来后就有问题了,老是说串口打不开,问题出在第二次构造串口时发生.(这个代码在发布后第一次能通过,但第二次调用时在强制为0后就不行了.)
主要代码如下: 请多指教
public int SendAlarmLED()
{
SerialConnection CommPort=ParityFor1();  //强制为1

SendHeadAddress(CommPort);     //发公共地址 0x00  
       
Thread.Sleep(100);
if(CommPort.IsOpen)        //串口如是开就关
                               CommPort.Close(); 
SerialConnection CommPort1=ParityFor0();    //强制为0

                           SendMust(CommPort1);  //最后发送的数据(略)
                  }public SerialConnection ParityFor0()
{
SerialConnection CommPort1 = new SerialConnection();
try
{
CommPort1.Options = new SerialOptions(this.ledCommPortName,
9600, 
Parity.Space,
(byte)8,
CommStopBits.One,
false, 
false, 
false, 
false, false, false);
}
catch
{
Console.Write("强制为0时串口未能构建");
}
return CommPort1;
}public SerialConnection ParityFor1()
{
SerialConnection CommPort = new SerialConnection();
try
{
CommPort.Options = new SerialOptions(this.ledCommPortName,
9600, 
Parity.Mark,
(byte)8,
CommStopBits.One,
false, 
false, 
false, 
false, false, false);

}
catch
{
Console.Write("强制为1时串口未能构建");
}
return CommPort;
}