|
|
|
@ -18,7 +18,7 @@ namespace Mesnac.DoUtils
|
|
|
|
|
public SerialPort serialPort = new SerialPort("COM5");
|
|
|
|
|
private static readonly Lazy<DoControl> lazy = new Lazy<DoControl>(() => new DoControl());
|
|
|
|
|
public static DoControl Instance => lazy.Value;
|
|
|
|
|
|
|
|
|
|
public bool AlarmState { get; private set; } = false;
|
|
|
|
|
private DoControl()
|
|
|
|
|
{
|
|
|
|
|
serialPort.BaudRate = 115200;
|
|
|
|
@ -125,11 +125,20 @@ namespace Mesnac.DoUtils
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// DO启停控制
|
|
|
|
|
/// 如果收到红灯亮的信号,AlarmState会变为True; 收到红灯灭的信号,AlarmState设置为false
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dOName">DegitalOut接口名称</param>
|
|
|
|
|
/// <param name="dOOnOff">启停状态</param>
|
|
|
|
|
public void DOControl(DOName dOName, DOOnOff dOOnOff)
|
|
|
|
|
{
|
|
|
|
|
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.On))
|
|
|
|
|
{
|
|
|
|
|
AlarmState = true;
|
|
|
|
|
}
|
|
|
|
|
if(dOName.Equals(DOName.Red) && dOOnOff.Equals(DOOnOff.Off))
|
|
|
|
|
{
|
|
|
|
|
AlarmState = false;
|
|
|
|
|
}
|
|
|
|
|
if (serialPort.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
|
|
|
|
@ -137,6 +146,7 @@ namespace Mesnac.DoUtils
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ComOn();
|
|
|
|
|
serialPort.Write(new byte[] { 0xE3, 0x01, 0x09, (byte)dOName, (byte)dOOnOff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 12);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|