From 1fd730e4ef6ae5c166db82c2e7e2fa4e09dc052d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com>
Date: Sat, 5 Mar 2022 16:58:42 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HBLConsole.Business/Devices/MORKS.cs | 334 +++++++++++++++++++-
HBLConsole.Business/MessageServer/Base.cs | 1 +
HBLConsole.Communication/ModbusTcpHelper.cs | 14 +-
HBLConsole.GVL/MORKS.cs | 152 ++++++++-
HBLConsole.MainConsole/Main.cs | 1 +
HBLConsole.Service/RTrig.cs | 41 +++
6 files changed, 531 insertions(+), 12 deletions(-)
create mode 100644 HBLConsole.Service/RTrig.cs
diff --git a/HBLConsole.Business/Devices/MORKS.cs b/HBLConsole.Business/Devices/MORKS.cs
index 48e52a9..5187fe2 100644
--- a/HBLConsole.Business/Devices/MORKS.cs
+++ b/HBLConsole.Business/Devices/MORKS.cs
@@ -1,4 +1,5 @@
-using HBLConsole.Communication;
+using BPA.Message;
+using HBLConsole.Communication;
using HBLConsole.Factory;
using HBLConsole.Interface;
using HBLConsole.Model;
@@ -7,7 +8,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
+using BPA.Message.Enum;
namespace HBLConsole.Business.Devices
{
@@ -17,6 +20,8 @@ namespace HBLConsole.Business.Devices
public static MORKS GetInstance => _Instance ?? (_Instance = new MORKS());
private MORKS() { }
+ GVL.MORKS mORKS = new GVL.MORKS();
+
///
/// 写入配方数据到 PLC
///
@@ -42,6 +47,9 @@ namespace HBLConsole.Business.Devices
ActionManagerment.GetInstance.Register(new Action(() =>
{
WriteRecipeBoms();
+ ReadPlcData();
+ DataParse();
+ Main();
}), "ConnectOk");
//获取物料信息
@@ -50,6 +58,330 @@ namespace HBLConsole.Business.Devices
//Modbus Tcp 连接
ModbusTcpHelper.GetInstance.ModbusTcpConnect("127.0.0.1");
}
+
+ ///
+ /// 数据读取
+ ///
+ private void ReadPlcData()
+ {
+ ThreadManagerment.GetInstance.StartLong(new Action(() =>
+ {
+ object result;
+ result = ModbusTcpHelper.GetInstance.Read(1120, ReadType.Coils, 16);
+ if (result != null)
+ {
+ if (result is bool[] bools)
+ {
+ if (bools.Length == 16)
+ {
+ mORKS.InitComplete = bools[0];
+ mORKS.TakeBowlIdle = bools[1];
+ mORKS.TemperatureReached = bools[2];
+ mORKS.AllowFallNoodle = bools[3];
+ mORKS.RbTakeNoodleComplete = bools[4];
+ mORKS.RbFallNoodleComplete = bools[5];
+ mORKS.RbOutMealComplete = bools[6];
+ mORKS.RobotIdle = bools[7];
+ mORKS.TakeMealDetect = bools[8];
+ mORKS.MissingBowl = bools[9];
+ mORKS.TurntableLowerLimit = bools[11];
+ }
+ }
+ }
+
+ //读取煮面栏状态
+ result = ModbusTcpHelper.GetInstance.Read(1136, ReadType.Coils, 6);
+ if (result != null)
+ {
+ if (result is bool[] bools)
+ {
+ if (bools.Length == 6)
+ {
+ for (int i = 0; i < 6; i++)
+ {
+ mORKS.NoodleCookerStatus[i] = bools[i];
+ }
+ }
+ }
+ }
+
+ //读取煮面炉完成信号
+ result = ModbusTcpHelper.GetInstance.Read(1144, ReadType.Coils, 6);
+ if (result != null)
+ {
+ if (result is bool[] bools)
+ {
+ if (bools.Length == 6)
+ {
+ for (int i = 0; i < 6; i++)
+ {
+ mORKS.CookNoodlesComplete[i] = bools[i];
+ }
+ }
+ }
+ }
+ Thread.Sleep(500);
+ }), "Read PLC Data");
+ }
+
+ ///
+ /// 数据解析
+ ///
+ private void DataParse()
+ {
+ ActionManagerment.GetInstance.Register(new Action