调整通信逻辑
This commit is contained in:
commit
c5a02416fb
5 files changed
+51
-38
No files matched your search
@@ -26,6 +26,8 @@ using static DyeingComputer.Windows.ViewStep;
|
||||
using System.Windows.Media;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace DyeingComputer.ViewModel
|
||||
@@ -236,22 +238,10 @@ namespace DyeingComputer.ViewModel
|
||||
public static string ProgramName = "-----";//工艺名
|
||||
public static Int32 DIDETime; //空闲计时器
|
||||
bool ERR_JOG;//故障状态
|
||||
private int timer1s_ = 0;
|
||||
private int timer5s_ = 0;
|
||||
public void CountDown()
|
||||
{
|
||||
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(1)//秒
|
||||
};
|
||||
timer1s.Tick += Tick_Event_1S;
|
||||
timer1s.Start();
|
||||
|
||||
DispatcherTimer timer5s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(5)//
|
||||
};
|
||||
timer5s.Tick += Tick_Event_5S;
|
||||
timer5s.Start();
|
||||
|
||||
//设置定时器
|
||||
DispatcherTimer disTimer = new DispatcherTimer
|
||||
{
|
||||
@@ -260,7 +250,7 @@ namespace DyeingComputer.ViewModel
|
||||
disTimer.Tick += DisTimer_200MS;
|
||||
disTimer.Start();//计时开始
|
||||
}//时间周期初始化
|
||||
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
||||
void Tick_Event_1S()//Tick_Event周期执行事件1S
|
||||
{
|
||||
SYSTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
Sys_Time = SYSTime.ToString();
|
||||
@@ -287,18 +277,22 @@ namespace DyeingComputer.ViewModel
|
||||
Alert_bell = !Alert_bell;
|
||||
}
|
||||
}
|
||||
void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S
|
||||
void Tick_Event_5S()//Tick_Event周期执行事件5S
|
||||
{
|
||||
if (!LINK_OK) Modbus_link();
|
||||
|
||||
if(WORK_RUN !=0) Chart();//写入记录
|
||||
//if(WORK_RUN !=0)
|
||||
Chart();//写入记录
|
||||
|
||||
if (string.IsNullOrEmpty(Name_err.ToString()) && ((Selet_dtm("1010") < 1) || (Selet_dtm("1010") > 160)))
|
||||
{ Name_err = Resources.Temperature + Resources.Sensor + Resources.Malfunction; } //温度故障提示
|
||||
}
|
||||
void DisTimer_200MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
|
||||
void DisTimer_200MS(object sender, EventArgs e)//Tick_Event周期执行事件200MS
|
||||
{
|
||||
if (LINK_OK) Modbus_link();
|
||||
timer1s_++;
|
||||
timer5s_++;
|
||||
|
||||
if (timer1s_ > 5) Tick_Event_1S();
|
||||
if (timer5s_ > 25) Tick_Event_5S();
|
||||
|
||||
if (LINK_OK) IO_data();
|
||||
|
||||
if (!string.IsNullOrEmpty(Name_err.ToString()) && (!ERR_JOG)) //有故障信息,无故障保持
|
||||
@@ -312,7 +306,7 @@ namespace DyeingComputer.ViewModel
|
||||
LogGing.LogGingDATA(Name_err.ToString() + "=>" + Resources.FailureRecovery);//解除故障信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Chart()
|
||||
{
|
||||
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
|
||||
@@ -1440,9 +1434,10 @@ namespace DyeingComputer.ViewModel
|
||||
port.DataBits = 8;
|
||||
port.Parity = Parity.None;
|
||||
port.StopBits = StopBits.One;
|
||||
port.ReadTimeout = 100;
|
||||
port.WriteTimeout = 100;
|
||||
port.ReadTimeout = 1000;
|
||||
port.WriteTimeout = 1000;
|
||||
port.Open();//打开串口
|
||||
Modbus_link();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -1471,15 +1466,15 @@ namespace DyeingComputer.ViewModel
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
LINK_RUN++;
|
||||
try
|
||||
{
|
||||
master.WriteMultipleCoils(slaveId, 02000, DQ); //写入线圈
|
||||
master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器
|
||||
DO = master.ReadCoils(slaveId, 02255, DO_L); //读取线圈
|
||||
RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器
|
||||
RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器
|
||||
master.WriteMultipleCoils(slaveId, 02000, DQ); //写入线圈
|
||||
master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器
|
||||
LINK_OK = true;
|
||||
Name_err = "";
|
||||
LINK_RUN++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1487,10 +1482,13 @@ namespace DyeingComputer.ViewModel
|
||||
LINK_ERR++;
|
||||
Name_err = "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")";
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
Modbus_link();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}//发送
|
||||
public static string SYSlog;
|
||||
void LOG_view()//细节页面
|
||||
{
|
||||
@@ -1499,7 +1497,7 @@ namespace DyeingComputer.ViewModel
|
||||
SYSlog = SYSlog + "\n" + Resources.Compute + Resources.Temperature + " : " + string.Format(" {0:###.#}", Convert.ToDouble(Selet_dtm("1005"))) + "°C";//显示计算温度
|
||||
SYSlog = SYSlog + " | " + Resources.ProportionalValves + " : " + string.Format("{0:###.#}", Convert.ToDouble(Selet_dtm("1004")) / 10) + "%";//显示比例
|
||||
int IO1015 = Convert.ToInt16(Selet_dtm("1015"));
|
||||
if (IO1015 < MT39)
|
||||
if (IO1015 <= MT39)
|
||||
{
|
||||
SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.Low_waterlevel + "]";//显示水位
|
||||
}
|
||||
@@ -1507,7 +1505,7 @@ namespace DyeingComputer.ViewModel
|
||||
{
|
||||
SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.Mid_waterlevel + "]";//显示水位
|
||||
}
|
||||
else if (IO1015 > MT38)
|
||||
else if (IO1015 >= MT38)
|
||||
{
|
||||
SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.High_waterlevel + "]";//显示水位
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user