using CommonServiceLocator;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DyeingComputer.Properties;
using DyeingComputer.UserClass;
using DyeingComputer.View;
using DyeingComputer.Windows;
using Microsoft.Win32;
using Newtonsoft.Json.Linq;
using NModbus;
using NModbus.Serial;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting.Channels;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using TouchSocket.Sockets;
using OpenHardwareMonitor.Hardware;
namespace DyeingComputer.ViewModel
{
///
/// 变量传递至ui
///
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
if (propertyName != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
public class MainWindowViewModel : ViewModelBase
{
System.Windows.Media.Brush Status_red = new SolidColorBrush() { Color = System.Windows.Media.Color.FromArgb(255, 255, 0, 0) };
System.Windows.Media.Brush Status_Black = new SolidColorBrush() { Color = System.Windows.Media.Color.FromArgb(255, 0, 0, 0) };
// private static SQLiteHelper SQLiteHelpers = null; //定义数据库
//private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
private IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
private PID pid = new PID();
public static DataTable errTabler = new DataTable();//错误表
// public static DataTable RUN_DATATABLE = new DataTable();//缓存工作表
public static DataTable Dyelot_dat = new DataTable();//物料表
public static Dictionary Hardware =new Dictionary();
public static string Dyelot; //领料单号
public static int RUN_STEPID;//当前步骤
public static int SYS_REDYE=0;//当前重燃步
public static string SYSKEY;
public static UInt32 RX = 0;
public static UInt32 TX = 0;
public static int UserInfoStart = 900;
public static string UserInfo;
public static bool UserCall_OK = false;
public static int ViewID = 0;//页面id
public static object Name_err = "";
public static object SYSTime = "-----";
public static object WorkNumder = "-----";
public static object StatusStr = "-----";
public static object Process_step = "-----";
public static string ProgramName = "-----";//工艺名
public static Int32 DIDETime; //空闲计时器
public static bool ERR_JOG;//故障状态
private int timer1s_ = 0;
private int timer5s_ = 0;
private int timer60s_ = 0;
uint TX_t;//中央连接状态判断
public ICommand ProgramgroupView_stop { get; }
bool _isInteractive;
public bool IsInteractive//步骤表交互选择
{
get => _isInteractive;
set
{
_isInteractive = value;
OnPropertyChanged("IsInteractive");
}
}
public static bool _UserButton;
public bool UserButton//步骤按钮交互选择
{
get => _UserButton;
set
{
_UserButton = value;
OnPropertyChanged("UserButton");
}
}//定义的委托
public static bool _Lock_bool;
Visibility _Lock_bool_xml;
public Visibility Lock_bool//锁图标
{
get => _Lock_bool_xml;
set
{
_Lock_bool_xml = value;
OnPropertyChanged("Lock_bool");
}
}
bool _Link_bool;
Visibility _Link_bool_xml;
public Visibility Link_bool//连接图标
{
get => _Link_bool_xml;
set
{
_Link_bool_xml = value;
OnPropertyChanged("Link_bool");
}
}
public static bool _AUTO_bool;
bool AUTO_bool_xml; //显示手自动状态
public bool AUTO_bool //
{
get => AUTO_bool_xml;
set
{
AUTO_bool_xml = value;
OnPropertyChanged("AUTO_bool");
}
}
System.Windows.Media.Brush Status_str_coloer;
public System.Windows.Media.Brush Status_Str_coloer
{
get => Status_str_coloer;
set
{
Status_str_coloer = value;
OnPropertyChanged("Status_Str_coloer");
}
}
public int wORK_run; //显示状态
public int WORK_run //通知UI控件参数改变
{
get { return wORK_run; }
set { wORK_run = value; OnPropertyChanged("WORK_run"); }
}
public string work_Temp; //显示温度
public string Work_Temp //通知UI控件参数改变
{
get { return work_Temp; }
set { work_Temp = value; OnPropertyChanged("Work_Temp"); }
}
public string work_Numder; //显示工单号
public string Work_Numder //通知UI控件参数改变
{
get { return work_Numder; }
set { work_Numder = value; OnPropertyChanged("Work_Numder"); }
}
public string status_Str = "-"; //显示状态
public string Status_Str //通知UI控件参数改变
{
get { return status_Str; }
set { status_Str = value; OnPropertyChanged("Status_Str"); }
}
public string sys_Time; //显示系统时间
public string Sys_Time //通知UI控件参数改变
{
get { return sys_Time; }
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
}
public int sys_workSTEPID; //
public int Sys_workSTEPID //通知UI控件参数改变
{
get { return sys_workSTEPID; }
set { sys_workSTEPID = value; OnPropertyChanged("Sys_workSTEPID"); }
}
public string sys_log; //
public string Sys_log //通知UI控件参数改变
{
get { return sys_log; }
set { sys_log = value; OnPropertyChanged("Sys_log"); }
}
public string program_Name;
public string Program_Name //通知UI控件参数改变
{
get { return program_Name; }
set { program_Name = value; OnPropertyChanged("Program_Name"); }
}
// 创建 Computer 实例并启用需要的硬件监控
Computer computer = new Computer
{
CPUEnabled = true, // 启用 CPU 监控
GPUEnabled = true, // 启用 GPU 监控
HDDEnabled = true, // 启用硬盘监控
RAMEnabled = true, // 启用内存监控(注意:大多数内存模块无温度传感器:cite[1])
MainboardEnabled = true // 启用主板监控
};
public MainWindowViewModel()
{
SYSKEY = MD5check.MD5Encrypt16(HardwareSN.GetCPUSerialNumber()+HardwareSN.GetBIOSSerialNumber());
ERRinf.ERRinf_i(errTabler);
Sys_workSTEPID = -1;
WorkNumder = "----------";
SYS_SET(); //crbl
SQL_data(); //读数据库
if(S04!="1") UPort(); //启动串口
if (dt_TP.Rows.Count > 0)
{
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(Properties.Resources.RunningProcess, "800", MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
DataRow drEmployee = dt_TP.Select("RUN=1").First();
RUN_STEPID = drEmployee.Field("Step");
STEP_START(drEmployee.Field("StepID"),
drEmployee.Field("Parameter1"),
drEmployee.Field("Parameter2"),
drEmployee.Field("Parameter3"),
drEmployee.Field("Parameter4"),
drEmployee.Field("Parameter5")
);
WORK_RUN = 2;
//SQLiteHelpers = new SQLiteHelper(DBAddress);
//SQLiteHelpers.Open();
Dyelot_dat = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder = '" +
drEmployee.Field("WorkOrder") + "'", null).Tables[0];
var DT_Set = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder = '" +
drEmployee.Field("WorkOrder") + "'", null).Tables[0].Rows[0];
Updata_dtm("1020", DT_Set.Field("PumpSpeed"));
Updata_dtm("1030", DT_Set.Field("Swing"));
Updata_dtm("1021", DT_Set.Field("Blower"));
Updata_dtm("1025", DT_Set.Field("ClothWheel"));
Updata_dtm("1026", DT_Set.Field("ClothWheel"));
Updata_dtm("1027", DT_Set.Field("ClothWheel"));
Updata_dtm("1028", DT_Set.Field("ClothWheel"));
Updata_dtm("1029", DT_Set.Field("ClothWheel"));
Updata_dtm("1035", DT_Set.Field("ClothWheel"));
Updata_dtm("1036", DT_Set.Field("ClothWheel"));
Updata_dtm("1037", DT_Set.Field("ClothWheel"));
Updata_dtm("1038", DT_Set.Field("ClothWheel"));
Updata_dtm("1039", DT_Set.Field("ClothWheel"));
Updata_dtm("1040", DT_Set.Field("ClothWheel"));
Updata_dtm("1041", DT_Set.Field("ClothWheel"));
//SQLiteHelpers.Close();
}
else
{
//SQLiteHelpers = new SQLiteHelper(DBAddress);
//SQLiteHelpers.Open();
MainWindow.SQLiteHelpers.Delete("RUN", null, null);
//SQLiteHelpers.Close();
}//清楚任务列表
}//如果有未完成的工艺
CountDown(); //启动循环任务
_ = AsyncTcpServer.Main();
IsInteractive = false;
UserButton = false;
_Lock_bool = false;
_Link_bool = false;
_AUTO_bool = false;
ProgramgroupView_run = new RelayCommand(
execute:ProgramgroupView_run_ );//开始/暂停事件
ProgramgroupView_stop = new RelayCommand(
execute: ProgramgroupView_stop_);//结束事件
}
DataTable dt_con = new DataTable();
DataTable dt_sys = new DataTable();
public string Selet_con(string key)//配置缓存
{
try
{
DataRow[] arrRows = dt_con.Select("ParameterID ='" + key + "'");
string index = arrRows[0]["Value"].ToString();
return index;
}
catch (Exception ex)
{
LogGing.LogGingDATA(ex.ToString());
return "0";
}
}
public string Selet_sys(string key)//配置缓存
{
try
{
DataRow[] arrRows = dt_sys.Select("ParameterID ='" + key + "'");
string index = arrRows[0]["Value"].ToString();
return index;
}
catch (Exception ex)
{
LogGing.LogGingDATA(ex.ToString());
return "0";
}
}
private static int MT05;//主缸排水延时
private static int MT06;//主缸排水延时
private int MT12;
private static double MT16;//流量计数系数
public static int MT17;//
public static int MT18;//主缸管数
public static int MT19;//
public static int MT20;//管数
private static double MT33;//主缸温度偏差
private int MT38;//高水位
private int MT39;//中水位
private int MT40;//低水位
private int MT41;//安全水位
private int MT42;//水洗排水阀
private int MT43;//水洗排水完成水位
private int MT44;
private int MT45;
private static int MU01;//呼叫操作员
public static string S01;//机台号
public static string S03;//设备组
public static string S04;//展示模式
public static string S05;//管控模式
public static string S06;//通讯编码
public static int S16;//风机联动
public static int S17;//
public static int S19;//
public static int S20;//
public static int SM01;//副缸
public static int SM02;//副缸
public static int SM03;//副缸
public static string SK01;
public static string SK02;
public static string SK03;
public static string SK04;
public static string SK05;
public static string SK06;
public static string SK07;
public static string SK08;
public static string SK09;
public static string SK10;
public static string SK11;
public static string SK12;
public int MI01;//布轮信息
public int MI02;//喷射流量信息
public int MI03;//动态压力
public int MI04;//能耗信息
private double MS01;//1缸温度偏差
private double MS02;//2缸温度偏差
private double MS03;//3缸温度偏差
public int MS04;
public int MS05;
public int MS06;
public int MS07;
public int MS08;
public int MS09;
public int MS10;
public int MS11;
public int MS12;
public int MS13;
public int MS14;
public int MS15;
private double MS16;//
public int MS17;//副缸
public int MS18;//副缸
public int MS19;//副缸
public static bool set_=false;
public void SYS_SET()
{
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
dt_con = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID desc", null).Tables[0]; //读取表写入缓存
dt_sys = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID desc", null).Tables[0]; //读取表写入缓存
//SQLiteHelpers.Close();
pid.Kp = Convert.ToDouble(Selet_con("MT21")); //读取pid
pid.Ki = Convert.ToDouble(Selet_con("MT22"));
pid.Kd = Convert.ToDouble(Selet_con("MT23"));
pid.N = Convert.ToDouble(Selet_con("MT24"));
pid.OutputUpperLimit = Convert.ToDouble(Selet_con("MT25"));
pid.OutputLowerLimit = - Convert.ToDouble(Selet_con("MT26"));
MT05 = Convert.ToInt16(Selet_con("MT05"));//主缸排水延时
MT06 = Convert.ToInt16(Selet_con("MT06"));//动力排水延时
MT12 = Convert.ToInt16(Selet_con("MT12"));//
MT16 = Convert.ToDouble(Selet_con("MT16"));//流量计数系数
MT17 = Convert.ToInt16(Selet_con("MT17"));//
MT18 = Convert.ToInt16(Selet_con("MT18"));//
MT19 = Convert.ToInt16(Selet_con("MT19"));//
MT20 = Convert.ToInt16(Selet_con("MT20"));//
MT33 = Convert.ToDouble(Selet_con("MT33"));//温度偏差参数
MT38 = Convert.ToInt16(Selet_con("MT38"));//
MT39 = Convert.ToInt16(Selet_con("MT39"));//
MT40 = Convert.ToInt16(Selet_con("MT40"));//
MT41 = Convert.ToInt16(Selet_con("MT41"));//
MT42 = Convert.ToInt16(Selet_con("MT42"));//
MT43 = Convert.ToInt16(Selet_con("MT43"));//
MT44 = Convert.ToInt16(Selet_con("MT44"));//
MT45 = Convert.ToInt16(Selet_con("MT45"));//
MU01 = Convert.ToInt16(Selet_con("MU01"));//呼叫操作员
MS01 = Convert.ToDouble(Selet_con("MS01"));
MS02 = Convert.ToDouble(Selet_con("MS02"));
MS03 = Convert.ToDouble(Selet_con("MS03"));
MS04 = Convert.ToInt16(Selet_con("MS04"));
MS05 = Convert.ToInt16(Selet_con("MS05"));
MS06 = Convert.ToInt16(Selet_con("MS06"));
MS07 = Convert.ToInt16(Selet_con("MS07"));
MS08 = Convert.ToInt16(Selet_con("MS08"));
MS09 = Convert.ToInt16(Selet_con("MS09"));
MS10 = Convert.ToInt16(Selet_con("MS10"));
MS11 = Convert.ToInt16(Selet_con("MS11"));
MS12 = Convert.ToInt16(Selet_con("MS12"));
MS13 = Convert.ToInt16(Selet_con("MS13"));
MS14 = Convert.ToInt16(Selet_con("MS14"));
MS15 = Convert.ToInt16(Selet_con("MS15"));
MS16 = Convert.ToDouble(Selet_con("MS16"));
MS17 = Convert.ToInt16(Selet_con("MS17"));
MS18 = Convert.ToInt16(Selet_con("MS18"));
MS19 = Convert.ToInt16(Selet_con("MS19"));
S01 = Selet_sys("S01");//
S03 = Selet_sys("S03");//
S04 = Selet_sys("S04");//
S05 = Selet_sys("S05");//
S06 = Selet_sys("S06");//
S16 = Convert.ToInt16(Selet_sys("S16"));//工作信息
S19 = Convert.ToInt16(Selet_sys("S19"));//工作信息
S20 = Convert.ToInt16(Selet_sys("S20"));//工作信息
MI01 = Convert.ToInt16(Selet_sys("MI01"));//工作信息
MI02 = Convert.ToInt16(Selet_sys("MI02"));//工作信息
MI03 = Convert.ToInt16(Selet_sys("MI03"));//工作信息
SM01 = Convert.ToInt16(Selet_sys("SM01"));//FG
SM02 = Convert.ToInt16(Selet_sys("SM02"));//FG
SM03 = Convert.ToInt16(Selet_sys("SM03"));//FG
SK01 = Selet_sys("SK01");
SK02 = Selet_sys("SK02");
SK03 = Selet_sys("SK03");
SK04 = Selet_sys("SK04");
SK05 = Selet_sys("SK05");
SK06 = Selet_sys("SK06");
SK07 = Selet_sys("SK07");
SK08 = Selet_sys("SK08");
SK09 = Selet_sys("SK09");
SK10 = Selet_sys("SK10");
SK11 = Selet_sys("SK11");
SK12 = Selet_sys("SK12");
}
private void ProgramgroupView_run_()////运行/暂停
{
if (!_Lock_bool)
{
if (WORK_RUN == 2)
{
UserButton = true;
IsInteractive = true;
WORK_RUN = 1;// 运行时停止键为暂停
errTabler.Clear();
APILog.LOGlog(WorkNumder.ToString(), "UserActions", "WORK_RUN = Pause", WORK_RUN.ToString());
}
else
if (WORK_RUN == 1)
{
UserButton = false;
IsInteractive = false;
WORK_RUN = 2;//
SETP_runtime = true;
TechnologicalProcess_view();
APILog.LOGlog(WorkNumder.ToString(), "UserActions", "WORK_RUN = RUN", WORK_RUN.ToString());
}
else
{
UserButton = true;
IsInteractive = true;
}
}
else
{
USERinf(Resources.LockedState+"\n"+ Resources.TCOIR+"\n"+Resources.PCATRIL);
}
}
public ICommand ProgramgroupView_run { get; }
private void ProgramgroupView_stop_()//结束
{
if (!_Lock_bool)
{
APILog.LOGlog(WorkNumder.ToString(), "UserActions", "WORK_RUN = STOP", WORK_RUN.ToString());
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(Properties.Resources.StopProcess, "800", MessageBoxButton.OKCancel);
if (messageBoxResult == MessageBoxResult.OK)
{
Dictionary _temp = new Dictionary();//缓存函数
_temp.Clear(); //使用前清缓存
_temp.Add("State", 301);
WORK_RUN = 0;// 运行时停止键为
DIDETime = 0;
APILog.LOGlog(WorkNumder.ToString(), "UserActions", "PROCESS_END", WORK_RUN.ToString());
dt_TP.Rows.Clear();
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindow.SQLiteHelpers.Delete("RUN", null, null);
MainWindow.SQLiteHelpers.Update("WorkOrder", _temp, "WorkOrder='" + WorkNumder + "'", null);
//SQLiteHelpers.Close(); //关闭连接
UserButton = false;
IsInteractive = false;
ProgramName = null;
WorkNumder = "----------";
}
}
else
{
USERinf(Resources.LockedState + "\n" + Resources.TCOIR + "\n" + Resources.PCATRIL);
}
}
public void CountDown()
{
//设置定时器
DispatcherTimer disTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(500) //毫秒
};
disTimer.Tick += DisTimer_500MS;
disTimer.Start();//计时开始
}//时间周期初始化
void Tick_Event_1S()//Tick_Event周期执行事件1S
{
SYSTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
Sys_Time = SYSTime.ToString();
Work_Temp = Selet_dtm("1010") + " ℃";
Work_Numder = WorkNumder.ToString();
StatusStr = Status_Str;
Program_Name = ProgramName;
if (dt_TP.Rows.Count>= RUN_STEPID+1) Process_step = dt_TP.Select("Step=" + RUN_STEPID).First().Field("ParameterName");
if (set_) { set_ = false; SYS_SET(); }//设置更新
if (!SETP_runtime) DIDETime++;
STEP_RUN_master(); if (S04 == "1") { Simulate(); }
STEP_RUN_slave();
LOG_view();
IO_view();
if (errTabler.Rows.Count != 0)
{
Status_Str = ERRinf.ERRinf_r(errTabler);
Alert_red = true;
Alert_bell = true;
ERR_JOG = true;
Status_Str_coloer = Status_red;
}
else { Status_Str_coloer = Status_Black; ERR_JOG = false; }
Updata_dtd("3001", Alert_red);
Updata_dtd("3003", Alert_yellow);
Updata_dtd("3004", Alert_bell);
if (_Lock_bool) { Lock_bool = Visibility.Visible; }
else { Lock_bool = Visibility.Collapsed; }//锁图标
if (_Link_bool) { Link_bool = Visibility.Visible; }
else { Link_bool = Visibility.Collapsed; }//连线图标
if (_AUTO_bool) { AUTO_bool = _AUTO_bool; Updata_dtd("3005",true); }
else { AUTO_bool = _AUTO_bool; }//手自动图标
if ((Selet_dtm("1010") < 1) || (Selet_dtm("1010") > 160))
{ ERRinf.ERRinf_w(errTabler, Resources.Temperature + Resources.Sensor +
Resources.Malfunction, "ERR101"); } //温度故障提示
else { ERRinf.ERRinf_d(errTabler, "ERR101"); }
if (Selet_dtd("2001")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.EmergencyStop, "ERR100"); } //急停
else { ERRinf.ERRinf_d(errTabler, "ERR100"); }
if (Selet_dtd("2008")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Blower, "ERR102"); } //风机
else { ERRinf.ERRinf_d(errTabler, "ERR102"); }
if (Selet_dtd("2009")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Pump + "-0", "ERR103"); } //主泵
else { ERRinf.ERRinf_d(errTabler, "ERR103"); }
if (Selet_dtd("2012")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Wiggle, "ERR109"); } //摆布故障
else { ERRinf.ERRinf_d(errTabler, "ERR109"); }
if (Selet_dtd("2013")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.OtherCircuits, "ERR108"); } //其它电器故障
else { ERRinf.ERRinf_d(errTabler, "ERR108"); }
if (Selet_dtd("2014")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Pump + "-1", "ERR104-1"); } //加料泵
else { ERRinf.ERRinf_d(errTabler, "ERR104-1"); }
if (Selet_dtd("2015")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Pump + "-2", "ERR104-2"); } //加料泵
else { ERRinf.ERRinf_d(errTabler, "ERR104-2"); }
if (Selet_dtd("2016")) { ERRinf.ERRinf_w(errTabler, Resources.Fault + ":" +
Resources.Pump + "-3", "ERR104-3"); } //加料泵
else { ERRinf.ERRinf_d(errTabler, "ERR104-3"); }
}
void Tick_Event_5S()//Tick_Event周期执行事件5S
{
if (TX_t != TX) { _Link_bool = true; TX_t = TX; } else { _Link_bool = false; TX_t = TX; } //中央连接状态判断
if(WORK_RUN !=0) Chart();//写入记录
if(!UserButton) TechnologicalProcess_view();//刷新步骤页面
FeedingRecords_inf();
if ((Selet_dtm("1025") > 0) && (Selet_dtd("3021") || Selet_dtd("3022")))
{
if (Selet_dtm("1030") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "1 :" + Resources.Timeout, "ERR110-1");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-1"); }
}//布轮1检测超时
if ((Selet_dtm("1026") > 0) && (Selet_dtd("3023") || Selet_dtd("3024")))
{
if (Selet_dtm("1031") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "2 :" + Resources.Timeout, "ERR110-2");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-2"); }
}//布轮2检测超时
if ((Selet_dtm("1027") > 0) && (Selet_dtd("3025") || Selet_dtd("3026")))
{
if (Selet_dtm("1032") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "3 :" + Resources.Timeout, "ERR110-3");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-3"); }
}//布轮3检测超时
if ((Selet_dtm("1028") > 0) && (Selet_dtd("3027") || Selet_dtd("3028")))
{
if (Selet_dtm("1033") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "4 :" + Resources.Timeout, "ERR110-4");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-4"); }
}//布轮4检测超时
if ((Selet_dtm("1029") > 0) && (Selet_dtd("3029") || Selet_dtd("3030")))
{
if (Selet_dtm("1034") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "5 :" + Resources.Timeout, "ERR110-5");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-5"); }
}//布轮5检测超时
if ((Selet_dtm("1035") > 0) && (Selet_dtd("3031") || Selet_dtd("3022")))
{
if (Selet_dtm("1036") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "6 :" + Resources.Timeout, "ERR110-6");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-6"); }
}//布轮6检测超时
if ((Selet_dtm("1037") > 0) && (Selet_dtd("3033") || Selet_dtd("3034")))
{
if (Selet_dtm("1038") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "7 :" + Resources.Timeout, "ERR110-7");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-7"); }
}//布轮7检测超时
if ((Selet_dtm("1039") > 0) && (Selet_dtd("3065") || Selet_dtd("3066")))
{
if (Selet_dtm("1040") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "8 :" + Resources.Timeout, "ERR110-8");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-8"); }
}//布轮8检测超时
if ((Selet_dtm("1051") > 0) && (Selet_dtd("3067") || Selet_dtd("3068")))
{
if (Selet_dtm("1052") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "9 :" + Resources.Timeout, "ERR110-9");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-9"); }
}//布轮9检测超时
if ((Selet_dtm("1053") > 0) && (Selet_dtd("3069") || Selet_dtd("3070")))
{
if (Selet_dtm("1054") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "10 :" + Resources.Timeout, "ERR110-10");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-10"); }
}//布轮10检测超时
if ((Selet_dtm("1055") > 0) && (Selet_dtd("3071") || Selet_dtd("3072")))
{
if (Selet_dtm("1056") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "11 :" + Resources.Timeout, "ERR110-11");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-11"); }
}//布轮11检测超时
if ((Selet_dtm("1057") > 0) && (Selet_dtd("3073") || Selet_dtd("3074")))
{
if (Selet_dtm("1058") == 0)
{
ERRinf.ERRinf_w(errTabler, Resources.ClothWheel + "12 :" + Resources.Timeout, "ERR110-12");
}
else { ERRinf.ERRinf_d(errTabler, "ERR110-12"); }
}//布轮12检测超时
}
void Tick_Event_60S()//Tick_Event周期执行事件5S
{
if(Hardware.Count>0) Hardware.Clear();
computer.Open(); // 开始监控
// 遍历所有硬件设备及其传感器,筛选出温度传感器并读取值
foreach (var hardwareItem in computer.Hardware)
{
hardwareItem.Update(); // 更新硬件信息:cite[2]
foreach (var sensor in hardwareItem.Sensors)
{
// if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
{
//Console.WriteLine($"{hardwareItem.Name} - {sensor.Name}: {sensor.Value.Value}°C");
// 实际应用中,你可能需要将这里的数据绑定到UI控件或存储起来
// Hardware.Add(sensor.Name+":"+sensor.SensorType, sensor.Value.Value);
}
}
}
computer.Close(); // 结束监控:cite[1]
}
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件200MS
{
if (User_Button)
{
TechnologicalProcess_view();
User_Button = false;
}//按钮刷新步骤页面
IOm_DATA();
timer1s_++;
timer5s_++;
timer60s_++;
if (timer1s_ >= 2) { timer1s_ =0; Tick_Event_1S(); }
if (timer5s_ >=10) { timer5s_ = 0; Tick_Event_5S(); }
if (timer60s_ >= 120) { timer60s_ = 0; Tick_Event_60S(); }
if (LINK_OK) IO_data();
}
void Chart()
{
Dictionary Chart_new = new Dictionary();//缓存函数
Chart_new.Add("DYELOT", work_Numder);
Chart_new.Add("Time", sys_Time);
Chart_new.Add("MST", string.Format(" {0:###.#}", TEMP_co));
Chart_new.Add("MTT", Selet_dtm("1010"));
Chart_new.Add("MTL", Selet_dtm("1015"));
Chart_new.Add("MTH", Selet_dtm("1009"));
Chart_new.Add("MUT", Selet_dtm("1011"));
Chart_new.Add("STTA", Selet_dtm("1012"));
Chart_new.Add("STLA", Selet_dtm("1017"));
Chart_new.Add("STTB", Selet_dtm("1013"));
Chart_new.Add("STLB", Selet_dtm("1018"));
Chart_new.Add("STTC", Selet_dtm("1014"));
Chart_new.Add("STLC", Selet_dtm("1019"));
//SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindow.SQLiteHelpers.InsertData("Chart", Chart_new);// 执行插入
//SQLiteHelpers.Close();
}//历史记录
public static int WORK_RUN = 0; //运行状态0停止1暂停2运行
private static string STEP_ID = "0";
private static double STEP_P1 = 0;
private static double STEP_P2 = 0;
private static double STEP_P3 = 0;
private static double STEP_P4 = 0;
private static double STEP_P5 = 0;
private static string STEP_IDp1 = "0";
private static double STEP_P1p1 = 0;
private static double STEP_P2p1 = 0;
private static double STEP_P3p1 = 0;
private static double STEP_P4p1 = 0;
private static double STEP_P5p1 = 0;
private static string STEP_IDp2 = "0";
private static double STEP_P1p2 = 0;
private static double STEP_P2p2 = 0;
private static double STEP_P3p2 = 0;
private static double STEP_P4p2 = 0;
private static double STEP_P5p2 = 0;
private static string STEP_IDp3 = "0";
private static double STEP_P1p3 = 0;
private static double STEP_P2p3 = 0;
private static double STEP_P3p3 = 0;
private static double STEP_P4p3 = 0;
private static double STEP_P5p3 = 0;
private static bool SETP_runtime = false; //步骤开始
private static bool STEP_finish = false; //步骤结束
public static int STEP_TIME = 0; //步骤计时S
public static int STEP_TIMEp = 0; //步骤计时S
public static int THL_mode = 0; //温控模式 0保温 1加热 2降
public static double TEMP_co = 0.5; //计算温度
public static double TEMP_tar = 0.5; //目标温度
private bool Alert_yellow = false; //警报黄灯
private bool Alert_red = false; //警报红灯
public static bool Alert_bell = false; //警报铃声
static Dictionary updata_RUN = new Dictionary();//
/**提示步骤页面信息**/
static UserInf userInf = null;
public static void USERinf(string DAT)
{
if (userInf == null || !userInf.IsLoaded)
{
userInf = new UserInf();
userInf.Inf_DAT = DAT;
userInf.Show();
}
}
/**提示步骤页面信息**/
static UserCall userCall = null;
static Sampling sampling = null;
public static void USERcall(string ID, string DAT)
{
if (userCall == null || !userCall.IsLoaded)
{
userCall = new UserCall();
userCall.Topmost = true;
userCall.CALL_time = S19;
userCall.Inf_DAT = DAT;
userCall.Show();
}
}
/**主功能**/
public static void STEP_START(string ID, double P1, double P2, double P3, double P4, double P5) //启动模块
{
STEP_ID = ID;
switch (ID)
{
case "001":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
TEMP_tar = STEP_P1;
double t_t = Convert.ToDouble(Selet_dtm("1010"));
if (STEP_P1 > t_t) { THL_mode = 1; }
else if (STEP_P1 < t_t) { THL_mode = 2; }
TEMP_co = t_t;
Updata_dtm("1003", STEP_P2 / 600);
STEP_TIME = Convert.ToInt16(STEP_P3) * 60;
SETP_runtime = true;
STEP_finish = false;
break;//功能模块001温度控制开始
case "007":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_TIME = 0;
SETP_runtime = true;
STEP_finish = false;
break;
case "008":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_TIME = 0;
SETP_runtime = true;
STEP_finish = false;
break;
case "013":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
STEP_P4 = Convert.ToDouble(P4);
STEP_P5 = 0;
SETP_runtime = true;
STEP_finish = false;
break;
case "015":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
STEP_P5 = 0;
STEP_TIME = 0;
SETP_runtime = true;
STEP_finish = false;
break;
case "017":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
STEP_P4 = Convert.ToDouble(P4);
STEP_P5 = Convert.ToDouble(P5);
SETP_runtime = true;
STEP_finish = false;
break;
case "020":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToInt16(MT05); //排水倒计时
SETP_runtime = true;
STEP_finish = false;
break;
case "022":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToInt16(MT06); //动力排水倒计时
SETP_runtime = true;
STEP_finish = false;
break;
case "031":
STEP_TIME = Convert.ToInt16(P1) * 60;
SETP_runtime = true;
STEP_finish = false;
break;
case "035":
STEP_TIME = Convert.ToInt32(MU01);
SETP_runtime = true;
STEP_finish = false;
break;
case "036":
STEP_TIME = Convert.ToInt32(MU01);
SETP_runtime = true;
STEP_finish = false;
break;
case "039":
STEP_TIME = Convert.ToInt32(MU01);
SETP_runtime = true;
STEP_finish = false;
break;
case "040":
STEP_TIME = Convert.ToInt32(MU01);
SETP_runtime = true;
STEP_finish = false;
break;
case "041":
SETP_runtime = true;
STEP_finish = false;
break;
case "049":
STEP_TIME = Convert.ToInt32(MU01);
SETP_runtime = true;
STEP_finish = false;
break;
case "050":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_TIME = 0;
SETP_runtime = true;
STEP_finish = false;
break;//主缸加压
case "051":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_TIME = 0;
SETP_runtime = true;
STEP_finish = false;
break;//主缸减压
case "054":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
SETP_runtime = true;
STEP_finish = false;
break;//主泵/风机速度
case "055":
STEP_TIME = 10;
SETP_runtime = true;
STEP_finish = false;
break;//主泵启动
case "056":
SETP_runtime = true;
STEP_finish = false;
break;//主泵停止
case "064":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
STEP_P4 = Convert.ToDouble(P4);
STEP_P5 = Convert.ToDouble(P5);
SETP_runtime = true;
STEP_finish = false;
break;//药缸备药
case "065":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
STEP_P5 = 0;
SETP_runtime = true;
STEP_finish = false;
break;//药缸加药
case "066":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
SETP_runtime = true;
STEP_finish = false;
break;//呼叫输送
case "067":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
SETP_runtime = true;
STEP_finish = false;
break;//呼叫输送
case "090":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
SETP_runtime = true;
STEP_finish = false;
break;//快速加酸
case "091":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
STEP_P3 = Convert.ToDouble(P3);
SETP_runtime = true;
STEP_finish = false;
break;//PH温度控制
case "093":
STEP_TIME = Convert.ToInt16(P1);
SETP_runtime = true;
STEP_finish = false;
break;//PH检测
case "094":
STEP_P1 = Convert.ToDouble(P1);
STEP_P2 = Convert.ToDouble(P2);
SETP_runtime = true;
STEP_finish = false;
break;//PH控制
default:
break;
}
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
updata_RUN.Clear();
updata_RUN.Add("RUN", 0);
MainWindow.SQLiteHelpers.Update("RUN", updata_RUN, "RUN ='1'", null);//更新
updata_RUN.Clear();
updata_RUN.Add("RUN", 1);
MainWindow.SQLiteHelpers.Update("RUN", updata_RUN, "Step ='" + RUN_STEPID + "'", null);//更新
dt_TP = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from RUN", null).Tables[0];
//SQLiteHelpers.Close();//关闭数据库
//启动副功能
STEP_RUN_slave_stop();
DataRow[] arrRows = dt_TP.Select("STEP ='" + RUN_STEPID + "'");
if (arrRows.First().Field