From 5eb5c0d9114f8b5dd72df4a42de8ba8ccfe2f6cc Mon Sep 17 00:00:00 2001 From: SoulStar Date: Mon, 21 Apr 2025 13:13:16 +0800 Subject: [PATCH] =?UTF-8?q?feat=20-=20=E6=B7=BB=E5=8A=A0=E7=82=B9=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HighWayIot.Plc/HighWayIot.Plc.csproj | 2 + .../PlcEntity/StationRecipeEntity.cs | 34 ++++ HighWayIot.Plc/PlcHelper/TransferSingal.cs | 177 ++++++++++++++++++ HighWayIot.Plc/PlcHelper/WorkStationHelper.cs | 4 +- HighWayIot.Rfid/RfidDataAnalyse.cs | 4 +- .../UserControlPages/TestPage.cs | 26 ++- 6 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 HighWayIot.Plc/PlcEntity/StationRecipeEntity.cs create mode 100644 HighWayIot.Plc/PlcHelper/TransferSingal.cs diff --git a/HighWayIot.Plc/HighWayIot.Plc.csproj b/HighWayIot.Plc/HighWayIot.Plc.csproj index 4f77e52..7bf2639 100644 --- a/HighWayIot.Plc/HighWayIot.Plc.csproj +++ b/HighWayIot.Plc/HighWayIot.Plc.csproj @@ -50,7 +50,9 @@ + + diff --git a/HighWayIot.Plc/PlcEntity/StationRecipeEntity.cs b/HighWayIot.Plc/PlcEntity/StationRecipeEntity.cs new file mode 100644 index 0000000..cfdc0dc --- /dev/null +++ b/HighWayIot.Plc/PlcEntity/StationRecipeEntity.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HighWayIot.Plc.PlcEntity +{ + /// + /// 工位配方信息 + /// + public class StationRecipeEntity + { + /// + /// 工位配方描述 + /// + public string StationRecipeDescripe { get; set; } + + /// + /// 工位配方号 + /// + public short StationRecipeNo { get; set; } + + /// + /// 工位小车号 + /// + public short StationVehicleNo { get; set; } + + /// + /// 称重工位胎坯重量 + /// + public float StationTireWeight { get; set; } + } +} diff --git a/HighWayIot.Plc/PlcHelper/TransferSingal.cs b/HighWayIot.Plc/PlcHelper/TransferSingal.cs new file mode 100644 index 0000000..581df87 --- /dev/null +++ b/HighWayIot.Plc/PlcHelper/TransferSingal.cs @@ -0,0 +1,177 @@ +using HighWayIot.Plc.PlcEntity; +using HslCommunication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HighWayIot.Plc.PlcHelper +{ + /// + /// 中专信号点位读写 + /// + public class TransferSingal + { + /// + /// 工位贴合开始信号写入 + /// + /// + /// + public bool WriteStationStickSingal(int stationNo) + { + bool result = false; + + switch (stationNo) + { + case 1: + result = PlcConnect.PlcWrite2("B201", true, DataTypeEnum.Bool).IsSuccess; + break; + case 2: + result = PlcConnect.PlcWrite2("B202", true, DataTypeEnum.Bool).IsSuccess; + break; + case 3: + result = PlcConnect.PlcWrite2("B203", true, DataTypeEnum.Bool).IsSuccess; + break; + case 4: + result = PlcConnect.PlcWrite2("B205", true, DataTypeEnum.Bool).IsSuccess; + break; + case 5: + result = PlcConnect.PlcWrite2("B207", true, DataTypeEnum.Bool).IsSuccess; + break; + default: + break; + } + + return result; + } + + + /// + /// 工位贴合计数开始信号写入 + /// + /// + /// + public bool WriteStationStickCountSingal(int stationNo) + { + bool result = false; + + switch (stationNo) + { + case 1: + result = PlcConnect.PlcWrite2("B211", true, DataTypeEnum.Bool).IsSuccess; + break; + case 2: + result = PlcConnect.PlcWrite2("B212", true, DataTypeEnum.Bool).IsSuccess; + break; + case 3: + result = PlcConnect.PlcWrite2("B213", true, DataTypeEnum.Bool).IsSuccess; + break; + case 4: + result = PlcConnect.PlcWrite2("B215", true, DataTypeEnum.Bool).IsSuccess; + break; + case 5: + result = PlcConnect.PlcWrite2("B217", true, DataTypeEnum.Bool).IsSuccess; + break; + default: + break; + } + + return result; + } + + /// + /// 读取小车就绪信号(开始贴合) 鼓到位信号读取(开始横裁信号)和贴合计数信号读取(横裁结束信号) + /// + /// 第一个Byte数组是第二个Byte数组是开始横裁信号,第三个是结束横裁信号 + public bool[][] ReadDrumReadyAndCountReadySignal() + { + OperateResult operateResult = PlcConnect.MelsecInstance1.Read("B991", 2); + + if (!operateResult.IsSuccess) + { + return null; + } + byte[] data = operateResult.Content; + bool[][] result = new bool[3][]; + result[0] = new bool[9]; + result[1] = new bool[8]; + result[2] = new bool[8]; + //12345工位小车就绪 + for (int i = 0; i < 6; i++) + { + result[0][i] = data[0].GetBoolByIndex(i); + } + //345称重工位就绪 + for (int i = 0; i < 3; i++) + { + result[0][i + 6] = data[1].GetBoolByIndex(i); + } + //开始和结束横裁的信号 + for (int i = 0; i < 8; i++) + { + result[1][i] = data[0].GetBoolByIndex(i); + result[2][i] = data[2].GetBoolByIndex(i); + } + + return result; + } + + /// + /// 监控中转信号 + /// + /// + public bool[][] ReadMonitorSingal() + { + OperateResult operateResult = PlcConnect.MelsecInstance1.Read("B9B1", 5); + + if (!operateResult.IsSuccess) + { + return null; + } + + byte[] data = operateResult.Content; + bool[][] result = new bool[5][]; + for (int i = 0; i < 5; i++) + { + result[i] = new bool[5]; + for (int j = 0; j < 5; j++) + { + result[i][j] = data[i * 2].GetBoolByIndex(j); + } + } + + return result; + } + + /// + /// 监控工位配方信息 + /// + /// + public List ReadStationRecipeInfo() + { + OperateResult operateResult = PlcConnect.MelsecInstance1.Read("W950", 80); + + if (!operateResult.IsSuccess) + { + return null; + } + + byte[] data = operateResult.Content; + List resultList = new List(); + + for (int i = 0; i < 5; i++) + { + resultList.Add(new StationRecipeEntity() + { + StationRecipeDescripe = PlcConnect.MelsecInstance2.ByteTransform.TransString(data, (i * 16) + 0, 20, Encoding.ASCII), + StationRecipeNo = PlcConnect.MelsecInstance2.ByteTransform.TransInt16(data, (i * 16) + 20), + StationVehicleNo = PlcConnect.MelsecInstance2.ByteTransform.TransInt16(data, (i * 16) + 22), + StationTireWeight = PlcConnect.MelsecInstance2.ByteTransform.TransSingle(data, (i * 16) + 24), + }); + } + + return resultList; + } + } +} diff --git a/HighWayIot.Plc/PlcHelper/WorkStationHelper.cs b/HighWayIot.Plc/PlcHelper/WorkStationHelper.cs index 153d303..d4887f2 100644 --- a/HighWayIot.Plc/PlcHelper/WorkStationHelper.cs +++ b/HighWayIot.Plc/PlcHelper/WorkStationHelper.cs @@ -36,13 +36,11 @@ namespace HighWayIot.Plc.PlcHelper /// /// RFID固定工位识别点位读取 /// - /// - /// public bool[] ReadStationSingal() { bool[] result = new bool[17]; - OperateResult PlcResult = PlcConnect.MelsecInstance2.Read("B230", 17); + OperateResult PlcResult = PlcConnect.MelsecInstance1.Read("B230", 2); byte[] data = PlcResult.Content; diff --git a/HighWayIot.Rfid/RfidDataAnalyse.cs b/HighWayIot.Rfid/RfidDataAnalyse.cs index 8aaee00..69d0257 100644 --- a/HighWayIot.Rfid/RfidDataAnalyse.cs +++ b/HighWayIot.Rfid/RfidDataAnalyse.cs @@ -67,8 +67,8 @@ namespace HighWayIot.Rfid index += 2; //取读到标签的EPC - Array.Copy(DataBytes, index, EPCData.EPC, 0, 4); - index += 4; + Array.Copy(DataBytes, index, EPCData.EPC, 0, 12); + index += 12; entity.Data.Add(EPCData); } diff --git a/HighWayIot.Winform/UserControlPages/TestPage.cs b/HighWayIot.Winform/UserControlPages/TestPage.cs index abcc033..3d5aca1 100644 --- a/HighWayIot.Winform/UserControlPages/TestPage.cs +++ b/HighWayIot.Winform/UserControlPages/TestPage.cs @@ -1,5 +1,6 @@ using HighWayIot.Log4net; using HighWayIot.Plc; +using HighWayIot.Plc.PlcHelper; using HighWayIot.Winform.Business; using HslCommunication; using System; @@ -43,11 +44,30 @@ namespace HighWayIot.Winform.UserControlPages XmlUtil xmlUtil = new XmlUtil(); private void button1_Click(object sender, EventArgs e) { - var list = xmlUtil.ConfigReader(); - foreach (var item in list) + OperateResult PlcResult = PlcConnect.MelsecInstance1.Read("B230", 2); + + if (PlcResult.IsSuccess) { - Console.WriteLine(item.RoleIndex + item.PageName); + byte[] bytes = PlcResult.Content; + Console.WriteLine("长度" + bytes.Length.ToString()); } + else + { + Console.WriteLine("读取失败"); + } + + WorkStationHelper helper = new WorkStationHelper(); + bool[] res = helper.ReadStationSingal(); + foreach(var r in res) + { + Console.WriteLine(r.ToString()); + } + + //var list = xmlUtil.ConfigReader(); + //foreach (var item in list) + //{ + // Console.WriteLine(item.RoleIndex + item.PageName); + //} } private async void button2_Click(object sender, EventArgs e)