This commit is contained in:
hehaibing-1996
2024-07-05 14:36:34 +08:00
parent adb0367a83
commit ed3673db03
35 changed files with 1435 additions and 1939 deletions

View File

@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@ -83,7 +84,6 @@ namespace WCS.BLL.Tool
}
return data.ToArray();
}
public static byte[] Query()
{
byte[] data2 = new byte[4];
@ -94,7 +94,6 @@ namespace WCS.BLL.Tool
byte[] senddata2 = Tool.Helper.Crc16(data2, data2.Length, true);
return senddata2;
}
public static byte[] SetId()
{
byte[] data2 = new byte[6];
@ -107,7 +106,6 @@ namespace WCS.BLL.Tool
byte[] senddata2 = Tool.Helper.Crc16(data2, data2.Length, true);
return senddata2;
}
//出库库位灯亮灯
public static byte[] OutstoreLight(List<int> board_id, string lightcolor, int status)
{
@ -155,7 +153,6 @@ namespace WCS.BLL.Tool
byte[] data = Crc16(data1, data1.Length, true);
return data;
}
//出库警示灯亮灯
public static byte[] OutstoreWarnLight(int lightid, string lightcolor, int status, int beestatus)
{
@ -240,8 +237,6 @@ namespace WCS.BLL.Tool
byte[] senddata1 = Tool.Helper.Crc16(data1, data1.Length, true);
return senddata1;
}
public static byte[] InstoreLightAndWarnLight(int board_id, int lightid)
{
byte[] data1 = new byte[8 + 3 * 7];
@ -340,6 +335,92 @@ namespace WCS.BLL.Tool
return data;
}
/// <summary>
/// 单灯货架控制
/// </summary>
/// <param name="board_id"></param>
/// <param name="lightcolor"></param>
/// <param name="status"></param>
/// <returns></returns>
public static byte[] SingleLightControl(List<SingleLightShelfModel> shelfs)
{
byte[] dataBase = new byte[5];
dataBase[0] = 0xff;
dataBase[1] = 0x01;
//一个报警灯一个货架
var lightCount = 0;
foreach (var shelf in shelfs)
{
//6个报警灯需要发送指令
if (shelf.WarningLightMode != -1)
{
for (int i = 0; i < 6; i++)
{
var singleLightData = GenerateSingleLightData(shelf.WarningBoardId + i, shelf.WarningLightMode, shelf.WarningLightColor);
lightCount++;
dataBase = dataBase.Concat(singleLightData).ToArray();
}
}
//蜂鸣器需要发送指令
if (shelf.WarningBuzzerMode != -1)
{
var singleLightData = GenerateSingleLightData(shelf.WarningBoardId + 6, shelf.WarningBuzzerMode, shelf.WarningLightColor);
lightCount++;
dataBase = dataBase.Concat(singleLightData).ToArray();
}
//库位灯指令
if (shelf.StoreList != null && shelf.StoreList.Count > 0)
{
foreach (var store in shelf.StoreList)
{
var singleLightData = GenerateSingleLightData(store.BoardId, store.LightMode, store.LightColor);
lightCount++;
dataBase = dataBase.Concat(singleLightData).ToArray();
}
}
}
byte[] length_base = BitConverter.GetBytes(dataBase.Length + 2);
dataBase[2] = length_base[1];
dataBase[3] = length_base[0];
//控制灯的数量
dataBase[4] = (byte)lightCount;
byte[] dataWithCRC = Crc16(dataBase, dataBase.Length, true);
return dataWithCRC;
}
//单独拼接一个灯的协议
public static byte[] GenerateSingleLightData(int lightId, int lightMode, int lightColor)
{
var data = new byte[3];
data[0] = (byte)lightId;
data[1] = (byte)lightMode;
data[2] = (byte)lightColor;
return data;
}
public class SingleLightShelfModel
{
public string ClientIp { get; set; } = string.Empty;
public int WarningBoardId { get; set; }
public int WarningLightMode { get; set; }
public int WarningBuzzerMode { get; set; }
public int WarningLightColor { get; set; }
public List<SingleLightStoreModel> StoreList { get; set; } = new List<SingleLightStoreModel>();
}
public class SingleLightStoreModel
{
public int BoardId { get; set; }
public int LightMode { get; set; }
public int LightColor { get; set; }
}
/// <summary>
/// 返回数据处理
/// </summary>
@ -396,9 +477,9 @@ namespace WCS.BLL.Tool
data1[6 + i * 3] = (byte)status;
data1[7 + i * 3] = color;
}
//data1[5 + 3 * 7 - 3] = (byte)(lightid + 6);
//data1[5 + 3 * 7 - 2] =(byte)beestatus;
//data1[5 + 3 * 7 - 1] = 0x00;
//dataBase[5 + 3 * 7 - 3] = (byte)(lightid + 6);
//dataBase[5 + 3 * 7 - 2] =(byte)beestatus;
//dataBase[5 + 3 * 7 - 1] = 0x00;
byte[] data2 = Crc16(data1, data1.Length, true);
return data2;
}