diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs index 706f323..d2478d1 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs @@ -1,8 +1,23 @@ -namespace Mesnac.Action.ChemicalWeighing +using HslCommunication; +using Mesnac.Action.ChemicalWeighing.Pl; + +namespace Mesnac.Action.ChemicalWeighing { public static class LjHelp { + //开门狗 - public static int WatchDog=>BasePlcHelper.Instance.WatchDog.LastValue.ToInt(); + public static int WatchDog + { + get + { + OperateResult read = PlcConnect.Instance.Read("DB2107.2.0", 2); + + var content = read.Content; + + return PlcConnect.Instance.ByteTransform.TransInt16(content, 0); + } + } + //BasePlcHelper.Instance.WatchDog.LastValue.ToInt(); } } \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs index 04e70f1..0afbf02 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs @@ -99,7 +99,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure PressureSettingView view = new PressureSettingView() { Id = _id, - HighLimit = b, + HighLimit =b, LowLimit = a, }; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs index f9694bc..df4c94a 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using DataBlockHelper.DBHelpers; +using DataBlockHelper.DbWrite; using DevExpress.XtraGauges.Core.Model; using DevExpress.XtraRichEdit.API.Layout; @@ -16,22 +18,41 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure { if (view != null) { - var basePlcHelper = GetPlcHelper; - basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.mainPress_V1_LowLimit, view.LowLimit); - basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.mainPress_V1_HighLimit, view.HighLimit); + // var basePlcHelper = GetPlcHelper; + // basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.mainPress_V1_LowLimit, view.LowLimit); + // basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.mainPress_V1_HighLimit, view.HighLimit); // basePlcHelper.PlcWriteByDataKey(basePlcHelper.mainPress_V1_Alarm, // new object[] { Convert.ToBoolean(view.Alarm) }); + + + + } + + PlcWriteUtil plcWriter = new PlcWriteUtil(); + + if (view != null) + { + // var basePlcHelper = GetPlcHelper; + + var ss= plcWriter.Write(PlcDbEnum.Db2107,"16.0",PlcDbType.PlcFloat,view.LowLimit); + ss= plcWriter.Write(PlcDbEnum.Db2107,"20.0",PlcDbType.PlcFloat,view.HighLimit); + + } } + + private static DB2107Helper _db2107Helper = new DB2107Helper(); + + private static PressureSettingView UpDbw12() { - var basePlcHelper = GetPlcHelper; + PressureSettingView view = new PressureSettingView(); + var v1 = _db2107Helper.Pressure.MainPress_V1; view.Id = 1; - view.LowLimit = basePlcHelper.mainPress_V1_LowLimit.NowValue.ToFloat(); - view.HighLimit = basePlcHelper.mainPress_V1_HighLimit.NowValue.ToFloat(); - view.Alarm = basePlcHelper.mainPress_V1_LowLimit.NowValue.ToInt(); + view.LowLimit = v1.LowLimit; + view.HighLimit = v1.HighLimit; return view; } @@ -40,6 +61,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure private static void DownDbw26(PressureSettingView view) { + + // PlcWriter plcWriter=new PlcWriter(); + if (view != null) { var basePlcHelper = GetPlcHelper; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index f4ba69f..e76397b 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -169,6 +169,9 @@ False ..\..\..\PlugInPlatform\Mesnac.PlugIn.dll + + ..\..\Microsoft.Office.Interop.Excel.dll + @@ -978,6 +981,10 @@ {f022c0e6-2819-4fb1-bb86-0f389f061a44} Mesnac.Controls.Default + + {4e36df17-e81d-4360-8687-8ad75422b470} + DataBlockHelper + {28acacf1-9936-4e97-a866-f84366ec5286} Mesnac.Basic diff --git a/DataBlockHelper/DbWrite/PlcWriteUtil.cs b/DataBlockHelper/DbWrite/PlcWriteUtil.cs index ae5a302..48c146b 100644 --- a/DataBlockHelper/DbWrite/PlcWriteUtil.cs +++ b/DataBlockHelper/DbWrite/PlcWriteUtil.cs @@ -1,4 +1,6 @@ using System; +using System.Text; +using HslCommunication; using HslCommunication.Profinet.Siemens; namespace DataBlockHelper.DbWrite @@ -16,28 +18,34 @@ namespace DataBlockHelper.DbWrite } - public void Write(PlcDbEnum dbEnum, string address, PlcDbType dbType, object value) + public OperateResult Write(PlcDbEnum dbEnum, string address, PlcDbType dbType, object value) { + OperateResult operateResult = new OperateResult(); + string plcAddress = $"{dbEnum.ToString()}.{address}"; + switch (dbType) { case PlcDbType.PlcInt: - _siemensS7Net.Write(plcAddress, Convert.ToInt32(value)); + operateResult=_siemensS7Net.Write(plcAddress, Convert.ToInt32(value)); break; case PlcDbType.PlcUint: - _siemensS7Net.Write(plcAddress, Convert.ToInt16(value)); + operateResult=_siemensS7Net.Write(plcAddress, Convert.ToInt16(value)); break; case PlcDbType.PlcBoolean: - _siemensS7Net.Write(plcAddress, Convert.ToBoolean(value)); + operateResult= _siemensS7Net.Write(plcAddress, Convert.ToBoolean(value)); break; case PlcDbType.PlcFloat: - _siemensS7Net.Write(plcAddress, Convert.ToSingle(value)); + float number = Convert.ToSingle(value); + operateResult=_siemensS7Net.Write(plcAddress,number); break; } + return operateResult; + } @@ -51,6 +59,8 @@ namespace DataBlockHelper.DbWrite public void Write(string plcAddress, PlcDbType dbType, object value) { + OperateResult operateResult = new OperateResult(); + switch (dbType) { case PlcDbType.PlcInt: diff --git a/DataBlockHelper/Entity/DB2107Entity/PressureEntity.cs b/DataBlockHelper/Entity/DB2107Entity/PressureEntity.cs index 289474b..1715ad0 100644 --- a/DataBlockHelper/Entity/DB2107Entity/PressureEntity.cs +++ b/DataBlockHelper/Entity/DB2107Entity/PressureEntity.cs @@ -51,6 +51,9 @@ namespace DataBlockHelper.Entity.DB2107Entity LowLimit = PlcConnect.Instance.ByteTransform.TransSingle(content, 4); HighLimit = PlcConnect.Instance.ByteTransform.TransSingle(content, 8); + + var operateResult = PlcConnect.Instance.ReadFloat("Db2107.20.0"); + byte byt = content[12]; Alarm = byt.GetBit(0); diff --git a/DataBlockHelper/PlcConnect.cs b/DataBlockHelper/PlcConnect.cs index 35c867b..fa6033c 100644 --- a/DataBlockHelper/PlcConnect.cs +++ b/DataBlockHelper/PlcConnect.cs @@ -24,19 +24,15 @@ namespace DataBlockHelper } - - public static void Init(PlcConfig config) - { - Config = config ?? new PlcConfig(); - } + public SiemensS7Net SiemensS7NetConnection() { SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); - s7.IpAddress = Config.IpAddress; - s7.Port = Config.Port; + s7.IpAddress = "192.168.1.50"; + s7.Port = 102; s7.ConnectServer(); return s7; } diff --git a/Main/MCEdit/MCEdit.csproj b/Main/MCEdit/MCEdit.csproj index 41b7bd2..fb32369 100644 --- a/Main/MCEdit/MCEdit.csproj +++ b/Main/MCEdit/MCEdit.csproj @@ -194,6 +194,10 @@ {d0c0324f-434e-47eb-8f7c-ba6cd7f233b4} Mesnac.Controls.Feeding + + {4e36df17-e81d-4360-8687-8ad75422b470} + DataBlockHelper + {ad132cad-5288-44dc-a38f-4b0658fc228c} Mesnac.DoUtils