change - DOControl代码完善

master
wangsr 1 year ago
parent 44b54a1796
commit f014130acd

Binary file not shown.

@ -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);
}
}

Binary file not shown.
Loading…
Cancel
Save