From 924bdf72dbb64d09c27eb337e01b180ae8546a5f Mon Sep 17 00:00:00 2001 From: wangsr Date: Wed, 16 Aug 2023 16:07:04 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E7=94=B5=E6=9C=BA=E8=B0=83=E8=AF=952?= =?UTF-8?q?=EF=BC=88=E4=B8=9A=E5=8A=A1=E5=81=8F=E5=B7=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectronicMachinery.cs | 60 ++--- .../ElectronicMachinery_2.Designer.cs | 196 ++++++++++++++++ .../ElectronicMachinery_2.cs | 213 ++++++++++++++++++ .../ElectronicMachinery_2.resx | 120 ++++++++++ .../ElectronicMachinery_3.Designer.cs | 39 ++++ .../ElectronicMachinery_3.cs | 20 ++ .../PlcCommunicationUtil.cs | 52 +++++ .../Mesnac.Action.ChemicalWeighing.csproj | 16 ++ .../Test/TestAction.cs | 2 +- 9 files changed, 688 insertions(+), 30 deletions(-) create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.Designer.cs create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.cs create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.resx create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.Designer.cs create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.cs create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/PlcCommunicationUtil.cs diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery.cs index 9582fce..a11b181 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery.cs @@ -33,6 +33,36 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach } + /// + /// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用 + /// + /// 数据块属性名 + /// + private DataKeyValue GetDataNameValue(string dmValue) + { + return new DataKeyValue(DmName + dmValue); + } + + /// + /// 从PLC中读取值 + /// + /// 要读取的属性 + /// + private int GetDataToInt(String dmValue) + { + return GetDataNameValue(dmValue).NowValue.ToInt(); + } + + /// + /// 向PLC中写入值 + /// + /// 要写入的属性 + /// 写入的值 + private void SetDataValue(String dmValue, int value) + { + Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value }); + } + /// /// 状态监测类 /// @@ -73,35 +103,7 @@ namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMach } } - /// - /// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用 - /// - /// 数据块属性名 - /// - private DataKeyValue GetDataNameValue(string dmValue) - { - return new DataKeyValue(DmName + dmValue); - } - - /// - /// 从PLC中读取值 - /// - /// 要读取的属性 - /// - private int GetDataToInt(String dmValue) - { - return GetDataNameValue(dmValue).NowValue.ToInt(); - } - - /// - /// 向PLC中写入值 - /// - /// 要写入的属性 - /// 写入的值 - private void SetDataValue(String dmValue, int value) - { - Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value }); - } + /// /// 列表框,选择设备对应数据块 diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.Designer.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.Designer.cs new file mode 100644 index 0000000..ce8a1fc --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.Designer.cs @@ -0,0 +1,196 @@ +namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery +{ + partial class ElectronicMachinery_2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ModeChangeState = new System.Windows.Forms.GroupBox(); + this.ModeStateLable = new System.Windows.Forms.Label(); + this.NowIs = new System.Windows.Forms.Label(); + this.ModeControl = new System.Windows.Forms.Button(); + this.OnOffControlState = new System.Windows.Forms.GroupBox(); + this.OnOffStateLable = new System.Windows.Forms.Label(); + this.OnOffControl = new System.Windows.Forms.Button(); + this.OtherControlGroup = new System.Windows.Forms.GroupBox(); + this.AlarmReset = new System.Windows.Forms.Button(); + this.Alarm = new System.Windows.Forms.Button(); + this.DmChange = new System.Windows.Forms.ListBox(); + this.ModeChangeState.SuspendLayout(); + this.OnOffControlState.SuspendLayout(); + this.OtherControlGroup.SuspendLayout(); + this.SuspendLayout(); + // + // ModeChangeState + // + this.ModeChangeState.Controls.Add(this.ModeStateLable); + this.ModeChangeState.Controls.Add(this.NowIs); + this.ModeChangeState.Controls.Add(this.ModeControl); + this.ModeChangeState.Location = new System.Drawing.Point(12, 12); + this.ModeChangeState.Name = "ModeChangeState"; + this.ModeChangeState.Size = new System.Drawing.Size(178, 65); + this.ModeChangeState.TabIndex = 0; + this.ModeChangeState.TabStop = false; + this.ModeChangeState.Text = "模式切换"; + // + // ModeStateLable + // + this.ModeStateLable.AutoSize = true; + this.ModeStateLable.Location = new System.Drawing.Point(117, 33); + this.ModeStateLable.Name = "ModeStateLable"; + this.ModeStateLable.Size = new System.Drawing.Size(53, 12); + this.ModeStateLable.TabIndex = 2; + this.ModeStateLable.Text = "手动模式"; + // + // NowIs + // + this.NowIs.AutoSize = true; + this.NowIs.Location = new System.Drawing.Point(117, 17); + this.NowIs.Name = "NowIs"; + this.NowIs.Size = new System.Drawing.Size(41, 12); + this.NowIs.TabIndex = 1; + this.NowIs.Text = "当前为"; + // + // ModeControl + // + this.ModeControl.Location = new System.Drawing.Point(6, 20); + this.ModeControl.Name = "ModeControl"; + this.ModeControl.Size = new System.Drawing.Size(105, 39); + this.ModeControl.TabIndex = 0; + this.ModeControl.Text = "切换手动模式"; + this.ModeControl.UseVisualStyleBackColor = true; + this.ModeControl.Click += new System.EventHandler(this.ModeControl_Click); + // + // OnOffControlState + // + this.OnOffControlState.Controls.Add(this.OnOffStateLable); + this.OnOffControlState.Controls.Add(this.OnOffControl); + this.OnOffControlState.Location = new System.Drawing.Point(12, 83); + this.OnOffControlState.Name = "OnOffControlState"; + this.OnOffControlState.Size = new System.Drawing.Size(178, 65); + this.OnOffControlState.TabIndex = 1; + this.OnOffControlState.TabStop = false; + this.OnOffControlState.Text = "启停控制"; + // + // OnOffStateLable + // + this.OnOffStateLable.AutoSize = true; + this.OnOffStateLable.Location = new System.Drawing.Point(117, 33); + this.OnOffStateLable.Name = "OnOffStateLable"; + this.OnOffStateLable.Size = new System.Drawing.Size(53, 12); + this.OnOffStateLable.TabIndex = 1; + this.OnOffStateLable.Text = "状态:关"; + // + // OnOffControl + // + this.OnOffControl.Location = new System.Drawing.Point(6, 20); + this.OnOffControl.Name = "OnOffControl"; + this.OnOffControl.Size = new System.Drawing.Size(105, 39); + this.OnOffControl.TabIndex = 0; + this.OnOffControl.Text = "启动"; + this.OnOffControl.UseVisualStyleBackColor = true; + this.OnOffControl.Click += new System.EventHandler(this.OnOffControl_Click); + // + // OtherControlGroup + // + this.OtherControlGroup.Controls.Add(this.AlarmReset); + this.OtherControlGroup.Controls.Add(this.Alarm); + this.OtherControlGroup.Location = new System.Drawing.Point(196, 12); + this.OtherControlGroup.Name = "OtherControlGroup"; + this.OtherControlGroup.Size = new System.Drawing.Size(119, 109); + this.OtherControlGroup.TabIndex = 2; + this.OtherControlGroup.TabStop = false; + this.OtherControlGroup.Text = "其他控制"; + // + // AlarmReset + // + this.AlarmReset.Location = new System.Drawing.Point(6, 65); + this.AlarmReset.Name = "AlarmReset"; + this.AlarmReset.Size = new System.Drawing.Size(107, 39); + this.AlarmReset.TabIndex = 1; + this.AlarmReset.Text = "报警复位"; + this.AlarmReset.UseVisualStyleBackColor = true; + this.AlarmReset.Click += new System.EventHandler(this.AlarmReset_Click); + // + // Alarm + // + this.Alarm.Location = new System.Drawing.Point(6, 20); + this.Alarm.Name = "Alarm"; + this.Alarm.Size = new System.Drawing.Size(107, 39); + this.Alarm.TabIndex = 0; + this.Alarm.Text = "电机报警"; + this.Alarm.UseVisualStyleBackColor = true; + this.Alarm.Click += new System.EventHandler(this.Alarm_Click); + // + // DmChange + // + this.DmChange.FormattingEnabled = true; + this.DmChange.ItemHeight = 12; + this.DmChange.Location = new System.Drawing.Point(12, 154); + this.DmChange.Name = "DmChange"; + this.DmChange.Size = new System.Drawing.Size(178, 64); + this.DmChange.TabIndex = 3; + this.DmChange.SelectedIndexChanged += new System.EventHandler(this.DmChange_SelectedIndexChanged); + this.DmChange.Items.AddRange(new object[] { + "磨粉主机电机", + "磨粉风机电机", + }); + // + // ElectronicMachinery_2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(326, 226); + this.Controls.Add(this.DmChange); + this.Controls.Add(this.OtherControlGroup); + this.Controls.Add(this.OnOffControlState); + this.Controls.Add(this.ModeChangeState); + this.Name = "ElectronicMachinery_2"; + this.Text = "电机控制_2"; + this.ModeChangeState.ResumeLayout(false); + this.ModeChangeState.PerformLayout(); + this.OnOffControlState.ResumeLayout(false); + this.OnOffControlState.PerformLayout(); + this.OtherControlGroup.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox ModeChangeState; + private System.Windows.Forms.GroupBox OnOffControlState; + private System.Windows.Forms.GroupBox OtherControlGroup; + private System.Windows.Forms.Label ModeStateLable; + private System.Windows.Forms.Label NowIs; + private System.Windows.Forms.Button ModeControl; + private System.Windows.Forms.Label OnOffStateLable; + private System.Windows.Forms.Button OnOffControl; + private System.Windows.Forms.Button AlarmReset; + private System.Windows.Forms.Button Alarm; + private System.Windows.Forms.ListBox DmChange; + } +} \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.cs new file mode 100644 index 0000000..5c472db --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.cs @@ -0,0 +1,213 @@ +using Mesnac.Action.ChemicalWeighing.Entity; +using Mesnac.DoUtils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery +{ + public partial class ElectronicMachinery_2 : Form + { + BasePlcHelper Plc = BasePlcHelper.Instance; + + int ManualModeIsOpen; + int ManualModeIsStart; + int AutoModeIsStart; + string DmName = "DM1GDS06"; + public ElectronicMachinery_2() + { + InitializeComponent(); + DoControl AlarmLight = DoControl.Instance; + DoControl.Instance.ComOn(); + DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); + StateMonitor(); + } + + private void ModeControl_Click(object sender, EventArgs e) + { + if (ManualModeIsOpen == 0) + { + SetDataValue("_ManualMode", 1); + SetDataValue("_AutoMode", 0); + ModeControl.Text = "切换自动模式"; + ModeStateLable.Text = "手动模式"; + ManualModeIsOpen = 1; + if (ManualModeIsStart == 0) + { + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + } + else + { + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + } + } + else + { + SetDataValue("_ManualMode", 0); + SetDataValue("_AutoMode", 1); + ModeControl.Text = "切换手动模式"; + ModeStateLable.Text = "自动模式"; + ManualModeIsOpen = 0; + if (AutoModeIsStart == 0) + { + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + } + else + { + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + } + } + } + + private void OnOffControl_Click(object sender, EventArgs e) + { + if (ManualModeIsOpen == 0) + { + if (AutoModeIsStart == 0) + { + SetDataValue("_StartAuto", 1); + SetDataValue("_StopAuto", 0); + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + AutoModeIsStart = 1; + } + else + { + SetDataValue("_StartAuto", 0); + SetDataValue("_StopAuto", 1); + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + AutoModeIsStart = 0; + } + } + else + { + if (ManualModeIsStart == 0) + { + SetDataValue("_StartManual", 1); + SetDataValue("_StopManual", 0); + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + ManualModeIsStart = 1; + } + else + { + SetDataValue("_StartManual", 0); + SetDataValue("_StopManual", 1); + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + ManualModeIsStart = 0; + } + } + } + + private void DmChange_SelectedIndexChanged(object sender, EventArgs e) + { + switch (DmChange.Text) + { + case "磨粉主机电机": + DmName = "DM1GDS06"; + break; + case "磨粉风机电机": + DmName = "DM1GDS07"; + break; + } + StateMonitor(); + ICSharpCode.Core.LoggingService.Debug(DmChange.Text + "电机切换成功!"); + } + + private void Alarm_Click(object sender, EventArgs e) + { + SetDataValue("_Alarm", 1); + DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On); + DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off); + } + + private void AlarmReset_Click(object sender, EventArgs e) + { + SetDataValue("_Alarm", 0); + DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); + DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off); + } + + /// + /// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用 + /// + /// 数据块属性名 + /// + private DataKeyValue GetDataNameValue(string dmValue) + { + return new DataKeyValue(DmName + dmValue); + } + + /// + /// 从PLC中读取值 + /// + /// 要读取的属性 + /// + private int GetDataToInt(String dmValue) + { + return GetDataNameValue(dmValue).NowValue.ToInt(); + } + + /// + /// 向PLC中写入值 + /// + /// 要写入的属性 + /// 写入的值 + private void SetDataValue(String dmValue, int value) + { + Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value }); + } + + /// + /// 状态监测类 + /// + private void StateMonitor() + { + ManualModeIsOpen = GetDataToInt("_ManualMode"); + ManualModeIsStart = GetDataToInt("_StartManual"); + AutoModeIsStart = GetDataToInt("_StartAuto"); + if (ManualModeIsOpen == 0) + { + ModeControl.Text = "切换手动模式"; + ModeStateLable.Text = "自动模式"; + if (AutoModeIsStart == 0) + { + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + } + else + { + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + } + } + else + { + ModeControl.Text = "切换自动模式"; + ModeStateLable.Text = "手动模式"; + if (ManualModeIsStart == 0) + { + OnOffControl.Text = "启动"; + OnOffStateLable.Text = "状态:关"; + } + else + { + OnOffControl.Text = "关闭"; + OnOffStateLable.Text = "状态:开"; + } + } + } + } +} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.resx b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_2.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.Designer.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.Designer.cs new file mode 100644 index 0000000..94f377b --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.Designer.cs @@ -0,0 +1,39 @@ +namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery +{ + partial class ElectronicMachinery_3 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.cs new file mode 100644 index 0000000..76ebda2 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/ElectronicMachinery/ElectronicMachinery_3.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery +{ + public partial class ElectronicMachinery_3 : Form + { + public ElectronicMachinery_3() + { + InitializeComponent(); + } + } +} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/PlcCommunicationUtil.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/PlcCommunicationUtil.cs new file mode 100644 index 0000000..3d24f44 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/EngineeringDebuggingMode/PlcCommunicationUtil.cs @@ -0,0 +1,52 @@ +using Mesnac.Action.ChemicalWeighing.Entity; +using Mesnac.PlcUtils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + + +namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode +{ + + public class PlcCommunicationUtil + { + string DmName; + BasePlcHelper Plc = BasePlcHelper.Instance; + + + + + /// + /// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用 + /// + /// 数据块属性名 + /// + private DataKeyValue GetDataNameValue(string dmValue) + { + return new DataKeyValue(DmName + dmValue); + } + + /// + /// 从PLC中读取值 + /// + /// 要读取的属性 + /// + private int GetDataToInt(String dmValue) + { + return GetDataNameValue(dmValue).NowValue.ToInt(); + } + + /// + /// 向PLC中写入值 + /// + /// 要写入的属性 + /// 写入的值 + private void SetDataValue(String dmValue, int value) + { + Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value }); + } + } +} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index d3ba0dc..0c52ad0 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -218,6 +218,19 @@ ElectronicMachinery.cs + + Form + + + ElectronicMachinery_2.cs + + + Form + + + ElectronicMachinery_3.cs + + Form @@ -680,6 +693,9 @@ ElectronicMachinery.cs + + ElectronicMachinery_2.cs + ValveStateControl.cs diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Test/TestAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Test/TestAction.cs index 38a195a..29aebe5 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Test/TestAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Test/TestAction.cs @@ -40,7 +40,7 @@ namespace Mesnac.Action.ChemicalWeighing.Test // dbHelper.CommandText = sql; - ValveStateControl Form = new ValveStateControl(); + ElectronicMachinery_2 Form = new ElectronicMachinery_2(); Form.Show();