Commit 38a1531c authored by shaxuezheng's avatar shaxuezheng

Add AutoControl

parent c60c7f7f
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ModbusDemo.Common
{
public class OperIni
{
public string Path;
public OperIni(string path)
{
this.Path = path;
}
/// <summary>
/// 写入INI文件
/// </summary>
/// <param name="section">节点名称[如[TypeName]]</param>
/// <param name="key">键</param>
/// <param name="val">值</param>
/// <param name="filepath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="section">节点名称</param>
/// <param name="key">键</param>
/// <param name="def">值</param>
/// <param name="retval">stringbulider对象</param>
/// <param name="size">字节大小</param>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
/// <summary>
/// 写入
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="iValue"></param>
public void WriteContentValue(string section, string key, string iValue)
{
WritePrivateProfileString(section, key, iValue, this.Path);
}
/// <summary>
/// 读取INI文件中的内容方法
/// </summary>
/// <param name="Section">键</param>
/// <param name="key">值</param>
/// <returns></returns>
public string ReadContentValue(string Section, string key)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(Section, key, "", temp, 1024, this.Path);
return temp.ToString();
}
}
}
...@@ -2,20 +2,6 @@ ...@@ -2,20 +2,6 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<SSDTUnitTestPath Condition="'$(SSDTUnitTestPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB</SSDTUnitTestPath> <SSDTUnitTestPath Condition="'$(SSDTUnitTestPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB</SSDTUnitTestPath>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SSDTPath Condition="'$(SSDTPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130</SSDTPath> <SSDTPath Condition="'$(SSDTPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130</SSDTPath>
...@@ -36,6 +22,20 @@ ...@@ -36,6 +22,20 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
<HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath> <HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
...@@ -88,12 +89,14 @@ ...@@ -88,12 +89,14 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="application\AutoControl.cs" />
<Compile Include="application\InIHelper.cs" />
<Compile Include="application\PoolModbusSet.cs" /> <Compile Include="application\PoolModbusSet.cs" />
<Compile Include="application\ModbusToPool.cs" /> <Compile Include="application\ModbusToPool.cs" />
<Compile Include="application\Pond.cs" /> <Compile Include="application\Pond.cs" />
<Compile Include="application\UsThread.cs" /> <Compile Include="application\UsThread.cs" />
<Compile Include="Common\ModualAlarm.cs" /> <Compile Include="Common\ModualAlarm.cs" />
<Compile Include="MessageFormat\ModualControl.cs" /> <Compile Include="Common\OperIni.cs" />
<Compile Include="MessageFormat\ModbusComm.cs" /> <Compile Include="MessageFormat\ModbusComm.cs" />
<Compile Include="Modular\414P.cs" /> <Compile Include="Modular\414P.cs" />
<Compile Include="Modular\478C.cs" /> <Compile Include="Modular\478C.cs" />
...@@ -167,11 +170,11 @@ ...@@ -167,11 +170,11 @@
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<!-- <SsdtUnitTestVersion>3.1</SsdtUnitTestVersion> --> <SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
<!-- </PropertyGroup> --> </PropertyGroup>
<!-- <Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" /> --> <Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" />
<!-- <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' == ''" /> --> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' == ''" />
<!-- <PropertyGroup> --> <PropertyGroup>
<SsdtUnitTestVersion>3.1</SsdtUnitTestVersion> <SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" /> <Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" />
......
...@@ -70,8 +70,8 @@ namespace ModbusDemo.Modular ...@@ -70,8 +70,8 @@ namespace ModbusDemo.Modular
public static modual.pcx78C cx78c = new modual.pcx78C(byX78cIdlist); public static modual.pcx78C cx78c = new modual.pcx78C(byX78cIdlist);
#if DEBUG_TEST #if DEBUG_TEST
public const byte byX66cNumber = 2; public const byte byX66cNumber = 3;
public static byte[] byX66cIdlist = {16,31}; public static byte[] byX66cIdlist = {16,31,35};
#else #else
public const byte byX66cNumber = 32; public const byte byX66cNumber = 32;
public static byte[] byX66cIdlist = {4,5,7,8,9,10,14,15,19,22,23,24,26,30,32,36,37,38,40,41,42,43,44,46,47,48,49,50,51,52,54,57}; public static byte[] byX66cIdlist = {4,5,7,8,9,10,14,15,19,22,23,24,26,30,32,36,37,38,40,41,42,43,44,46,47,48,49,50,51,52,54,57};
......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModbusDemo.windows;
using ModbusDemo.Modular;
namespace ModbusDemo.application
{
public class AutoControl
{
//Automatic Control Enablation
//Startcontrol MAX
//stopcontrol Min
//modbuspolling ——water level
//工作状态
public class Status
{
public bool Beyond_the_limit; //超出极限值
public bool normal;//正常·工作中
public bool Minimum_Early_Warning;//低值预警
}
public class Control : Status
{
public bool Enablation;
public float maxLevel;
public float minLevel;
public float DifferenceValue;
public double realTimeLevel;
public bool status;
public string Name;
public double StatusTime;
}
public static void CriticalValueMonitoring(
bool Enabl, double MaxLevel,
double MinLevel, double ActualValue,
string Affiliation, out Control control)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
Control usControl = new Control
{
Enablation = Enabl,
realTimeLevel = ActualValue,
Name = Affiliation
};
if (usControl.Enablation == true)
{
if (MaxLevel != 0.0 && MinLevel != 0.0)
{
InIHelper.WriteConfig("MaxLevel", Affiliation, MaxLevel.ToString());
InIHelper.WriteConfig("MinLevel", Affiliation, MinLevel.ToString());
usControl.maxLevel = InIHelper.ReadConfig<float>("MaxLevel", Affiliation);
usControl.minLevel = InIHelper.ReadConfig<float>("MinLevel", Affiliation);
}
else
{
usControl.maxLevel = InIHelper.ReadConfig<float>("MaxLevel", Affiliation);
usControl.minLevel = InIHelper.ReadConfig<float>("MinLevel", Affiliation);
}
usControl.realTimeLevel = Meanfilter(usControl.realTimeLevel);//实时值
usControl.DifferenceValue = usControl.maxLevel - usControl.minLevel;//极值差
if (usControl.realTimeLevel > usControl.maxLevel)
{
usControl.status = true;
usControl.Beyond_the_limit = true;
}
else if (usControl.realTimeLevel < usControl.maxLevel && usControl.realTimeLevel > (usControl.minLevel + usControl.minLevel * 0.15))
{
usControl.status = true;
usControl.normal = true;
}
if (usControl.realTimeLevel < (usControl.minLevel - usControl.minLevel * 0.1))
{
usControl.status = false;
usControl.Minimum_Early_Warning = true;
}
if (usControl.status == true)
{
stopwatch.Start(); // 开始监视运行时间
}
else
{
stopwatch.Stop(); // 停止监视
}
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
//double hours = timespan.TotalHours; // 总小时
usControl.StatusTime = timespan.TotalMinutes; // 总分钟
//usControl.StatusTime = timespan.TotalSeconds; // 总秒数
usControl.StatusTime = timespan.TotalMilliseconds; // 总毫秒数
}
control = usControl;
}
public static double Meanfilter(double Value)
{
double[] MeanValue = new double[10];
for (int i = 0; i < 10; i++)
{
MeanValue[i] = Value;
}
Value = MeanValue[0] * 0.1 + MeanValue[5] * 0.3 + MeanValue[9] * 0.6;
return Value;
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ModbusDemo.Common;
namespace ModbusDemo.application
{
public class InIHelper
{
private static string FileName = Application.StartupPath + "\\AppConfig.ini";
/// <summary>
/// 读取配置文件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="section"></param>
/// <param name="key"></param>
/// <returns></returns>
public static T ReadConfig<T>(string section, string key)
{
if (File.Exists(FileName))
{
OperIni f = new OperIni(FileName);
string value = f.ReadContentValue(section, key);
if (String.IsNullOrWhiteSpace(value))
return default(T);
if (typeof(T).IsEnum)
return (T)Enum.Parse(typeof(T), value, true);
return (T)Convert.ChangeType(value, typeof(T));
}
else
{
return default(T);
}
}
/// <summary>
/// 写配置文件
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="value"></param>
public static void WriteConfig(string section, string key, string value)
{
//如果文件不存在,则创建
if (!File.Exists(FileName))
{
using (FileStream myFs = new FileStream(FileName, FileMode.Create)) { }
}
OperIni f = new OperIni(FileName);
f.WriteContentValue(section, key, value);
}
}
}
...@@ -70,20 +70,18 @@ ...@@ -70,20 +70,18 @@
this.cmbStopBit.Items.AddRange(new object[] { this.cmbStopBit.Items.AddRange(new object[] {
"1", "1",
"2"}); "2"});
this.cmbStopBit.Location = new System.Drawing.Point(461, 98); this.cmbStopBit.Location = new System.Drawing.Point(346, 78);
this.cmbStopBit.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.cmbStopBit.Name = "cmbStopBit"; this.cmbStopBit.Name = "cmbStopBit";
this.cmbStopBit.Size = new System.Drawing.Size(73, 24); this.cmbStopBit.Size = new System.Drawing.Size(56, 22);
this.cmbStopBit.TabIndex = 70; this.cmbStopBit.TabIndex = 70;
// //
// btCloseCOM // btCloseCOM
// //
this.btCloseCOM.Enabled = false; this.btCloseCOM.Enabled = false;
this.btCloseCOM.Font = new System.Drawing.Font("Arial", 8F); this.btCloseCOM.Font = new System.Drawing.Font("Arial", 8F);
this.btCloseCOM.Location = new System.Drawing.Point(432, 130); this.btCloseCOM.Location = new System.Drawing.Point(324, 104);
this.btCloseCOM.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btCloseCOM.Name = "btCloseCOM"; this.btCloseCOM.Name = "btCloseCOM";
this.btCloseCOM.Size = new System.Drawing.Size(104, 29); this.btCloseCOM.Size = new System.Drawing.Size(78, 23);
this.btCloseCOM.TabIndex = 72; this.btCloseCOM.TabIndex = 72;
this.btCloseCOM.Text = "Close"; this.btCloseCOM.Text = "Close";
this.btCloseCOM.Click += new System.EventHandler(this.btCloseCOM_Click); this.btCloseCOM.Click += new System.EventHandler(this.btCloseCOM_Click);
...@@ -95,19 +93,17 @@ ...@@ -95,19 +93,17 @@
"0-None Parity", "0-None Parity",
"1-Odd Parity", "1-Odd Parity",
"2-Even Parity"}); "2-Even Parity"});
this.cmbParity.Location = new System.Drawing.Point(311, 98); this.cmbParity.Location = new System.Drawing.Point(233, 78);
this.cmbParity.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.cmbParity.Name = "cmbParity"; this.cmbParity.Name = "cmbParity";
this.cmbParity.Size = new System.Drawing.Size(132, 24); this.cmbParity.Size = new System.Drawing.Size(100, 22);
this.cmbParity.TabIndex = 69; this.cmbParity.TabIndex = 69;
// //
// btOpenCOM // btOpenCOM
// //
this.btOpenCOM.Font = new System.Drawing.Font("Arial", 8F); this.btOpenCOM.Font = new System.Drawing.Font("Arial", 8F);
this.btOpenCOM.Location = new System.Drawing.Point(311, 130); this.btOpenCOM.Location = new System.Drawing.Point(233, 104);
this.btOpenCOM.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btOpenCOM.Name = "btOpenCOM"; this.btOpenCOM.Name = "btOpenCOM";
this.btOpenCOM.Size = new System.Drawing.Size(104, 29); this.btOpenCOM.Size = new System.Drawing.Size(78, 23);
this.btOpenCOM.TabIndex = 71; this.btOpenCOM.TabIndex = 71;
this.btOpenCOM.Text = "Open"; this.btOpenCOM.Text = "Open";
this.btOpenCOM.Click += new System.EventHandler(this.btOpenCOM_Click); this.btOpenCOM.Click += new System.EventHandler(this.btOpenCOM_Click);
...@@ -118,19 +114,17 @@ ...@@ -118,19 +114,17 @@
this.cmbDataBit.Items.AddRange(new object[] { this.cmbDataBit.Items.AddRange(new object[] {
"7", "7",
"8"}); "8"});
this.cmbDataBit.Location = new System.Drawing.Point(236, 98); this.cmbDataBit.Location = new System.Drawing.Point(177, 78);
this.cmbDataBit.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.cmbDataBit.Name = "cmbDataBit"; this.cmbDataBit.Name = "cmbDataBit";
this.cmbDataBit.Size = new System.Drawing.Size(63, 24); this.cmbDataBit.Size = new System.Drawing.Size(48, 22);
this.cmbDataBit.TabIndex = 68; this.cmbDataBit.TabIndex = 68;
// //
// labStopBit // labStopBit
// //
this.labStopBit.Font = new System.Drawing.Font("Arial", 8F); this.labStopBit.Font = new System.Drawing.Font("Arial", 8F);
this.labStopBit.Location = new System.Drawing.Point(461, 79); this.labStopBit.Location = new System.Drawing.Point(346, 63);
this.labStopBit.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labStopBit.Name = "labStopBit"; this.labStopBit.Name = "labStopBit";
this.labStopBit.Size = new System.Drawing.Size(75, 19); this.labStopBit.Size = new System.Drawing.Size(56, 15);
this.labStopBit.TabIndex = 73; this.labStopBit.TabIndex = 73;
this.labStopBit.Text = "Stop Bit"; this.labStopBit.Text = "Stop Bit";
this.labStopBit.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.labStopBit.TextAlign = System.Drawing.ContentAlignment.TopCenter;
...@@ -138,10 +132,9 @@ ...@@ -138,10 +132,9 @@
// labParity // labParity
// //
this.labParity.Font = new System.Drawing.Font("Arial", 8F); this.labParity.Font = new System.Drawing.Font("Arial", 8F);
this.labParity.Location = new System.Drawing.Point(313, 79); this.labParity.Location = new System.Drawing.Point(235, 63);
this.labParity.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labParity.Name = "labParity"; this.labParity.Name = "labParity";
this.labParity.Size = new System.Drawing.Size(131, 19); this.labParity.Size = new System.Drawing.Size(98, 15);
this.labParity.TabIndex = 74; this.labParity.TabIndex = 74;
this.labParity.Text = "Parity"; this.labParity.Text = "Parity";
this.labParity.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.labParity.TextAlign = System.Drawing.ContentAlignment.TopCenter;
...@@ -149,10 +142,9 @@ ...@@ -149,10 +142,9 @@
// labBaud // labBaud
// //
this.labBaud.Font = new System.Drawing.Font("Arial", 8F); this.labBaud.Font = new System.Drawing.Font("Arial", 8F);
this.labBaud.Location = new System.Drawing.Point(124, 79); this.labBaud.Location = new System.Drawing.Point(93, 63);
this.labBaud.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labBaud.Name = "labBaud"; this.labBaud.Name = "labBaud";
this.labBaud.Size = new System.Drawing.Size(100, 19); this.labBaud.Size = new System.Drawing.Size(75, 15);
this.labBaud.TabIndex = 75; this.labBaud.TabIndex = 75;
this.labBaud.Text = "Baudrate"; this.labBaud.Text = "Baudrate";
this.labBaud.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.labBaud.TextAlign = System.Drawing.ContentAlignment.TopCenter;
...@@ -160,10 +152,9 @@ ...@@ -160,10 +152,9 @@
// labDataBit // labDataBit
// //
this.labDataBit.Font = new System.Drawing.Font("Arial", 8F); this.labDataBit.Font = new System.Drawing.Font("Arial", 8F);
this.labDataBit.Location = new System.Drawing.Point(236, 79); this.labDataBit.Location = new System.Drawing.Point(177, 63);
this.labDataBit.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labDataBit.Name = "labDataBit"; this.labDataBit.Name = "labDataBit";
this.labDataBit.Size = new System.Drawing.Size(64, 19); this.labDataBit.Size = new System.Drawing.Size(48, 15);
this.labDataBit.TabIndex = 76; this.labDataBit.TabIndex = 76;
this.labDataBit.Text = "Data Bit"; this.labDataBit.Text = "Data Bit";
this.labDataBit.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.labDataBit.TextAlign = System.Drawing.ContentAlignment.TopCenter;
...@@ -180,19 +171,17 @@ ...@@ -180,19 +171,17 @@
"38400", "38400",
"57600", "57600",
"115200"}); "115200"});
this.cmbBaud.Location = new System.Drawing.Point(123, 98); this.cmbBaud.Location = new System.Drawing.Point(92, 78);
this.cmbBaud.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.cmbBaud.Name = "cmbBaud"; this.cmbBaud.Name = "cmbBaud";
this.cmbBaud.Size = new System.Drawing.Size(100, 24); this.cmbBaud.Size = new System.Drawing.Size(76, 22);
this.cmbBaud.TabIndex = 67; this.cmbBaud.TabIndex = 67;
// //
// labPort // labPort
// //
this.labPort.Font = new System.Drawing.Font("Arial", 8F); this.labPort.Font = new System.Drawing.Font("Arial", 8F);
this.labPort.Location = new System.Drawing.Point(16, 79); this.labPort.Location = new System.Drawing.Point(12, 63);
this.labPort.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.labPort.Name = "labPort"; this.labPort.Name = "labPort";
this.labPort.Size = new System.Drawing.Size(100, 19); this.labPort.Size = new System.Drawing.Size(75, 15);
this.labPort.TabIndex = 66; this.labPort.TabIndex = 66;
this.labPort.Text = "COM Port"; this.labPort.Text = "COM Port";
this.labPort.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.labPort.TextAlign = System.Drawing.ContentAlignment.TopCenter;
...@@ -200,32 +189,30 @@ ...@@ -200,32 +189,30 @@
// cmbPort // cmbPort
// //
this.cmbPort.Font = new System.Drawing.Font("Arial", 8F); this.cmbPort.Font = new System.Drawing.Font("Arial", 8F);
this.cmbPort.Location = new System.Drawing.Point(16, 98); this.cmbPort.Location = new System.Drawing.Point(12, 78);
this.cmbPort.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.cmbPort.Name = "cmbPort"; this.cmbPort.Name = "cmbPort";
this.cmbPort.Size = new System.Drawing.Size(99, 24); this.cmbPort.Size = new System.Drawing.Size(75, 22);
this.cmbPort.TabIndex = 65; this.cmbPort.TabIndex = 65;
// //
// label7 // label7
// //
this.label7.Font = new System.Drawing.Font("Arial", 8F); this.label7.Font = new System.Drawing.Font("Arial", 8F);
this.label7.ForeColor = System.Drawing.Color.Blue; this.label7.ForeColor = System.Drawing.Color.Blue;
this.label7.Location = new System.Drawing.Point(16, 58); this.label7.Location = new System.Drawing.Point(12, 46);
this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label7.Name = "label7"; this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(187, 21); this.label7.Size = new System.Drawing.Size(140, 17);
this.label7.TabIndex = 64; this.label7.TabIndex = 64;
this.label7.Text = "Connection Status"; this.label7.Text = "Connection Status";
// //
// txtReceiveMessage // txtReceiveMessage
// //
this.txtReceiveMessage.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.txtReceiveMessage.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtReceiveMessage.Location = new System.Drawing.Point(563, 14); this.txtReceiveMessage.Location = new System.Drawing.Point(422, 11);
this.txtReceiveMessage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.txtReceiveMessage.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.txtReceiveMessage.Multiline = true; this.txtReceiveMessage.Multiline = true;
this.txtReceiveMessage.Name = "txtReceiveMessage"; this.txtReceiveMessage.Name = "txtReceiveMessage";
this.txtReceiveMessage.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txtReceiveMessage.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtReceiveMessage.Size = new System.Drawing.Size(677, 660); this.txtReceiveMessage.Size = new System.Drawing.Size(509, 529);
this.txtReceiveMessage.TabIndex = 77; this.txtReceiveMessage.TabIndex = 77;
this.txtReceiveMessage.TextChanged += new System.EventHandler(this.txtReceiveMessage_TextChanged); this.txtReceiveMessage.TextChanged += new System.EventHandler(this.txtReceiveMessage_TextChanged);
// //
...@@ -237,40 +224,35 @@ ...@@ -237,40 +224,35 @@
this.updateops.Controls.Add(this.label13); this.updateops.Controls.Add(this.label13);
this.updateops.Controls.Add(this.UpdateBar); this.updateops.Controls.Add(this.UpdateBar);
this.updateops.Controls.Add(this.UpdateBtn); this.updateops.Controls.Add(this.UpdateBtn);
this.updateops.Location = new System.Drawing.Point(20, 218); this.updateops.Location = new System.Drawing.Point(15, 174);
this.updateops.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.updateops.Name = "updateops"; this.updateops.Name = "updateops";
this.updateops.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); this.updateops.Size = new System.Drawing.Size(387, 111);
this.updateops.Size = new System.Drawing.Size(516, 139);
this.updateops.TabIndex = 92; this.updateops.TabIndex = 92;
this.updateops.TabStop = false; this.updateops.TabStop = false;
this.updateops.Text = "更新操作"; this.updateops.Text = "更新操作";
// //
// imagesname // imagesname
// //
this.imagesname.Location = new System.Drawing.Point(75, 88); this.imagesname.Location = new System.Drawing.Point(56, 70);
this.imagesname.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.imagesname.Name = "imagesname"; this.imagesname.Name = "imagesname";
this.imagesname.Size = new System.Drawing.Size(144, 15); this.imagesname.Size = new System.Drawing.Size(108, 12);
this.imagesname.TabIndex = 5; this.imagesname.TabIndex = 5;
this.imagesname.Text = "wtd.bin"; this.imagesname.Text = "wtd.bin";
// //
// label12 // label12
// //
this.label12.AutoSize = true; this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(21, 88); this.label12.Location = new System.Drawing.Point(16, 70);
this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label12.Name = "label12"; this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(52, 15); this.label12.Size = new System.Drawing.Size(41, 12);
this.label12.TabIndex = 4; this.label12.TabIndex = 4;
this.label12.Text = "镜像:"; this.label12.Text = "镜像:";
// //
// choosebth // choosebth
// //
this.choosebth.Location = new System.Drawing.Point(243, 81); this.choosebth.Location = new System.Drawing.Point(182, 65);
this.choosebth.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.choosebth.Name = "choosebth"; this.choosebth.Name = "choosebth";
this.choosebth.Size = new System.Drawing.Size(100, 29); this.choosebth.Size = new System.Drawing.Size(75, 23);
this.choosebth.TabIndex = 3; this.choosebth.TabIndex = 3;
this.choosebth.Text = "选择bin"; this.choosebth.Text = "选择bin";
this.choosebth.UseVisualStyleBackColor = true; this.choosebth.UseVisualStyleBackColor = true;
...@@ -279,27 +261,24 @@ ...@@ -279,27 +261,24 @@
// label13 // label13
// //
this.label13.AutoSize = true; this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(21, 32); this.label13.Location = new System.Drawing.Point(16, 26);
this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label13.Name = "label13"; this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(52, 15); this.label13.Size = new System.Drawing.Size(41, 12);
this.label13.TabIndex = 2; this.label13.TabIndex = 2;
this.label13.Text = "进度:"; this.label13.Text = "进度:";
// //
// UpdateBar // UpdateBar
// //
this.UpdateBar.Location = new System.Drawing.Point(77, 25); this.UpdateBar.Location = new System.Drawing.Point(58, 20);
this.UpdateBar.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.UpdateBar.Name = "UpdateBar"; this.UpdateBar.Name = "UpdateBar";
this.UpdateBar.Size = new System.Drawing.Size(373, 29); this.UpdateBar.Size = new System.Drawing.Size(280, 23);
this.UpdateBar.TabIndex = 1; this.UpdateBar.TabIndex = 1;
// //
// UpdateBtn // UpdateBtn
// //
this.UpdateBtn.Location = new System.Drawing.Point(351, 81); this.UpdateBtn.Location = new System.Drawing.Point(263, 65);
this.UpdateBtn.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.UpdateBtn.Name = "UpdateBtn"; this.UpdateBtn.Name = "UpdateBtn";
this.UpdateBtn.Size = new System.Drawing.Size(100, 29); this.UpdateBtn.Size = new System.Drawing.Size(75, 23);
this.UpdateBtn.TabIndex = 0; this.UpdateBtn.TabIndex = 0;
this.UpdateBtn.Text = "一键更新"; this.UpdateBtn.Text = "一键更新";
this.UpdateBtn.UseVisualStyleBackColor = true; this.UpdateBtn.UseVisualStyleBackColor = true;
...@@ -314,10 +293,9 @@ ...@@ -314,10 +293,9 @@
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(44, 446); this.label1.Location = new System.Drawing.Point(33, 357);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(69, 20); this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 93; this.label1.TabIndex = 93;
this.label1.Text = "温度:"; this.label1.Text = "温度:";
// //
...@@ -325,39 +303,35 @@ ...@@ -325,39 +303,35 @@
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(44, 488); this.label2.Location = new System.Drawing.Point(33, 390);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 20); this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 94; this.label2.TabIndex = 94;
this.label2.Text = "水位:"; this.label2.Text = "水位:";
// //
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(108, 451); this.label3.Location = new System.Drawing.Point(81, 361);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(55, 15); this.label3.Size = new System.Drawing.Size(41, 12);
this.label3.TabIndex = 95; this.label3.TabIndex = 95;
this.label3.Text = "label3"; this.label3.Text = "label3";
// //
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(108, 492); this.label4.Location = new System.Drawing.Point(81, 394);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 15); this.label4.Size = new System.Drawing.Size(41, 12);
this.label4.TabIndex = 96; this.label4.TabIndex = 96;
this.label4.Text = "label4"; this.label4.Text = "label4";
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(371, 476); this.button2.Location = new System.Drawing.Point(278, 381);
this.button2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 29); this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 97; this.button2.TabIndex = 97;
this.button2.Text = "test"; this.button2.Text = "test";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
...@@ -365,10 +339,9 @@ ...@@ -365,10 +339,9 @@
// //
// SubscribeBut // SubscribeBut
// //
this.SubscribeBut.Location = new System.Drawing.Point(371, 432); this.SubscribeBut.Location = new System.Drawing.Point(278, 346);
this.SubscribeBut.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.SubscribeBut.Name = "SubscribeBut"; this.SubscribeBut.Name = "SubscribeBut";
this.SubscribeBut.Size = new System.Drawing.Size(100, 29); this.SubscribeBut.Size = new System.Drawing.Size(75, 23);
this.SubscribeBut.TabIndex = 98; this.SubscribeBut.TabIndex = 98;
this.SubscribeBut.Text = "订阅消息"; this.SubscribeBut.Text = "订阅消息";
this.SubscribeBut.UseVisualStyleBackColor = true; this.SubscribeBut.UseVisualStyleBackColor = true;
...@@ -377,26 +350,28 @@ ...@@ -377,26 +350,28 @@
// label5 // label5
// //
this.label5.AutoSize = true; this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(111, 528); this.label5.Location = new System.Drawing.Point(83, 422);
this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(55, 15); this.label5.Size = new System.Drawing.Size(41, 12);
this.label5.TabIndex = 99; this.label5.TabIndex = 99;
this.label5.Text = "label5"; this.label5.Text = "label5";
// //
// label6 // label6
// //
this.label6.AutoSize = true; this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(23, 528); this.label6.Location = new System.Drawing.Point(17, 422);
this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label6.Name = "label6"; this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(82, 15); this.label6.Size = new System.Drawing.Size(65, 12);
this.label6.TabIndex = 100; this.label6.TabIndex = 100;
this.label6.Text = "超时次数:"; this.label6.Text = "超时次数:";
// //
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1256, 689); this.ClientSize = new System.Drawing.Size(942, 551);
this.Controls.Add(this.label6); this.Controls.Add(this.label6);
this.Controls.Add(this.label5); this.Controls.Add(this.label5);
this.Controls.Add(this.SubscribeBut); this.Controls.Add(this.SubscribeBut);
...@@ -421,7 +396,6 @@ ...@@ -421,7 +396,6 @@
this.Controls.Add(this.cmbPort); this.Controls.Add(this.cmbPort);
this.Controls.Add(this.label7); this.Controls.Add(this.label7);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "牧场项目"; this.Text = "牧场项目";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
......
...@@ -63,6 +63,9 @@ namespace ModbusDemo ...@@ -63,6 +63,9 @@ namespace ModbusDemo
t_UpgradeConn = new Thread(UpgradeProc); t_UpgradeConn = new Thread(UpgradeProc);
t_UpgradeConn.IsBackground = true; t_UpgradeConn.IsBackground = true;
t_UpgradeConn.Start(); t_UpgradeConn.Start();
Thread AutoControl = new Thread(Auto_Control);
AutoControl.Start();
} }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{ {
...@@ -412,7 +415,7 @@ namespace ModbusDemo ...@@ -412,7 +415,7 @@ namespace ModbusDemo
totxt.Log($">> Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}{Environment.NewLine}"); totxt.Log($">> Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}{Environment.NewLine}");
stConvertString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); stConvertString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
Console.WriteLine(stConvertString); Console.WriteLine(stConvertString);
ModualControl.vGetaWay_Receive_Control(stConvertString); //ModualControl.vGetaWay_Receive_Control(stConvertString);
Ctrl ctrl = JsonConvert.DeserializeObject<Ctrl>(Encoding.UTF8.GetString(e.ApplicationMessage.Payload)); Ctrl ctrl = JsonConvert.DeserializeObject<Ctrl>(Encoding.UTF8.GetString(e.ApplicationMessage.Payload));
Ctrl ctrl_Back = new Ctrl(); Ctrl ctrl_Back = new Ctrl();
Ctrl2 ctrl2 = new Ctrl2(); Ctrl2 ctrl2 = new Ctrl2();
...@@ -530,6 +533,14 @@ namespace ModbusDemo ...@@ -530,6 +533,14 @@ namespace ModbusDemo
#endregion #endregion
#region modbus线程 #region modbus线程
//自动控制
private void Auto_Control()
{
AutoControl.Control control_new = new AutoControl.Control();
//东中转池的数据
AutoControl.CriticalValueMonitoring(true, 6.5, 2, ModualPoll.cx18x.sX18xDataStruct[0].dNowConvertData[0], "东中转池", out control_new);
}
private static bool bSetDataIsRunning = false; private static bool bSetDataIsRunning = false;
private Thread ModbusPollThread; private Thread ModbusPollThread;
private bool bModbusPollThreadStart = false; private bool bModbusPollThreadStart = false;
...@@ -603,14 +614,8 @@ namespace ModbusDemo ...@@ -603,14 +614,8 @@ namespace ModbusDemo
bSetDataIsRunning = false; bSetDataIsRunning = false;
} }
} }
<<<<<<< HEAD
} }
#region PoolTest #region PoolTest
=======
}
#region PoolTest
>>>>>>> ae9d62a8c8c10f8339da24024e6330c7ac4ff704
#endregion #endregion
//声明委托 //声明委托
...@@ -1167,6 +1172,7 @@ namespace ModbusDemo ...@@ -1167,6 +1172,7 @@ namespace ModbusDemo
private void txtReceiveMessage_TextChanged(object sender, EventArgs e) private void txtReceiveMessage_TextChanged(object sender, EventArgs e)
{ {
if (txtReceiveMessage.TextLength > 3000) if (txtReceiveMessage.TextLength > 3000)
{ {
txtReceiveMessage.Text = "0"; txtReceiveMessage.Text = "0";
...@@ -1175,8 +1181,26 @@ namespace ModbusDemo ...@@ -1175,8 +1181,26 @@ namespace ModbusDemo
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
ModualPoll.vAllNodePoll(); AutoControl.Control control = new AutoControl.Control();
mqttData=ModualPoll.stAll_Poll_Package(); for (double i = 0; i < 7; i++)
{
AutoControl.CriticalValueMonitoring(true, 6.5, 2, i, "东中转池", out control);
Console.WriteLine(control.Name);
Console.WriteLine(control.maxLevel);
Console.WriteLine(control.minLevel);
Console.WriteLine(control.Enablation);
Console.WriteLine(control.realTimeLevel);
Console.WriteLine(control.status);
Console.WriteLine(control.Beyond_the_limit);
Console.WriteLine(control.Minimum_Early_Warning);
Console.WriteLine(control.normal);
Console.WriteLine(control.StatusTime);
}
//ModualPoll.cx18x.sX18xDataStruct[0].dNowConvertData[0]
//返回状态
//调用modbus读写线圈
//调用modbus异常报警
} }
private async void SubscribeBut_Click(object sender, EventArgs e) private async void SubscribeBut_Click(object sender, EventArgs e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment