121 lines
3.7 KiB
C#
121 lines
3.7 KiB
C#
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WCS.BLL.HardWare
|
|
{
|
|
public class WarningLight
|
|
{
|
|
#region 关于协议的几个枚举
|
|
public enum LightColorEnum
|
|
{
|
|
红色 = 0x01,
|
|
绿色 = 0x02,
|
|
蓝色 = 0x03,
|
|
}
|
|
public enum LightModeEnum
|
|
{
|
|
关闭 = 0x00,
|
|
常亮 = 0x01,
|
|
闪烁 = 0x02,
|
|
短亮一次 = 0x03
|
|
}
|
|
public enum LightBuzzerStatus
|
|
{
|
|
关闭 = 0x00,
|
|
循环鸣叫 = 0x01,
|
|
鸣叫一次 = 0x02
|
|
}
|
|
#endregion
|
|
public int LightId { get; set; } = 2047;
|
|
|
|
public void LightOperation(LightColorEnum lightColor, LightModeEnum lightMode, LightBuzzerStatus lightBuzzerStatus, TCPClient tcpClient, byte time = 0x00)
|
|
{
|
|
try
|
|
{
|
|
var data = new byte[8] { 0x20, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00 };
|
|
data[2] = (byte)lightColor;
|
|
data[3] = (byte)lightMode;
|
|
data[5] = (byte)lightBuzzerStatus;
|
|
|
|
//Only For Debug
|
|
//data[5] = (byte)LightBuzzerStatus.关闭;
|
|
|
|
data[4] = time;//灯短亮一次的时间
|
|
data[6] = time;//蜂鸣器持续鸣叫的时间
|
|
|
|
tcpClient.Send(tcpClient.GenerateMessage(LightId, data));
|
|
return;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 蓝色报警灯常亮
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void BlueLight(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.蓝色, LightModeEnum.常亮, LightBuzzerStatus.关闭, tcpClient);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绿色报警灯常亮
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GreenLight(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.绿色, LightModeEnum.常亮, LightBuzzerStatus.关闭, tcpClient);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭报警灯
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void CloseLight(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.蓝色, LightModeEnum.关闭, LightBuzzerStatus.关闭, tcpClient);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 红色报警灯 响3秒 蓝灯结束
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void WaringLightBlueEnd(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.红色, LightModeEnum.短亮一次, LightBuzzerStatus.鸣叫一次, tcpClient, 0x22);
|
|
Thread.Sleep(3300);
|
|
BlueLight(tcpClient);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 红色报警灯 响3秒 红灯结束
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void WaringLightAlwaysRed(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.红色, LightModeEnum.常亮, LightBuzzerStatus.鸣叫一次, tcpClient, 0x22);
|
|
}
|
|
|
|
public void SuccessLightBlueEnd(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.绿色, LightModeEnum.短亮一次, LightBuzzerStatus.鸣叫一次, tcpClient, 0x03);
|
|
Thread.Sleep(300);
|
|
BlueLight(tcpClient);
|
|
}
|
|
|
|
public void SuccessLightGreenEnd(TCPClient tcpClient)
|
|
{
|
|
LightOperation(LightColorEnum.绿色, LightModeEnum.短亮一次, LightBuzzerStatus.鸣叫一次, tcpClient, 0x03);
|
|
Thread.Sleep(300);
|
|
GreenLight(tcpClient);
|
|
}
|
|
}
|
|
}
|