Commit 83d8d9d1 authored by leon.huang's avatar leon.huang

merge origin master

parents 7176757f 3fd90cd4
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();
}
}
}
......@@ -666,7 +666,6 @@ namespace ModbusDemo.MessageFormat
string strChannelString = "d" + i.ToString();
for (int j = 0; j < 8; j++)
{
if (jsonObj["ss"][i]["cfg"].Value<string>("name") == strChannelString)
{
cLiquidLevelConfig.stChannelNumber = strChannelString;
......
......@@ -2,20 +2,6 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<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>
<SSDTPath Condition="'$(SSDTPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130</SSDTPath>
......@@ -36,6 +22,20 @@
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<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 Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
......@@ -78,6 +78,7 @@
<HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -88,13 +89,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="application\AutoControl.cs" />
<Compile Include="application\InIHelper.cs" />
<Compile Include="application\PoolModbusSet.cs" />
<Compile Include="application\ModbusToPool.cs" />
<Compile Include="application\Pond.cs" />
<Compile Include="application\UsThread.cs" />
<Compile Include="Common\ModualAlarm.cs" />
<Compile Include="MessageFormat\ModualControl.cs" />
<Compile Include="Common\OperIni.cs" />
<Compile Include="MessageFormat\ModbusComm.cs" />
<Compile Include="MessageFormat\ModualControl.cs" />
<Compile Include="Modular\414P.cs" />
<Compile Include="Modular\478C.cs" />
<Compile Include="Modular\418X.cs" />
......@@ -167,15 +171,11 @@
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<!-- <SsdtUnitTestVersion>3.1</SsdtUnitTestVersion> -->
<!-- </PropertyGroup> -->
<!-- <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)' == ''" /> -->
<!-- <PropertyGroup> -->
<SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
</PropertyGroup>
<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)' == ''" />
<PropertyGroup>
<SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......

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 double maxLevel;
public double minLevel;
public double 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);
}
}
}
......@@ -36,6 +36,7 @@ namespace ModbusDemo.windows
public bool state;
public ushort[] current;//电流
public ushort[] Voltage;//电压
}
public class Level: ModbusAttribute //液位属性
......
This diff is collapsed.
......@@ -981,8 +981,43 @@ namespace ModbusDemo
private void button2_Click(object sender, EventArgs e)
{
ModualPoll.vAllNodePoll();
mqttData = ModualPoll.stAll_Poll_Package();
//AutoControl.Control usEcontrol = new AutoControl.Control();
//AutoControl.Control usWcontrol = new AutoControl.Control();
//if (ModualControl.cPoolLevelConfig.Count!=0)
//{
// for (int i = 0; i < ModualControl.cPoolLevelConfig.Count; i++)
// {
// if (ModualControl.cPoolLevelConfig[i].byModbusID == 6)
// {
// usWcontrol.maxLevel = ModualControl.cPoolLevelConfig[i].dUpLevel;
// usWcontrol.minLevel = ModualControl.cPoolLevelConfig[i].dDownLevel;
// usWcontrol.Name = "西·中转池";
// usWcontrol.Enablation = true;
// AutoControl.CriticalValueMonitoring(true, ModualControl.cPoolLevelConfig[1].dUpLevel,
// ModualControl.cPoolLevelConfig[0].dDownLevel, ModualPoll.cx18x.sX18xDataStruct[1].dNowConvertData[1],
// "西·中转池",
// out usWcontrol
// );
// }
// if (ModualControl.cPoolLevelConfig[i].byModbusID == 3)
// {
// usEcontrol.maxLevel = ModualControl.cPoolLevelConfig[i].dUpLevel;
// usEcontrol.minLevel = ModualControl.cPoolLevelConfig[i].dDownLevel;
// usEcontrol.Name = "东·中转池";
// usEcontrol.Enablation = true;
// AutoControl.CriticalValueMonitoring(true, ModualControl.cPoolLevelConfig[0].dUpLevel,
// ModualControl.cPoolLevelConfig[0].dDownLevel, ModualPoll.cx18x.sX18xDataStruct[0].dNowConvertData[0],
// "东·中转池",
// out usEcontrol
// );
// }
// }
//}
}
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