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 OpenTK.Graphics.ES11; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; 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.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 static DyeingComputer.UserClass.SqliteHelper; using static DyeingComputer.ViewModel.MainWindowViewModel; using static DyeingComputer.Windows.ViewStep; using static System.Net.WebRequestMethods; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; 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 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 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; Visibility AUTO_bool_xml; //显示手自动状态 public Visibility 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"); } } 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; 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; } else { SQLiteHelpers = new SQLiteHelper(DBAddress); SQLiteHelpers.Open(); 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;//主缸管数 private static double MT33;//主缸温度偏差 private int MT38;//高水位 private int MT39;//中水位 private int MT40;//低水位 private int MT41;//安全水位 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 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 MS17;//副缸 public int MS18;//副缸 public int MS19;//副缸 public static bool set_=false; public void SYS_SET() { SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 dt_con = SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID desc", null).Tables[0]; //读取表写入缓存 dt_sys = 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"));// 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"));// MU01 = Convert.ToInt16(Selet_con("MU01"));//呼叫操作员 MS01 = Convert.ToDouble(Selet_con("MS01")); MS02 = Convert.ToDouble(Selet_con("MS02")); MS03 = Convert.ToDouble(Selet_con("MS03")); 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 SK5 = Selet_sys("SK5");// } private void ProgramgroupView_run_()////运行/暂停 { if (WORK_RUN == 2) { UserButton = true; IsInteractive = true; WORK_RUN = 1;// 运行时停止键为暂停 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; } } public ICommand ProgramgroupView_run { get; } private void ProgramgroupView_stop_()//结束 { 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) { 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(); //打开数据库 SQLiteHelpers.Delete("RUN", null, null); SQLiteHelpers.Close(); //关闭连接 UserButton = false; IsInteractive = false; ProgramName = null; WorkNumder = "----------"; } } 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>0) Process_step = dt_TP.Select("Step=" + RUN_STEPID).First().Field("ParameterName"); if (set_) { set_ = false; SYS_SET(); }//设置更新 if (!SETP_runtime) DIDETime++; STEP_RUN(); 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 = Visibility.Visible; Updata_dtd("3005",true); } else { AUTO_bool = Visibility.Collapsed; }//手自动图标 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"); } } uint TX_t; 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();//刷新步骤页面 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 DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件200MS { if (User_Button) { TechnologicalProcess_view(); User_Button = false; }//按钮刷新步骤页面 IOm_DATA(); timer1s_++; timer5s_++; if (timer1s_ >= 2) { timer1s_ =0; Tick_Event_1S(); } if (timer5s_ >=10) { timer5s_ = 0; Tick_Event_5S(); } 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(); //打开数据库 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 bool SETP_runtime = false; //步骤开始 private static bool STEP_finish = false; //步骤结束 public static int STEP_TIME = 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; //警报红灯 private bool Alert_bell = false; //警报铃声 static Dictionary updata_RUN = new Dictionary();// public static void STEP_START(string ID, double P1, double P2, double P3, double P4, double P5) //启动模块 { UserCall userCall = new UserCall(); userCall.Topmost = true; userCall.CALL_time= S19; 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); SETP_runtime = true; STEP_finish = false; break; case "008": STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); SETP_runtime = true; STEP_finish = false; break; case "013": break; case "015": break; case "017": break; case "020": STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); STEP_TIME = Convert.ToInt16(MT05); //排水倒计时 SETP_runtime = true; STEP_finish = false; break; case "022": STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); STEP_TIME = 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": userCall.Inf_DAT = Resources.ClothIntake; userCall.Show(); STEP_TIME = Convert.ToInt32(MU01); SETP_runtime = true; STEP_finish = false; break; case "036": userCall.Show(); STEP_TIME = Convert.ToInt32(MU01); SETP_runtime = true; STEP_finish = false; break; case "039": userCall.Show(); STEP_TIME = Convert.ToInt32(MU01); SETP_runtime = true; STEP_finish = false; break; case "040": Sampling sampling = new Sampling(); sampling.Topmost = true; sampling.CALL_time = S20; sampling.Show(); STEP_TIME = Convert.ToInt32(MU01); SETP_runtime = true; STEP_finish = false; break; case "041": userCall.Show(); SETP_runtime = false; STEP_finish = false; break; case "049": userCall.Show(); STEP_TIME = Convert.ToInt32(MU01); SETP_runtime = true; STEP_finish = false; break; case "050": STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); SETP_runtime = true; STEP_finish = false; break;//主缸加压 case "051": STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); 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); 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); SQLiteHelpers.Update("RUN", updata_RUN, "RUN ='1'", null);//更新 updata_RUN.Clear(); updata_RUN.Add("RUN", 1); SQLiteHelpers.Update("RUN", updata_RUN, "Step ='"+ RUN_STEPID + "'", null);//更新 dt_TP = SQLiteHelpers.ExecuteDataSet("select * from RUN", null).Tables[0]; SQLiteHelpers.Close();//关闭数据库 } TimeSpan ts = new TimeSpan(00,00,01);//1秒间隔 private int temp_time10s = 10;//开关周期时间 private bool PH_start = false; private double TANK1_L,TANK2_L,TANK3_L,TANK1_SL,TANK2_SL,TANK3_SL;//实际加料量|每秒加料量 private double TANK1_Pt, TANK1_Pc, TANK2_Pt, TANK2_Pc, TANK3_Pt, TANK3_Pc;//加料比例开度与模拟 private string TANK1, TANK2, TANK3;//料桶信息 public static string TANK1_DYELOT, TANK2_DYELOT, TANK3_DYELOT;//料单号 private int TANK1_REDYE,TANK1_STEP, TANK2_REDYE, TANK2_STEP, TANK3_REDYE, TANK3_STEP; void STEP_RUN() { WORK_run = WORK_RUN; if (WORK_RUN == 2) { if (SETP_runtime && (!STEP_finish))// { switch (STEP_ID) { case "001": int TIME_H; int TIME_M; int TIME_S; double TO = 0; double T = Selet_dtm("1010"); //实际温度 if (THL_mode == 0) //保温 { TO = pid.PID_iterate(STEP_P1, T, ts); TEMP_co = STEP_P1; if (TO < 0) TO = 0; TIME_H = STEP_TIME / 3600; TIME_M = (STEP_TIME - TIME_H * 3600) / 60; TIME_S = STEP_TIME - TIME_H * 3600 - TIME_M * 60; if (errTabler.Rows.Count==0) Status_Str = Resources.Heat_insulating + ":" + Resources.Time + string.Format(" {0:D2}", TIME_H) + ":" + string.Format(" {0:D2}", TIME_M) + ":" + string.Format(" {0:D2}", TIME_S); if (STEP_TIME <= 0) { STEP_finish = true; Updata_dtm("1004", 0); Updata_dtd("3009", false); Updata_dtd("3010", false); } else { STEP_TIME--; } } else if (THL_mode == 1)//升温 { if (STEP_P1 > TEMP_co) TEMP_co = TEMP_co + (STEP_P2 / 60); TO = pid.PID_iterate(TEMP_co, T, ts); if (TO < 0) TO = 0; if ((TEMP_co < T) || (T - TEMP_co > 3)) TO = 0; if (STEP_P1 < T) { THL_mode = 0; TIME_M = 0; } else { TIME_M = Convert.ToInt16((STEP_P1 - T) / STEP_P2 ); } if (errTabler.Rows.Count == 0) { Status_Str = Resources.Heats + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C"; if ((TEMP_co - T) > 5) { ERRinf.ERRinf_w(errTabler, Status_Str + "[" + Resources.Heats + Resources.LnsufficientPower + "]", "201-1");//写入 } else { ERRinf.ERRinf_d(errTabler, "201-1");// Status_Str = Status_Str + Resources.Expected + string.Format(" {0:D2}", TIME_M) + Resources.Min; } } } else if (THL_mode == 2)//降温 { if (STEP_P1 < TEMP_co) TEMP_co = TEMP_co - (STEP_P2 / 60); TO = pid.PID_iterate(TEMP_co, T, ts); if (TO > 0) TO = 0; TO = Math.Abs(TO); if (STEP_P1 > T) { THL_mode = 0; TIME_M = 0; } else { TIME_M = Convert.ToInt16((T - STEP_P1) / STEP_P2 ); } if (errTabler.Rows.Count == 0) { Status_Str = Resources.Cooling + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C"; if ((T - TEMP_co) > 5) { ERRinf.ERRinf_w(errTabler, Status_Str + "[" + Resources.Cooling + Resources.LnsufficientPower + "]", "201-2");//写入 } else { ERRinf.ERRinf_d(errTabler, "201-2");// Status_Str = Status_Str + Resources.Expected + string.Format(" {0:D2}", TIME_M) + Resources.Min; } } } Updata_dtm("1004", TO); Updata_dtm("1005", TEMP_co); if (MT12 == 1)//输出类型0开关1模拟 { if (THL_mode == 2) { Updata_dta("5002", Convert.ToInt16(TO)); } else { Updata_dta("5001", Convert.ToInt16(TO)); } } else { if (temp_time10s <= 0) { temp_time10s = 10; } else { temp_time10s--; } if (THL_mode == 2) { if ((temp_time10s <= Convert.ToInt16(TO)/100)) { Updata_dtd("3010", true); } else { Updata_dtd("3010", false); }//降温 } else { if (temp_time10s == 1) temp_time10s = 2; if ((temp_time10s <= Convert.ToInt16(TO)/100)) { Updata_dtd("3009", true); } else { Updata_dtd("3009", false); }//升温 } } break;//功能模块001温度控制 case "007": if (STEP_P1.ToString() == "1") { Updata_dtd("3013", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "1"; } else if (STEP_P1.ToString() == "2") { Updata_dtd("3014", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "2"; } else if (STEP_P1.ToString() == "3") { Updata_dtd("3015", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "3"; } else if (STEP_P1.ToString() == "4") { Updata_dtd("3016", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "4"; } if (Selet_dtm("1015") >= STEP_P2) //到达水位 { Updata_dtd("3013", false); Updata_dtd("3014", false); Updata_dtd("3015", false); Updata_dtd("3016", false); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.Finish; STEP_finish = true; } break;//液位入水 case "008": if (STEP_P1.ToString() == "1") { Updata_dtd("3013", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "1"; } else if (STEP_P1.ToString() == "2") { Updata_dtd("3014", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "2"; } else if (STEP_P1.ToString() == "3") { Updata_dtd("3015", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "3"; } else if (STEP_P1.ToString() == "4") { Updata_dtd("3016", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.AddWater + "4"; } if (Selet_dtm("1016") >= STEP_P2) //到达水量 { Updata_dtd("3013", false); Updata_dtd("3014", false); Updata_dtd("3015", false); Updata_dtd("3016", false); if (errTabler.Rows.Count == 0) Status_Str = Resources.AddWater + ":" + Resources.Finish; STEP_finish = true; } break;//流量入水 case "013": break; case "015": break; case "017": break; case "020": if (STEP_P1.ToString() == "1") { Updata_dtd("3017", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "1"; } else if (STEP_P1.ToString() == "2") { Updata_dtd("3018", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "2"; } else if (STEP_P1.ToString() == "3") { Updata_dtd("3019", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "3"; } if (Selet_dtm("1015") <= STEP_P2) //排水状态完成 { if (STEP_TIME <= 0)//排水延时 { Updata_dtd("3017", false); Updata_dtd("3018", false); Updata_dtd("3019", false); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Finish; STEP_finish = true; } else { STEP_TIME--; //排水延时计时 if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Time + STEP_TIME; } } break;//排水 case "022": if (STEP_P1.ToString() == "1") { Updata_dtd("3017", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "1"; } else if (STEP_P1.ToString() == "2") { Updata_dtd("3018", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "2"; } else if (STEP_P1.ToString() == "3") { Updata_dtd("3019", true); if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Drainage + "3"; } Updata_dtd("3020", true);//开排水泵 if (Selet_dtm("1015") <= STEP_P2) //排水状态完成 { if (STEP_TIME <= 0)//排水延时 { Updata_dtd("3017", false); Updata_dtd("3018", false); Updata_dtd("3019", false); Updata_dtd("3020", false);//开排水泵 if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Finish; STEP_finish = true; } else { STEP_TIME--; //排水延时计时 if (errTabler.Rows.Count == 0) Status_Str = Resources.Drainage + ":" + Resources.Time + STEP_TIME; } } break;//动力排水 case "031": if (STEP_TIME <= 0) { STEP_finish = true; } else { STEP_TIME--; TIME_M = STEP_TIME / 60; TIME_S = STEP_TIME - TIME_M * 60; if (errTabler.Rows.Count == 0) Status_Str = Resources.RunningTime + ":" + Resources.Time + string.Format(" {0:D3}", TIME_M) + ":" + string.Format(" {0:D2}", TIME_S); } break;//运转时间 case "035": if (Selet_dtd("2004")|| UserCall_OK) { UserCall_OK = false; STEP_finish = true; Alert_yellow = false; } else { Alert_yellow = true; if (STEP_TIME <= 0) { Alert_bell = false; } else { STEP_TIME--; Alert_bell = true; } } if (errTabler.Rows.Count == 0) Status_Str = Resources.ClothIntake; break;//准备入布 case "036": if (Selet_dtd("2004")|| UserCall_OK) { UserCall_OK=false; STEP_finish = true; Alert_yellow = false; } else { Alert_yellow = true; if (STEP_TIME <= 0) { Alert_bell = false; } else { STEP_TIME--; Alert_bell = true; } } if (errTabler.Rows.Count == 0) Status_Str = Resources.OutTheCloth; break;//准备出布 case "039": if (Selet_dtd("2004")|| UserCall_OK) { UserCall_OK = false; STEP_finish = true; Alert_yellow = false; } else { Alert_yellow = true; if (STEP_TIME <= 0) { Alert_bell = false; } else { STEP_TIME--; Alert_bell = true; } } if (errTabler.Rows.Count == 0) Status_Str = Resources.CallWorkers; break;//呼叫人工 case "040": if (Selet_dtd("2004")|| UserCall_OK) { UserCall_OK = false; STEP_finish = true; Alert_yellow = false; } else { Alert_yellow = true; if (STEP_TIME <= 0) { Alert_bell = false; } else { STEP_TIME--; Alert_bell = true; } } if (errTabler.Rows.Count == 0) Status_Str = Resources.Sampling; break;//取样 case "041": STEP_finish = true; if (errTabler.Rows.Count == 0) Status_Str = Resources.End; break;//结束 case "049": if (Selet_dtd("2004")|| UserCall_OK) { UserCall_OK = false; STEP_finish = true; Alert_yellow = false; } else { Alert_yellow = true; STEP_TIME--; if (STEP_TIME <= 0) { Alert_bell = false; } else { Alert_bell = true; } } if (errTabler.Rows.Count == 0) Status_Str = Resources.Await; break;//等待 case "050": break;//主缸加压 case "051": break;//主缸减压 case "054": Updata_dtm("1020", STEP_P1); Updata_dtm("1021", STEP_P2); Updata_dtm("1008", STEP_P3); STEP_finish = true; break;//主泵/风机速度 case "055": if (Selet_dtm("1015") > MT41) { Updata_dtd("3011", true);//主泵启动 if (S16 == 1) Updata_dtd("3012", true);//风机启动 STEP_TIME--; if (STEP_TIME <= 0) { STEP_finish = true; } if (errTabler.Rows.Count == 0) Status_Str = Resources.PumpStart + "("+ STEP_TIME + "S)"; } else { Updata_dtd("3011", false); Updata_dtd("3012", false); if (errTabler.Rows.Count == 0) Status_Str = Resources.MasterCylinder + Resources.Low_waterlevel; } break;//主泵启动 case "056": Updata_dtd("3011", false);//主泵 if (S16 == 1) Updata_dtd("3012", false);//风机 STEP_finish = true; if (errTabler.Rows.Count == 0) Status_Str = Resources.PumpStops; break;//主泵停止 case "064": if ((STEP_P1 == 1)||(STEP_P1==0)) { if (Selet_dtm("1017") >= STEP_P3)//水位 { TANK1 = Resources.Ready; Updata_dtd("3036", false); Updata_dtd("3037", false); Updata_dtd("3038", false); if (Selet_dtm("1012") >= STEP_P4)//温度 { Updata_dtd("3039",false); if (Selet_dtd("2004"))//投料确认 { if (STEP_TIME <= 0)//搅拌 { TANK1 = Resources.Ready + Resources.Finish; Updata_dtd("3040",false); STEP_finish = true; } else { STEP_TIME--; Updata_dtd("3040",true); } Alert_yellow = false; Alert_bell = false; } else { Alert_yellow = true; STEP_TIME = Convert.ToInt16(STEP_P5); Alert_bell = true; } } else { Updata_dtd("3039",true); Updata_dtd("3040", true); } } else { if (STEP_P2 == 0) Updata_dtd("3038", true); else if(STEP_P2 == 1) Updata_dtd("3036", true); else if (STEP_P2 == 2) Updata_dtd("3037", true); } if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank +" 1 :" + Resources.Ready; } //药缸1 else if (STEP_P1 == 2) { if (Selet_dtm("1018") >= STEP_P3)//水位 { TANK2 = Resources.Ready; Updata_dtd("3046", false); Updata_dtd("3047", false); Updata_dtd("3048", false); if (Selet_dtm("1013") >= STEP_P4)//温度 { Updata_dtd("3049", false); if (Selet_dtd("2004"))//投料确认 { if (STEP_TIME <= 0)//搅拌 { TANK2 = Resources.Ready + Resources.Finish; Updata_dtd("3050", false); STEP_finish = true; } else { STEP_TIME--; Updata_dtd("3050", true); } Alert_yellow = false; Alert_bell = false; } else { Alert_yellow = true; STEP_TIME = Convert.ToInt16(STEP_P5); Alert_bell = true; } } else { Updata_dtd("3049", true); Updata_dtd("3050", true); } } else { if (STEP_P2 == 0) Updata_dtd("3048", true); else if (STEP_P2 == 1) Updata_dtd("3046", true); else if (STEP_P2 == 2) Updata_dtd("3047", true); } if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 2 :" + Resources.Ready; }//药缸2 else if (STEP_P1 == 3) { if (Selet_dtm("1019") >= STEP_P3)//水位 { TANK3 = Resources.Ready; Updata_dtd("3056", false); Updata_dtd("3057", false); Updata_dtd("3058", false); if (Selet_dtm("1014") >= STEP_P4)//温度 { Updata_dtd("3059", false); if (Selet_dtd("2004"))//投料确认 { if (STEP_TIME <= 0)//搅拌 { TANK3 = Resources.Ready + Resources.Finish; Updata_dtd("3060", false); STEP_finish = true; } else { STEP_TIME--; Updata_dtd("3060", true); } Alert_yellow = false; Alert_bell = false; } else { Alert_yellow = true; STEP_TIME = Convert.ToInt16(STEP_P5); Alert_bell = true; } } else { Updata_dtd("3059", true); Updata_dtd("3060", true); } } else { if (STEP_P2 == 0) Updata_dtd("3058", true); else if (STEP_P2 == 1) Updata_dtd("3056", true); else if (STEP_P2 == 2) Updata_dtd("3057", true); } if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 3 :" + Resources.Ready; }//药缸3 break;//药缸备药 case "065": if (STEP_P1 == 1) { if ((TANK1_L - Selet_dtm("1017")) > TANK1_SL) { TANK1_Pc = TANK2_Pc - 3.3; }//计算比例 else { TANK1_Pc = TANK1_Pc + 3.3; } if (((TANK1_Pt - TANK1_Pc) > 5) || ((TANK1_Pt - TANK1_Pc) > -5)) TANK1_Pt = TANK1_Pc;//调整比例 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 1 :" + Resources.AddTheMedicine; } //药缸1 else if (STEP_P1 == 2) { if ((TANK2_L - Selet_dtm("1018")) > TANK2_SL) { TANK2_Pc = TANK2_Pc - 3.3; }//计算比例 else { TANK2_Pc = TANK2_Pc + 3.3; } if (((TANK2_Pt - TANK2_Pc) > 5) || ((TANK2_Pt - TANK2_Pc) > -5)) TANK2_Pt = TANK2_Pc;//调整比例 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 2 :" + Resources.AddTheMedicine; }//药缸2 else if (STEP_P1 == 3) { if ((TANK3_L - Selet_dtm("1019")) > TANK3_SL) { TANK3_Pc = TANK3_Pc - 3.3; }//计算比例 else { TANK3_Pc = TANK3_Pc + 3.3; } if (((TANK3_Pt - TANK3_Pc) > 5) || ((TANK3_Pt - TANK3_Pc) > -5)) TANK3_Pt = TANK3_Pc;//调整比例 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 3 :" + Resources.AddTheMedicine; }//药缸3 break;//药缸加药 case "066": if (STEP_P1 == 1) { TANK1_REDYE = SYS_REDYE; if(string.IsNullOrEmpty(TANK1_DYELOT)) TANK1_DYELOT = WorkNumder.ToString(); TANK1_STEP =Convert.ToInt16(STEP_P3); FeedingRecords(work_Numder,TANK1_DYELOT,Convert.ToInt16(STEP_P1),TANK1_STEP,Convert.ToInt16(STEP_P2));//调用呼叫 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 1 :" + Resources.CallDistribution; STEP_finish = true; } //药缸1 else if (STEP_P1 == 2) { TANK2_REDYE = SYS_REDYE; if (string.IsNullOrEmpty(TANK2_DYELOT)) TANK2_DYELOT = WorkNumder.ToString(); TANK2_STEP = Convert.ToInt16(STEP_P3); FeedingRecords(work_Numder, TANK2_DYELOT, Convert.ToInt16(STEP_P1), TANK2_STEP, Convert.ToInt16(STEP_P2));//调用呼叫 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 2 :" + Resources.CallDistribution; STEP_finish = true; }//药缸2 else if (STEP_P1 == 3) { TANK3_REDYE = SYS_REDYE; if (string.IsNullOrEmpty(TANK3_DYELOT)) TANK3_DYELOT = WorkNumder.ToString(); TANK3_STEP = Convert.ToInt16(STEP_P3); FeedingRecords(work_Numder, TANK3_DYELOT, Convert.ToInt16(STEP_P1), TANK3_STEP, Convert.ToInt16(STEP_P2));//调用呼叫 if (errTabler.Rows.Count == 0) Status_Str = Resources.Tank + " 3 :" + Resources.CallDistribution; STEP_finish = true; }//药缸3 //STEP_finish = true; break;//呼叫输送 case "067": STEP_finish = true; break;//等待输送 case "090": if (((STEP_P1-1)= Selet_dtm("1009")) { PH_start= false; STEP_finish = true; } if (errTabler.Rows.Count == 0) Status_Str = "PH" + Resources.PHControl + "(" + Selet_dtm("1009") + "pH)"; } else { if (errTabler.Rows.Count == 0) Status_Str = "PH" + Resources.PHControl + "(" + Resources.Await + Resources.Temperature +")"; } break;//快速加酸 case "091": T = Selet_dtm("1010"); //实际温度 if (STEP_P1 > TEMP_co) TEMP_co = TEMP_co + (STEP_P2 / 600); TO = pid.PID_iterate(TEMP_co, T, ts); if (TO < 0) TO = 0; if ((TEMP_co < T) || (T - TEMP_co > 3)) TO = 0; if (STEP_P1 <= T) { TO = 0; Updata_dtm("1004", TO); Updata_dta("5001", Convert.ToInt16(TO)); Updata_dtd("3009", false); } else { Updata_dtm("1004", TO); Updata_dtm("1005", TEMP_co); if (MT12 == 1)//输出类型0开关1模拟 { Updata_dta("5001", Convert.ToInt16(TO)); } else { if (temp_time10s <= 0) { temp_time10s = 10; } else { temp_time10s--; } if (THL_mode == 2) { if ((temp_time10s <= Convert.ToInt16(TO) / 100)) { Updata_dtd("3010", true); } else { Updata_dtd("3010", false); }//降温 } else { if ((temp_time10s <= Convert.ToInt16(TO) / 100)) { Updata_dtd("3009", true); } else { Updata_dtd("3009", false); }//升温 } } } if (errTabler.Rows.Count == 0) { Status_Str = Resources.Heats + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C"; if ((TEMP_co - T) > 5) { Status_Str = Status_Str + "[" + Resources.Heats + Resources.LnsufficientPower + "]"; } else { Status_Str = Resources.Heats + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C"; } } if (STEP_P2 >= Selet_dtm("1009")) { PH_start = false; STEP_finish = true; } else { PH_start= true; Status_Str = Status_Str + "(" + Selet_dtm("1009")+"pH)"; } break;//PH温度控制 case "093": if (STEP_TIME <= 0) { STEP_finish = true; } else { STEP_TIME--; } if (errTabler.Rows.Count == 0) Status_Str = "PH" + Resources.PHDetection +"("+ STEP_TIME +")"; break;//PH检测 case "094": if (STEP_TIME <= 0)//控制时间到达结束 { PH_start = false; STEP_finish = true; } else { PH_start = true; STEP_TIME--; } if (errTabler.Rows.Count == 0) Status_Str = "PH" + Resources.PHControl + "(" + STEP_TIME + "S)"; break;//PH控制(时间) default: break; } } else { if (STEP_finish) { RUN_STEPID++; DataRow[] arrRows = dt_TP.Select("STEP ='" + RUN_STEPID + "'"); string T_ID = arrRows[0]["StepID"].ToString(); double T_P1 = Convert.ToDouble(arrRows[0]["Parameter1"].ToString()); double T_P2 = Convert.ToDouble(arrRows[0]["Parameter2"].ToString()); double T_P3 = Convert.ToDouble(arrRows[0]["Parameter3"].ToString()); double T_P4 = Convert.ToDouble(arrRows[0]["Parameter4"].ToString()); double T_P5 = Convert.ToDouble(arrRows[0]["Parameter5"].ToString()); STEP_START(T_ID, T_P1, T_P2, T_P3, T_P4, T_P5); if (ViewID == 1) { sys_workSTEPID = RUN_STEPID; } else { sys_workSTEPID = -1; } } if (errTabler.Rows.Count == 0) { Status_Str = Resources.Await; } } } else if (WORK_RUN == 1) { Status_Str = Resources.Paused; Updata_dtm("1004", 0); Updata_dtd("3009", false); Updata_dtd("3010", false); } else if (WORK_RUN == 0) { // if (Status_Str == Resources.Paused) // { Updata_dtm("1004", 0); Updata_dtm("1005", Selet_dtm("1010")); for (int i = 1; i <128; i++) { Updata_dtd((3000+i).ToString(), false); } // }//清除输出状态 if (errTabler.Rows.Count == 0) { //WorkNumder = "----------"; int TIMEH = DIDETime / 3600; int TIMEM = (DIDETime - TIMEH * 3600) / 60; int TIMES = DIDETime - TIMEH * 3600 - TIMEM * 60; Status_Str = Resources.Dide + string.Format(" {0:D4}", TIMEH) + ":" + string.Format(" {0:D2}", TIMEM) + ":" + string.Format(" {0:D2}", TIMES); } } } public static bool CALL_FR = false;//呼叫状态 string SK5; void FeedingRecords(string WorkOrder,string Dyelot,int TANK,int STEP,int Type) //呼叫输送 { CALL_FR = true; int SQLI = 0; Dictionary dat_FR = new Dictionary(); dat_FR.Add("State", "201"); dat_FR.Add("Tank", TANK.ToString()); dat_FR.Add("Machine", S01); dat_FR.Add("CALL_TIME", sys_Time); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 if (SK5 == "1")//是否检查原料类型 { SQLI = SQLiteHelpers.ExecuteDataSet("select * from Dyelot where " + "Dyelot = '" + Dyelot + "' AND Step = '" + STEP + "' AND Redye ='" + SYS_REDYE + "' AND State = '101' AND ProductType='" + Type + "'", null).Tables[0].Rows.Count; } else { SQLI = SQLiteHelpers.ExecuteDataSet("select * from Dyelot where " + "Dyelot = '" + Dyelot + "' AND Step = '" + STEP + "' AND Redye ='" + SYS_REDYE + "' AND State = '101'", null).Tables[0].Rows.Count; } if (SQLI > 0) SQLiteHelpers.Update("Dyelot", dat_FR, "Dyelot = '" + Dyelot + "' AND Step = '" + STEP + "' AND Redye ='" + SYS_REDYE + "'", null);//行更新 SQLiteHelpers.Close(); //关闭连接 } public static SerialPort port = new SerialPort();//创建串口 static ModbusFactory factory = new ModbusFactory(); string protocols_; // Create Modbus Master static IModbusMaster master = factory.CreateRtuMaster(port); bool PORTOK = false; void UPort() { try { protocols_ = Configini.IniReadvalue("SYS", "Protocols"); port.PortName = Configini.IniReadvalue("SYS", "COM"); port.BaudRate = 57600;//配置 port.DataBits = 8; port.Parity = Parity.Even; port.StopBits = StopBits.One; port.ReadTimeout = 1000; port.WriteTimeout = 1000; port.Open();//打开串口 PORTOK= true; Port_link(); } catch (Exception e) { LogGing.LogGingDATA("800_SerialPort_Not"); LogGing.LogGingDATA(e.Message); ERRinf.ERRinf_w(errTabler, "800_SerialPort_Not", "ERR000"); } }//ck private bool LINK_OK = false; private int LINK_RUN = 0; private int LINK_ERR = 0; bool[] DQ = new bool[63]; ushort DQ_L = 63; bool[] DO = new bool[63]; ushort DO_L = 63; //int[] MW = new int[128]; // ushort MW_L = 128; ushort[] DW = new ushort[63]; ushort DW_L = 63; ushort[] RW = new ushort[63]; ushort RW_L = 63; readonly byte slaveId = 1; private async void Port_link() { if (PORTOK) { await Task.Run(() => { try { if (protocols_ == "MODBUS_RTU") { DO = master.ReadCoils(slaveId, 0, DO_L); //读取线圈 RW = master.ReadHoldingRegisters(slaveId, 0, RW_L); //读取寄存器 master.WriteMultipleCoils(slaveId, 0, DQ); //写入线圈 master.WriteMultipleRegisters(slaveId, 0, DW); //写入寄存器 }//MODBUSRTU else { DO = master.ReadCoils(slaveId, 02255, DO_L); //读取线圈 RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器 master.WriteMultipleCoils(slaveId, 02000, DQ); //写入线圈 master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器 }//SCMODBUSRTU LINK_OK = true; ERRinf.ERRinf_d(errTabler, "ERR001"); LINK_RUN++; } catch (Exception ex) { LINK_OK = false; LINK_ERR++; ERRinf.ERRinf_w(errTabler, "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")", "ERR001"); } finally { Port_link(); } }); } }//发送 public static string SYSlog; void LOG_view()//细节页面 { SYSlog = Resources.MasterCylinder + Resources.Temperature + " : " + string.Format(" {0:###.#}", Convert.ToDouble(Selet_dtm("1010"))) + "°C";//显示实际温度 SYSlog = SYSlog + " | "+ Resources.CylinderBottom + Resources.Temperature + " : " + string.Format(" {0:###.#}", Convert.ToDouble(Selet_dtm("1011"))) + "°C";//显示目标温度 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) { SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.Low_waterlevel + "]";//显示水位 } else if ((IO1015 > MT39) && (IO1015 < MT38)) { SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.Mid_waterlevel + "]";//显示水位 } else if (IO1015 >= MT38) { SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.WaterLevel + " : " + string.Format("{0:D4}", IO1015) + "L =>[" + Resources.High_waterlevel + "]";//显示水位 } if (Selet_dtd("3011")) //主泵状态 { SYSlog = SYSlog + "\n" + Resources.PumpSpeed + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1020"))) + "% => [" + Resources.PumpStart + "]";//主泵状态 }//主泵状态 else { SYSlog = SYSlog + "\n" + Resources.PumpSpeed + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1020"))) + "% => [" + Resources.PumpStops + "]";//主泵状态 } SYSlog = SYSlog + "\n-------------------------------------------------------"; if (MI03 == 1) { SYSlog = SYSlog + "\n" + Resources.MasterCylinder + Resources.Pressure + " : " + string.Format("{0:###.#}", Convert.ToDouble(Selet_dtm("1042"))) + "Bar"; SYSlog = SYSlog + " | " + Resources.Nozzle + Resources.Pressure + " : " + string.Format("{0:###.#}", Convert.ToDouble(Selet_dtm("1043"))) + "Bar"; SYSlog = SYSlog + "\n" + Resources.DifferentialPressure + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1044"))) + "%"; } //压力 if (MainWindowViewModel.MT17 == 1) { SYSlog = SYSlog + "\n" + Resources.Blower + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1021"))) + "%"; }// SYSlog = SYSlog + "\n" + Resources.GuidingWheel + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1046"))) + "M/min"; if (MI02 == 2) SYSlog = SYSlog + "\n" + Resources.Nozzle + Resources.Flowmeter + " : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1045"))) + "L/min";//喷射流量 if (MI01 == 1)// { SYSlog = SYSlog + "\n" + Resources.ClothWheel + "M/min"; SYSlog = SYSlog + "\n" + "1 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1025"))); if (MT18 >= 2) SYSlog = SYSlog + " | " + "2 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1026"))); if (MT18 >= 3) SYSlog = SYSlog + " | " + "3 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1027"))); if (MT18 >= 4) SYSlog = SYSlog + "\n" + "4 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1028"))); if (MT18 >= 5) SYSlog = SYSlog + " | " + "5 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1029"))); if (MT18 >= 6) SYSlog = SYSlog + " | " + "6 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1035"))); if (MT18 >= 7) SYSlog = SYSlog + "\n" + "7 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1037"))); if (MT18 >= 8) SYSlog = SYSlog + " | " + "8 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1039"))); if (MT18 >= 9) SYSlog = SYSlog + " | " + "9 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1051"))); if (MT18 >= 10) SYSlog = SYSlog + "\n" + "10 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1053"))); if (MT18 >= 11) SYSlog = SYSlog + " | " + "11 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1055"))); if (MT18 >= 12) SYSlog = SYSlog + " | " + "12 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1057"))); SYSlog = SYSlog + "\n" + Resources.Cycletime + "Sec"; SYSlog = SYSlog + "\n" + "1 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1030"))); if (MT18 >= 2) SYSlog = SYSlog + " | " + "2 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1031"))); if (MT18 >= 3) SYSlog = SYSlog + " | " + "3 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1032"))); if (MT18 >= 4) SYSlog = SYSlog + "\n" + "4 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1033"))); if (MT18 >= 5) SYSlog = SYSlog + " | " + "5 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1034"))); if (MT18 >= 6) SYSlog = SYSlog + " | " + "6 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1036"))); if (MT18 >= 7) SYSlog = SYSlog + "\n" + "7 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1038"))); if (MT18 >= 8) SYSlog = SYSlog + " | " + "8 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1040"))); if (MT18 >= 9) SYSlog = SYSlog + " | " + "9 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1052"))); if (MT18 >= 10) SYSlog = SYSlog + "\n" + "10 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1054"))); if (MT18 >= 11) SYSlog = SYSlog + " | " + "11 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1056"))); if (MT18 >= 12) SYSlog = SYSlog + " | " + "12 : " + string.Format("{0:D3}", Convert.ToInt16(Selet_dtm("1058"))); }//布轮信息 SYSlog = SYSlog + "\n-------------------------------------------------------"; if (SM01 == 1) { SYSlog = SYSlog + "\n" + Resources.Medicine + Resources.Tank + "1 => [" + Resources.WaterLevel + ":" + string.Format("{0:D4}", Convert.ToInt16(Selet_dtm("1017"))) + "L][" + Resources.Temperature + ":" + string.Format(" {0:###.#}", Convert.ToInt16(Selet_dtm("1012"))) + "°C]"; SYSlog = SYSlog + "\n" + Resources.Dyelot + " : " + TANK1_DYELOT + "_" + TANK1_REDYE + " => " + TANK1_STEP; SYSlog = SYSlog + "\n" + Resources.WorkingStatus + " : " + TANK1; }//附缸1 if (SM02 == 1) { SYSlog = SYSlog + "\n" + Resources.Medicine + Resources.Tank + "2 => [" + Resources.WaterLevel + ":" + string.Format("{0:D4}", Convert.ToInt16(Selet_dtm("1018"))) + "L][" + Resources.Temperature + ":" + string.Format(" {0:###.#}", Convert.ToInt16(Selet_dtm("1013"))) + "°C]"; SYSlog = SYSlog + "\n" + Resources.Dyelot + " : " + TANK2_DYELOT + "_" + TANK1_REDYE + " => " + TANK2_STEP; SYSlog = SYSlog + "\n" + Resources.WorkingStatus + " : " + TANK2; }//附缸2 if (SM03 == 1) { SYSlog = SYSlog + "\n" + Resources.Medicine + Resources.Tank + "3 => [" + Resources.WaterLevel + ":" + string.Format("{0:D4}", Convert.ToInt16(Selet_dtm("1019"))) + "L][" + Resources.Temperature + ":" + string.Format(" {0:###.#}", Convert.ToInt16(Selet_dtm("1014"))) + "°C]"; SYSlog = SYSlog + "\n" + Resources.Dyelot + " : " + TANK3_DYELOT + "_" + TANK1_REDYE + " => " + TANK3_STEP; SYSlog = SYSlog + "\n" + Resources.WorkingStatus + " : " + TANK3; }//附缸3 Sys_log = SYSlog; } public static DataTable dt_d = new DataTable("DIO"); public static DataTable dt_a = new DataTable("AIO"); public static DataTable dt_m = new DataTable("M"); public static DataTable dt_TP = new DataTable(); public static DataTable dt_ParameterSet = new DataTable(); public static DataTable dt_SysSet = new DataTable(); public static void SQL_data()//获得io表 { SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 dt_d = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='DO' OR type='DQ' order by ID", null).Tables[0]; //读取表写入缓存 dt_a = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='AI' OR type='AO' order by ID", null).Tables[0]; dt_m = SQLiteHelpers.ExecuteDataSet("select * from IOName where type='M' order by ID", null).Tables[0]; dt_ParameterSet = SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID asc", null).Tables[0]; dt_SysSet = SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0]; dt_TP = SQLiteHelpers.ExecuteDataSet("select * from RUN", null).Tables[0]; SQLiteHelpers.Close(); dt_d.RowChanged += new DataRowChangeEventHandler(ROW_changed_D);//添加行改变触发事件 dt_a.RowChanged += new DataRowChangeEventHandler(ROW_changed_A); //创建dt_d主建 DataColumn[] dt_dcols =new DataColumn[] { dt_d.Columns["ID"] }; dt_d.PrimaryKey = dt_dcols; //创建dt_a主建 DataColumn[] dt_acols = new DataColumn[] { dt_a.Columns["ID"] }; dt_a.PrimaryKey = dt_acols; //创建dt_m主建 DataColumn[] dt_mcols = new DataColumn[] { dt_m.Columns["ID"] }; dt_m.PrimaryKey = dt_mcols; } private void IOm_DATA() { Updata_dtm("1001", LINK_RUN); Updata_dtm("1002", LINK_ERR); Updata_dtm("1010", (Convert.ToDouble(Selet_dta("4001")) + MT33) / 10); Updata_dtm("1006", Selet_dta("4006")); Updata_dtm("1015", Selet_dta("4007")); Updata_dtm("1016", Selet_dta("4006") * MT16); Updata_dtm("1012", (Convert.ToDouble(Selet_dta("4003")) + MS01) / 10); Updata_dtm("1013", (Convert.ToDouble(Selet_dta("4004")) + MS02) / 10); Updata_dtm("1014", (Convert.ToDouble(Selet_dta("4005")) + MS03) / 10); } private async void IO_data()//刷新 { await Task.Run(() => { for (ushort i = 0; i < DO_L; i++) { Upplc_dtd((i + 2001).ToString(), DO[i]); } for (ushort i = 0; i < DQ_L; i++) { DQ[i] = Seplc_dtd((i + 3001).ToString()); } for (ushort i = 0; i < RW_L; i++) { Upplc_dta((i + 4001).ToString(), RW[i]); } for (ushort i = 0; i < DW_L; i++) { DW[i] = Convert.ToUInt16(Seplc_dta((i + 5001).ToString())); } }); } public static object D_view=true; public static object A_view=true; public static bool User_Button = false; public void IO_view()//IO显示 { if (ViewID == 5) { try { SYSData_M = ToObservableCollection(dt_m); } catch (Exception) { } try { if ((bool)A_view) SYSData_A = ToObservableCollection(dt_a); } catch (Exception) { } try { if ((bool)D_view) SYSData_D = ToObservableCollection(dt_d); } catch (Exception) { } } } public void TechnologicalProcess_view()//显示 { if (ViewID == 1) { try { TechnologicalProcess_View = ToObservableCollection(dt_TP); } catch (Exception) { } } } private static void ROW_changed_D(object sender, DataRowChangeEventArgs e)//开关量改变事件 { try { int MD = int.Parse(e.Row.Field("ID")); if (MD < 3001 || MD > 3004) { APILog.IOlog(e.Row.Field("IOName") , e.Row.Field("type") , e.Row.Field("DIO") , e.Row.Field("ID") , e.Row.Field("PLC")); } } catch (Exception) { } } private static void ROW_changed_A(object sender, DataRowChangeEventArgs e)//模拟量改变事件 { try { APILog.IOlog(e.Row.Field("IOName") , e.Row.Field("type") , e.Row.Field("AIO") , e.Row.Field("ID") , e.Row.Field("PLC")); } catch (Exception) { } } public static double Selet_dtm(string key)//M寄存器 { try { lock (dt_m) { // DataRow[] arrRows = dt_m.Select("ID='" + key + "'"); // double index = Convert.ToDouble(arrRows[0]["Value"].ToString()); DataRow drEmployee = dt_m.Rows.Find(key); double index = drEmployee.Field("value"); return index; } } catch (Exception ex) { LogGing.LogGingDATA("SDTM:"+ex.ToString()); return -1; } } public static bool Selet_dtd(string key)//D寄存器 { try { lock (dt_d) { // DataRow[] arrRows = dt_d.Select("ID='" + key + "'"); // bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString()); DataRow drEmployee = dt_d.Rows.Find(key); bool index = drEmployee.Field("DIO"); return index; } } catch (Exception ex) { LogGing.LogGingDATA("SDTD:" + ex.ToString()); return false; } } public static int Selet_dta(string key)//A寄存器 { try { lock (dt_a) { // DataRow[] arrRows = dt_a.Select("ID='" + key + "'"); // int index = Convert.ToInt16(arrRows[0]["AIO"].ToString()); DataRow drEmployee = dt_a.Rows.Find(key); int index = drEmployee.Field("AIO"); return index; } } catch (Exception ex) { LogGing.LogGingDATA("SDTA:" + ex.ToString()); return -1; } } public static void Updata_dtm(string key,double Value)//更新M寄存器 { try { lock (dt_m) { DataRow drEmployee = dt_m.Rows.Find(key); if (drEmployee.Field("value") != Value) { drEmployee.BeginEdit(); drEmployee["Value"] = Value; drEmployee.EndEdit(); drEmployee.ClearErrors(); } } } catch (Exception ex) { LogGing.LogGingDATA("UDTM:" + ex.ToString()); } } public static void Updata_dtd(string key, bool Value)//更新D寄存器 { try { lock (dt_d)//锁 { DataRow drEmployee = dt_d.Rows.Find(key); if (drEmployee.Field("DIO") != Value) { drEmployee.BeginEdit(); drEmployee["DIO"] = Value; drEmployee.EndEdit(); drEmployee.ClearErrors(); } } } catch (Exception ex) { LogGing.LogGingDATA("UDTD:" + ex.ToString()); } } public static void Updata_dta(string key, int Value)//更新A寄存器 { try { lock (dt_a) { DataRow drEmployee = dt_a.Rows.Find(key); if (drEmployee.Field("AIO") != Value) { drEmployee.BeginEdit(); drEmployee["AIO"] = Value; drEmployee.EndEdit(); drEmployee.ClearErrors(); } } } catch (Exception ex) { LogGing.LogGingDATA("UDTA:" + ex.ToString()); } } public static void Upplc_dtd(string key, bool Value)//更新PLCD { try { lock (dt_d)//锁 { DataRow[] arrRows = dt_d.Select("PLC=" + key); foreach (DataRow row in arrRows) { if ((bool)row["DIO"] != Value) row["DIO"] = Value; } } } catch (Exception ex) { LogGing.LogGingDATA("PLCDTD:" + ex.ToString()); } } public static void Upplc_dta(string key, int Value)//更新PLCA寄存器 { try { lock (dt_a) { DataRow[] arrRows = dt_a.Select("PLC=" + key); foreach (DataRow row in arrRows) { if ((int)row["AIO"] != Value) row["AIO"] = Value; } } } catch (Exception ex) { LogGing.LogGingDATA("PLCDTA:" + ex.ToString()); } } public static bool Seplc_dtd(string key)//PLCD寄存器 { try { lock (dt_d) { // DataRow[] arrRows = dt_d.Select("ID='" + key + "'"); // bool index = Convert.ToBoolean(arrRows[0]["DIO"].ToString()); DataRow drEmployee = dt_d.Select("PLC=" + key).First(); bool index = drEmployee.Field("DIO"); return index; } } catch (Exception ex) { LogGing.LogGingDATA("PLCDTD:" + ex.ToString()); return false; } } public static int Seplc_dta(string key)//PLCA寄存器 { try { lock (dt_a) { // DataRow[] arrRows = dt_a.Select("ID='" + key + "'"); // int index = Convert.ToInt16(arrRows[0]["AIO"].ToString()); DataRow drEmployee = dt_a.Select("PLC=" + key).First(); int index = drEmployee.Field("AIO"); return index; } } catch (Exception ex) { LogGing.LogGingDATA("PLCDTA:" + ex.ToString()); return -1; } } ObservableCollection sysData_A = new ObservableCollection(); ObservableCollection sysData_D = new ObservableCollection(); ObservableCollection sysData_M = new ObservableCollection(); ObservableCollection technologicalProcess_View = new ObservableCollection(); public ObservableCollection SYSData_A { get { return sysData_A; } set { sysData_A = value; RaisePropertyChanged("SYSData_A"); } } public ObservableCollection SYSData_D { get { return sysData_D; } set { sysData_D = value; RaisePropertyChanged("SYSData_D"); } } public ObservableCollection SYSData_M { get { return sysData_M; } set { sysData_M = value; RaisePropertyChanged("SYSData_M"); } } public ObservableCollection TechnologicalProcess_View { get { return technologicalProcess_View; } set { technologicalProcess_View = value; RaisePropertyChanged("TechnologicalProcess_View"); } } public class DATA_A { public string IOName { get; set; } public int AIO { get; set; } public string ID { get; set; } public string PLC { get; set; } public string type { get; set; } } public class DATA_D { public string IOName { get; set; } public bool DIO { get; set; } public string ID { get; set; } public string PLC { get; set; } public string type { get; set; } } public class DATA_M { public string IOName { get; set; } public double Value { get; set; } public string ID { get; set; } public string PLC { get; set; } public string type { get; set; } } public class TechnologicalProcess { public int RUN { get; set; } public string ProgramID { get; set; } public string Program { get; set; } public double Step { get; set; } public string StepID { get; set; } public string StepName { get; set; } public string ParameterName { get; set; } public string Parameter1 { get; set; } public string Parameter2 { get; set; } public string Parameter3 { get; set; } public string Parameter4 { get; set; } public string Parameter5 { get; set; } public string Parameter6 { get; set; } public string Parameter7 { get; set; } public string Parameter8 { get; set; } public string Parameter9 { get; set; } public string Parameter10 { get; set; } public string DYELOT { get; set; } } public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new() { Type t = typeof(T); PropertyInfo[] propertys = t.GetProperties(); ObservableCollection lst = new ObservableCollection(); string typeName = string.Empty; foreach (DataRow dr in dt.Rows) { T entity = new T(); foreach (PropertyInfo pi in propertys) { typeName = pi.Name; if (dt.Columns.Contains(typeName)) { if (!pi.CanWrite) continue; object value = dr[typeName]; if (value == DBNull.Value) continue; if (pi.PropertyType == typeof(string)) { pi.SetValue(entity, value.ToString(), null); } else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?)) { pi.SetValue(entity, int.Parse(value.ToString()), null); } else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime)) { pi.SetValue(entity, DateTime.Parse(value.ToString()), null); } else if (pi.PropertyType == typeof(float)) { pi.SetValue(entity, float.Parse(value.ToString()), null); } else if (pi.PropertyType == typeof(double)) { pi.SetValue(entity, double.Parse(value.ToString()), null); } else { pi.SetValue(entity, value, null); } } } lst.Add(entity); } return lst; } } }