From 21e4d962219ca6475a9c9b9867b877ae4ba0125d Mon Sep 17 00:00:00 2001 From: wangsr Date: Wed, 13 Dec 2023 09:23:30 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20DB2105=E7=BB=B4=E6=8A=A4=20=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=8E=92=E6=B0=B4=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ManualControl/ForceWaterControl.cs | 91 ++++----- DataBlockHelper/DBHelpers/DB2105Helper.cs | 7 + .../DBHelpers/DB2105WriteHelper.cs | 187 ++++++++++++++++++ DataBlockHelper/DataBlockHelper.csproj | 1 + .../Entity/DB2105Entity/ForceWaterEntity.cs | 37 ++++ 5 files changed, 279 insertions(+), 44 deletions(-) create mode 100644 DataBlockHelper/Entity/DB2105Entity/ForceWaterEntity.cs diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ForceWaterControl.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ForceWaterControl.cs index a59b3f2..a52627a 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ForceWaterControl.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ForceWaterControl.cs @@ -24,7 +24,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl FMCTextBoxEntity MCTextBoxE = new FMCTextBoxEntity(); FMCButtonEntity ButtonE = new FMCButtonEntity(); FMCRadioButtonEntity RadioButtonE = new FMCRadioButtonEntity(); - DB2119Helper DB2119 = new DB2119Helper(); + DB2105Helper DB2105 = new DB2105Helper(); private List Controls; @@ -59,7 +59,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl private void ForceControl_OnSwitchChanged(object obj, bool state) { - DB2119 = new DB2119Helper(); + DB2105 = new DB2105Helper(); if (state) { if (MessageBox.Show("是否要打开强制排水模式?", "强制模式启动确认", @@ -75,16 +75,16 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl switch (name) { case "ForceControlHA": - Db2119WriteHelper.AddHaAddForceOn(state); + DB2105WriteHelper.AddHaAddForceOn(state); break; case "ForceControlCA": - Db2119WriteHelper.AddCaAddForceOn(state); + DB2105WriteHelper.AddCaAddForceOn(state); break; case "ForceControlHB": - Db2119WriteHelper.AddHbAddForceOn(state); + DB2105WriteHelper.AddHbAddForceOn(state); break; case "ForceControlCB": - Db2119WriteHelper.AddCbAddForceOn(state); + DB2105WriteHelper.AddCbAddForceOn(state); break; default: break; } @@ -93,22 +93,25 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl private void StateRefresh(object sender, EventArgs e) { - HslSwitchE.ForceControlHA.SwitchStatus = DB2119.Force_HA.forceOn; - HslSwitchE.ForceControlCA.SwitchStatus = DB2119.Force_CA.forceOn; - HslSwitchE.ForceControlHB.SwitchStatus = DB2119.Force_HB.forceOn; - HslSwitchE.ForceControlCB.SwitchStatus = DB2119.Force_CB.forceOn; - DefaultSwitch(HslSwitchE.ForceControlHA, DB2119.Force_HA.forceOn); + HslSwitchE.ForceControlHA.SwitchStatus = DB2105.Force_HA.forceOn; + HslSwitchE.ForceControlCA.SwitchStatus = DB2105.Force_CA.forceOn; + HslSwitchE.ForceControlHB.SwitchStatus = DB2105.Force_HB.forceOn; + HslSwitchE.ForceControlCB.SwitchStatus = DB2105.Force_CB.forceOn; + DefaultSwitch(HslSwitchE.ForceControlHA, DB2105.Force_HA.forceOn); + DefaultSwitch(HslSwitchE.ForceControlCA, DB2105.Force_CA.forceOn); + DefaultSwitch(HslSwitchE.ForceControlHB, DB2105.Force_HB.forceOn); + DefaultSwitch(HslSwitchE.ForceControlCB, DB2105.Force_CB.forceOn); } private void BottomSelect(RuntimeParameter runtime) { - DB2119 = new DB2119Helper(); + DB2105 = new DB2105Helper(); SingleSelect(); if (ButtonE.StartMetage1 == runtime.Sender) { - if (!DB2119.Force_CA.forceOn) + if (!DB2105.Force_CA.forceOn) { MessageBox.Show("冷水称A强制控制按钮未打开!"); return; @@ -118,15 +121,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddCaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text)); - Db2119WriteHelper.AddCaAddForceBin(GelChooseA); - Db2119WriteHelper.AddCaAddStartIn(true); + DB2105WriteHelper.AddCaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text)); + DB2105WriteHelper.AddCaAddForceBin(GelChooseA); + DB2105WriteHelper.AddCaAddStartIn(true); ManualLogControl("冷水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue1.Text), GelChooseA); MessageBox.Show("冷水称A强制补充"); } if (ButtonE.StartMetage2 == runtime.Sender) { - if (!DB2119.Force_HA.forceOn) + if (!DB2105.Force_HA.forceOn) { MessageBox.Show("热水称A强制控制按钮未打开!"); return; @@ -136,15 +139,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddHaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text)); - Db2119WriteHelper.AddHaAddForceBin(GelChooseA); - Db2119WriteHelper.AddHaAddStartIn(true); + DB2105WriteHelper.AddHaAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text)); + DB2105WriteHelper.AddHaAddForceBin(GelChooseA); + DB2105WriteHelper.AddHaAddStartIn(true); ManualLogControl("热水称A强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue2.Text), GelChooseA); MessageBox.Show("热水称A强制补充"); } if (ButtonE.StartMetage3 == runtime.Sender) { - if (!DB2119.Force_CB.forceOn) + if (!DB2105.Force_CB.forceOn) { MessageBox.Show("冷水称B强制控制按钮未打开!"); return; @@ -154,15 +157,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddCbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text)); - Db2119WriteHelper.AddCbAddForceBin(GelChooseB); - Db2119WriteHelper.AddCbAddStartIn(true); + DB2105WriteHelper.AddCbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text)); + DB2105WriteHelper.AddCbAddForceBin(GelChooseB); + DB2105WriteHelper.AddCbAddStartIn(true); ManualLogControl("冷水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue3.Text), GelChooseB + 4); MessageBox.Show("冷水称B强制补充"); } if (ButtonE.StartMetage4 == runtime.Sender) { - if (!DB2119.Force_HB.forceOn) + if (!DB2105.Force_HB.forceOn) { MessageBox.Show("热水称B强制控制按钮未打开!"); return; @@ -172,9 +175,9 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddHbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text)); - Db2119WriteHelper.AddHbAddForceBin(GelChooseB); - Db2119WriteHelper.AddHbAddStartIn(true); + DB2105WriteHelper.AddHbAddValue(Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text)); + DB2105WriteHelper.AddHbAddForceBin(GelChooseB); + DB2105WriteHelper.AddHbAddStartIn(true); ManualLogControl("热水称B强制补充", Convert.ToInt16(MCTextBoxE.SetWaterValue4.Text), GelChooseB + 4); MessageBox.Show("热水称B强制补充"); } @@ -182,7 +185,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl if (ButtonE.StartOut1 == runtime.Sender) { - if (!DB2119.Force_CA.forceOn) + if (!DB2105.Force_CA.forceOn) { MessageBox.Show("冷水称A强制控制按钮未打开!"); return; @@ -192,15 +195,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddCaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text)); - Db2119WriteHelper.AddCaAddForceBin(GelChooseA); - Db2119WriteHelper.AddCaAddStartOut(true); + DB2105WriteHelper.AddCaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text)); + DB2105WriteHelper.AddCaAddForceBin(GelChooseA); + DB2105WriteHelper.AddCaAddStartOut(true); ManualLogControl("冷水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue1.Text), GelChooseA); MessageBox.Show("冷水称A强制排水"); } if (ButtonE.StartOut2 == runtime.Sender) { - if (!DB2119.Force_HA.forceOn) + if (!DB2105.Force_HA.forceOn) { MessageBox.Show("热水称A强制控制按钮未打开!"); return; @@ -210,15 +213,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddHaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text)); - Db2119WriteHelper.AddHaAddForceBin(GelChooseA); - Db2119WriteHelper.AddHaAddStartOut(true); + DB2105WriteHelper.AddHaAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text)); + DB2105WriteHelper.AddHaAddForceBin(GelChooseA); + DB2105WriteHelper.AddHaAddStartOut(true); ManualLogControl("热水称A强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue2.Text), GelChooseA); MessageBox.Show("热水称A强制排水"); } if (ButtonE.StartOut3 == runtime.Sender) { - if (!DB2119.Force_CB.forceOn) + if (!DB2105.Force_CB.forceOn) { MessageBox.Show("冷水称B强制控制按钮未打开!"); return; @@ -228,15 +231,15 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddCbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text)); - Db2119WriteHelper.AddCbAddForceBin(GelChooseB); - Db2119WriteHelper.AddCbAddStartOut(true); + DB2105WriteHelper.AddCbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text)); + DB2105WriteHelper.AddCbAddForceBin(GelChooseB); + DB2105WriteHelper.AddCbAddStartOut(true); ManualLogControl("冷水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue3.Text), GelChooseB + 4); MessageBox.Show("冷水称B强制排水"); } if (ButtonE.StartOut4 == runtime.Sender) { - if (!DB2119.Force_HB.forceOn) + if (!DB2105.Force_HB.forceOn) { MessageBox.Show("热水称B强制控制按钮未打开!"); return; @@ -246,9 +249,9 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl { return; } - Db2119WriteHelper.AddHbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text)); - Db2119WriteHelper.AddHbAddForceBin(GelChooseB); - Db2119WriteHelper.AddHbAddStartOut(true); + DB2105WriteHelper.AddHbAddRemainValue(Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text)); + DB2105WriteHelper.AddHbAddForceBin(GelChooseB); + DB2105WriteHelper.AddHbAddStartOut(true); ManualLogControl("热水称B强制排水", Convert.ToInt16(MCTextBoxE.StayWaterValue4.Text), GelChooseB + 4); MessageBox.Show("热水称B强制排水"); } diff --git a/DataBlockHelper/DBHelpers/DB2105Helper.cs b/DataBlockHelper/DBHelpers/DB2105Helper.cs index 7abdf1f..4181e80 100644 --- a/DataBlockHelper/DBHelpers/DB2105Helper.cs +++ b/DataBlockHelper/DBHelpers/DB2105Helper.cs @@ -159,6 +159,11 @@ namespace DataBlockHelper.DBHelpers public ManualH H4 => ReadH(164); + public ForceWaterEntity Force_HA => new ForceWaterEntity(bytes, 174); + public ForceWaterEntity Force_HB => new ForceWaterEntity(bytes, 182); + public ForceWaterEntity Force_CA => new ForceWaterEntity(bytes, 190); + public ForceWaterEntity Force_CB => new ForceWaterEntity(bytes, 198); + /// /// 获取所有的 feededDry 是不是读取好了 /// @@ -228,6 +233,8 @@ namespace DataBlockHelper.DBHelpers return manual; } + + } diff --git a/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs b/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs index 017f1f5..e177d0c 100644 --- a/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs +++ b/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs @@ -454,7 +454,194 @@ namespace DataBlockHelper.DBHelpers return operate.IsSuccess; } + private static readonly int HaNo = 106; + public static readonly int HbNo = 114; + private static readonly int CaNo = 122; + private static readonly int CbNo = 130; + #region 添加方法Ha + + public static void AddHaAddValue(short value) + { + AddValue(value, HaNo); + } + + public static void AddHaAddRemainValue(short value) + { + AddRemainValue(value, HaNo); + } + + public static void AddHaAddForceBin(short value) + { + AddForceBin(value, HaNo); + } + + public static void AddHaAddForceOn(bool value) + { + AddForceOn(value, HaNo); + } + + + public static void AddHaAddStartIn(bool value) + { + AddStartIn(value, HaNo); + } + + public static void AddHaAddStartOut(bool value) + { + AddStartOut(value, HaNo); + } + #endregion + + #region Hb 添加方法 + + + public static void AddHbAddValue(short value) + { + AddValue(value, HbNo); + } + + public static void AddHbAddRemainValue(short value) + { + AddRemainValue(value, HbNo); + } + + public static void AddHbAddForceBin(short value) + { + AddForceBin(value, HbNo); + } + + public static void AddHbAddForceOn(bool value) + { + AddForceOn(value, HbNo); + } + + + public static void AddHbAddStartIn(bool value) + { + AddStartIn(value, HbNo); + } + + public static void AddHbAddStartOut(bool value) + { + AddStartOut(value, HbNo); + } + #endregion + + #region Ca 添加方法 + + + public static void AddCaAddValue(short value) + { + AddValue(value, CaNo); + } + + public static void AddCaAddRemainValue(short value) + { + AddRemainValue(value, CaNo); + } + + public static void AddCaAddForceBin(short value) + { + AddForceBin(value, CaNo); + } + + public static void AddCaAddForceOn(bool value) + { + AddForceOn(value, CaNo); + } + + + public static void AddCaAddStartIn(bool value) + { + AddStartIn(value, CaNo); + } + + public static void AddCaAddStartOut(bool value) + { + AddStartOut(value, CaNo); + } + #endregion + + #region Cb 添加方法 + + + + + public static void AddCbAddValue(short value) + { + AddValue(value, CbNo); + } + + public static void AddCbAddRemainValue(short value) + { + AddRemainValue(value, CbNo); + } + + public static void AddCbAddForceBin(short value) + { + AddForceBin(value, CbNo); + } + + public static void AddCbAddForceOn(bool value) + { + AddForceOn(value, CbNo); + } + + + public static void AddCbAddStartIn(bool value) + { + AddStartIn(value, CbNo); + } + + public static void AddCbAddStartOut(bool value) + { + AddStartOut(value, CbNo); + } + #endregion + + + private static void AddValue(short value, int start) + { + //106 + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{start}.0", value); + } + + private static void AddRemainValue(short value, int start) + { + int nu = start + 2; + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{nu}.0", value); + } + + private static void AddForceBin(short value, int start) + { + int nu = start + 4; + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{nu}.0", value); + } + + private static void AddForceOn(bool value, int start) + { + int nu = start + 6; + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{nu}.0", value); + } + + private static void AddStartIn(bool value, int start) + { + int nu = start + 6; + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{nu}.1", value); + } + + private static void AddStartOut(bool value, int start) + { + int nu = start + 6; + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{nu}.2", value); + } } diff --git a/DataBlockHelper/DataBlockHelper.csproj b/DataBlockHelper/DataBlockHelper.csproj index 3da30cf..f23baee 100644 --- a/DataBlockHelper/DataBlockHelper.csproj +++ b/DataBlockHelper/DataBlockHelper.csproj @@ -77,6 +77,7 @@ + diff --git a/DataBlockHelper/Entity/DB2105Entity/ForceWaterEntity.cs b/DataBlockHelper/Entity/DB2105Entity/ForceWaterEntity.cs new file mode 100644 index 0000000..3a08f17 --- /dev/null +++ b/DataBlockHelper/Entity/DB2105Entity/ForceWaterEntity.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataBlockHelper.Entity.DB2105Entity +{ + public class ForceWaterEntity + { + public ForceWaterEntity(byte[] bytes, int startSet) + { + //OperateResult read = PlcConnect.Instance.Read("DB2104.2.0", 50); + + var content = bytes.Skip(startSet).Take(8).ToArray(); + + var instanceByteTransform = PlcConnect.Instance.ByteTransform; + + addValue = instanceByteTransform.TransInt16(content, 0); + remainValue = instanceByteTransform.TransInt16(content, 2); + forceBin = instanceByteTransform.TransInt16(content, 4); + + var byt = content[6]; + + forceOn = byt.GetBit(0); + startIn = byt.GetBit(1); + startOut = byt.GetBit(2); + } + + public short addValue { get; private set; } + public short remainValue { get; private set; } + public short forceBin { get; private set; } + public bool forceOn { get; private set; } + public bool startIn { get; private set; } + public bool startOut { get; private set; } + } +}