Commit ff16860c authored by leon.huang's avatar leon.huang

modify data

parent 468680e9
This diff is collapsed.
...@@ -11,7 +11,7 @@ namespace ModbusDemo.application ...@@ -11,7 +11,7 @@ namespace ModbusDemo.application
public static class AllPond public static class AllPond
{ {
private static ModualPool.pcTemperature cEastTransitPoolTemper = new ModualPool.pcTemperature("EastTransitPoolTemper", 27, "d0"); private static ModualPool.pcTemperature cEastTransitPoolTemper = new ModualPool.pcTemperature("EastTransitPoolTemper", 27, "d0");
private static ModualPool.pcLiquidlevel cEastTransitPoolLevel = new ModualPool.pcLiquidlevel("EastTransitPoolLevel", 13, "d0"); private static ModualPool.pcLiquidlevel cEastTransitPoolLevel = new ModualPool.pcLiquidlevel("EastTransitPoolLevel", 13, "d2");
private static ModualPool.pcOperation cEastTransitPoolSouthWaterBase = new ModualPool.pcOperation private static ModualPool.pcOperation cEastTransitPoolSouthWaterBase = new ModualPool.pcOperation
{ {
byModbusID = 31, byModbusID = 31,
...@@ -19,9 +19,9 @@ namespace ModbusDemo.application ...@@ -19,9 +19,9 @@ namespace ModbusDemo.application
strChannelNumber = new string[] { "d1","d2" }, strChannelNumber = new string[] { "d1","d2" },
bOpenOperation = new bool[] { true,true }, bOpenOperation = new bool[] { true,true },
bCloseOperation = new bool[] { false,false }, bCloseOperation = new bool[] { false,false },
bHadRefControl = true, bHadRefControl = false,
byResModbusID = 13, byResModbusID = 0,
strResChannelNumber = "d0" strResChannelNumber = null
}; };
private static ModualPool.pcMachine cEastTransitPoolSouthWater = new ModualPool.pcMachine("EastTransitPoolSouthWater", cEastTransitPoolSouthWaterBase); private static ModualPool.pcMachine cEastTransitPoolSouthWater = new ModualPool.pcMachine("EastTransitPoolSouthWater", cEastTransitPoolSouthWaterBase);
...@@ -131,7 +131,7 @@ namespace ModbusDemo.application ...@@ -131,7 +131,7 @@ namespace ModbusDemo.application
public static class cEastTransitPool public static class cEastTransitPool
{ {
public static double vSetMaxLevel; public static double vSetMaxLevel;
public static double vSetMinLevel; public static double vSetMinLevel;
public static ModualPool.pcTemperature cTemper { get => cEastTransitPoolTemper; set => cEastTransitPoolTemper = value;} public static ModualPool.pcTemperature cTemper { get => cEastTransitPoolTemper; set => cEastTransitPoolTemper = value;}
public static ModualPool.pcLiquidlevel cLevel { get => cEastTransitPoolLevel; set => cEastTransitPoolLevel = value;} public static ModualPool.pcLiquidlevel cLevel { get => cEastTransitPoolLevel; set => cEastTransitPoolLevel = value;}
...@@ -144,15 +144,7 @@ namespace ModbusDemo.application ...@@ -144,15 +144,7 @@ namespace ModbusDemo.application
public static ModualPool.pcMachine cStirrer3 {get => cEastTransitPoolStirrer3; set => cEastTransitPoolStirrer3 = value; } public static ModualPool.pcMachine cStirrer3 {get => cEastTransitPoolStirrer3; set => cEastTransitPoolStirrer3 = value; }
public static ModualPool.pcMachine cStirrer4 {get => cEastTransitPoolStirrer4; set => cEastTransitPoolStirrer4 = value; } public static ModualPool.pcMachine cStirrer4 {get => cEastTransitPoolStirrer4; set => cEastTransitPoolStirrer4 = value; }
public static ModualPool.pcButton cButton1 {get => cEastTransitPoolButton1; set => cEastTransitPoolButton1 = value; } public static ModualPool.pcButton cButton1 {get => cEastTransitPoolButton1; set => cEastTransitPoolButton1 = value; }
private static void vSet_Poll_Max_Level(double dData)
{
vSetMaxLevel = dData;
}
private static void vSet_Poll_Min_Level(double dData)
{
vSetMinLevel = dData;
}
} }
......
...@@ -38,7 +38,7 @@ namespace ModbusDemo.application ...@@ -38,7 +38,7 @@ namespace ModbusDemo.application
public int modularx; public int modularx;
public byte modbusID; public byte modbusID;
} }
public static byte[] EmodbusId = { 5, 51 }; public static byte[] EmodbusId = { 16, 51 };
public static byte[] WmodbusId = { 35, 31 }; public static byte[] WmodbusId = { 35, 31 };
public static byte[] LevelmodbusID = { 6, 13 }; public static byte[] LevelmodbusID = { 6, 13 };
public static bool[] state_ON = { true, true, true, true, true, true }; public static bool[] state_ON = { true, true, true, true, true, true };
...@@ -47,7 +47,7 @@ namespace ModbusDemo.application ...@@ -47,7 +47,7 @@ namespace ModbusDemo.application
public static bool Wtimerun = false; public static bool Wtimerun = false;
static System.Diagnostics.Stopwatch ETime = new System.Diagnostics.Stopwatch(); static System.Diagnostics.Stopwatch ETime = new System.Diagnostics.Stopwatch();
static System.Diagnostics.Stopwatch WTime = new System.Diagnostics.Stopwatch(); static System.Diagnostics.Stopwatch WTime = new System.Diagnostics.Stopwatch();
private static readonly int Runtimeout = 1; private static readonly int Runtimeout = 10;
public static void CriticalValueMonitoring(ref Control usControl,bool Enabl, string Affiliation, out Control control) public static void CriticalValueMonitoring(ref Control usControl,bool Enabl, string Affiliation, out Control control)
{ {
......
...@@ -58,4 +58,53 @@ namespace ModbusDemo.application ...@@ -58,4 +58,53 @@ namespace ModbusDemo.application
f.WriteContentValue(section, key, value); f.WriteContentValue(section, key, value);
} }
} }
public class pcConfig
{
public static string FileName = Application.StartupPath + "\\PoolConfig.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);
}
}
} }
...@@ -15,8 +15,8 @@ namespace ModbusDemo.application ...@@ -15,8 +15,8 @@ namespace ModbusDemo.application
{ {
private string strTemperName; private string strTemperName;
public double dCurrentTemperate { get => vGet_ResCurrent();} public double dCurrentTemperate { get => vGet_ResCurrent();}
private byte byModbusID; public byte byModbusID;
private string[] strChannelNumber; public string[] strChannelNumber;
public pcTemperature(string strName,byte byModbusID, params string[] strChannelNumber) public pcTemperature(string strName,byte byModbusID, params string[] strChannelNumber)
{ {
this.strTemperName = strName; this.strTemperName = strName;
...@@ -50,8 +50,8 @@ namespace ModbusDemo.application ...@@ -50,8 +50,8 @@ namespace ModbusDemo.application
{ {
private string strLevel; private string strLevel;
public double dCurrentlevel { get => vGet_ResCurrent();} public double dCurrentlevel { get => vGet_ResCurrent();}
private byte byModbusID; public byte byModbusID;
private string[] strChannelNumber; public string[] strChannelNumber;
public pcLiquidlevel(string strName, byte byModbusID,params string[] strChannelNumber) public pcLiquidlevel(string strName, byte byModbusID,params string[] strChannelNumber)
{ {
this.strLevel = strName; this.strLevel = strName;
...@@ -67,7 +67,7 @@ namespace ModbusDemo.application ...@@ -67,7 +67,7 @@ namespace ModbusDemo.application
List<double> ConvertData = new List<double>(); List<double> ConvertData = new List<double>();
for (int i = 0; i < dConvertData.Count(); i++) for (int i = 0; i < dConvertData.Count(); i++)
{ {
if (dConvertData[i] > 0 && dConvertData[i] < 5) if (dConvertData[i] > 0 && dConvertData[i] < 20)
{ {
ConvertData.Add(dConvertData[i]); ConvertData.Add(dConvertData[i]);
} }
......
...@@ -289,11 +289,11 @@ namespace ModbusDemo ...@@ -289,11 +289,11 @@ namespace ModbusDemo
//Reconnecting //Reconnecting
if (isReconnect) if (isReconnect)
{ {
Invoke((new Action(() => Invoke((new Action(async () =>
{ {
txtReceiveMessage.AppendText("正在尝试重新连接" + Environment.NewLine); txtReceiveMessage.AppendText("正在尝试重新连接" + Environment.NewLine);
totxt.Log("正在尝试重新连接" + Environment.NewLine); totxt.Log("正在尝试重新连接" + Environment.NewLine);
await Subscribe();
//Console.WriteLine("正在尝试重新连接" + Environment.NewLine); //Console.WriteLine("正在尝试重新连接" + Environment.NewLine);
}))); })));
...@@ -1061,17 +1061,11 @@ namespace ModbusDemo ...@@ -1061,17 +1061,11 @@ namespace ModbusDemo
ModbusComm.Modbus.Transport.ReadTimeout = 1000; ModbusComm.Modbus.Transport.ReadTimeout = 1000;
ModbusComm.Modbus.Transport.WriteTimeout = 1000; ModbusComm.Modbus.Transport.WriteTimeout = 1000;
ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0; ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0;
<<<<<<< HEAD
//t_AutoControl = new Thread(T_AutoControl); //t_AutoControl = new Thread(AtuoControl_run);
//t_AutoControl.IsBackground = true; //t_AutoControl.IsBackground = true;
//t_AutoControl.Start(); //t_AutoControl.Start();
=======
//t_AutoControl = new Thread(T_AutoControl)
//{
// IsBackground = true
//};
//t_AutoControl.Start();
modbus_Timer.Enabled = true; modbus_Timer.Enabled = true;
btOpenCOM.Enabled = false; btOpenCOM.Enabled = false;
...@@ -1110,7 +1104,7 @@ namespace ModbusDemo ...@@ -1110,7 +1104,7 @@ namespace ModbusDemo
} }
private async void run() private async void run()
{ {
comPort.PortName = "COM6"; comPort.PortName = "COM2";
comPort.BaudRate = 9600; comPort.BaudRate = 9600;
comPort.Parity = Parity.None; comPort.Parity = Parity.None;
comPort.StopBits = StopBits.One; comPort.StopBits = StopBits.One;
...@@ -1130,7 +1124,7 @@ namespace ModbusDemo ...@@ -1130,7 +1124,7 @@ namespace ModbusDemo
ModbusComm.Modbus.Transport.WriteTimeout = 1000; ModbusComm.Modbus.Transport.WriteTimeout = 1000;
ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0; ModbusComm.Modbus.Transport.WaitToRetryMilliseconds = 0;
//t_AutoControl = new Thread(T_AutoControl) //t_AutoControl = new Thread(AtuoControl_run)
//{ //{
// IsBackground = true // IsBackground = true
//}; //};
......
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