|
|
@ -13,7 +13,7 @@ namespace Mesnac.DoUtils
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 报警灯控制类
|
|
|
|
/// 报警灯控制类
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class DoControl
|
|
|
|
public sealed class DoControl
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public SerialPort serialPort = new SerialPort("COM5");
|
|
|
|
public SerialPort serialPort = new SerialPort("COM5");
|
|
|
|
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
|
|
|
|
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
|
|
|
@ -38,9 +38,16 @@ namespace Mesnac.DoUtils
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public void ComOn()
|
|
|
|
public void ComOn()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!serialPort.IsOpen)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
serialPort.Open();
|
|
|
|
if (!serialPort.IsOpen)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
serialPort.Open();
|
|
|
|
|
|
|
|
ICSharpCode.Core.LoggingService<DoControl>.Debug($"打开报警器串口成功,串口:{serialPort.PortName};波特率:{serialPort.BaudRate}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ICSharpCode.Core.LoggingService<DoControl>.Error($"报警器串口打开异常,串口:{serialPort.PortName};波特率:{serialPort.BaudRate};异常信息:{ex.Message}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -129,12 +136,14 @@ namespace Mesnac.DoUtils
|
|
|
|
/// <param name="dOOnOff">启停状态</param>
|
|
|
|
/// <param name="dOOnOff">启停状态</param>
|
|
|
|
public void DOControl(DOName dOName, DOOnOff dOOnOff)
|
|
|
|
public void DOControl(DOName dOName, DOOnOff dOOnOff)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//ComOn();
|
|
|
|
if (serialPort.IsOpen)
|
|
|
|
if (!serialPort.IsOpen)
|
|
|
|
{
|
|
|
|
|
|
|
|
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
serialPort.Open();
|
|
|
|
ComOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|