You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1460 lines
74 KiB
1460 lines
74 KiB
using DyeingComputer.UserClass;
|
|
using LiveChartsCore.Geo;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NModbus;
|
|
using OpenTK.Graphics.ES11;
|
|
using ScottPlot.Palettes;
|
|
using ScottPlot.TickGenerators.TimeUnits;
|
|
using SunlightCentralizedControlManagement_SCCM_.EX.Exchange;
|
|
using SunlightCentralizedControlManagement_SCCM_.Properties;
|
|
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
|
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
using System.IO.Ports;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
using System.Speech.Synthesis;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Markup;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using System.Xml.Linq;
|
|
using TouchSocket.Core;
|
|
using TouchSocket.SerialPorts;
|
|
using TouchSocket.Sockets;
|
|
using static MaterialDesignThemes.Wpf.Theme;
|
|
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
|
using static SunlightCentralizedControlManagement_SCCM_.View.MachinesView;
|
|
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.ManualDyelotModel;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
|
|
|
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
|
{
|
|
/// <summary>
|
|
/// 变量传递至ui
|
|
/// </summary>
|
|
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
|
|
{
|
|
//调用配置文件
|
|
private static UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
|
|
public static string SQLIP; //读配置文件
|
|
public static string SQLNAME;
|
|
public static string SQMOD;
|
|
public static string SQLUSER;
|
|
public static string SQLPASWORD;
|
|
public static string SN_ID;
|
|
public static string SN_KEY;
|
|
public static bool DyelotsDispenser;
|
|
public static SqlConnection conn_SC =new SqlConnection();//数据库
|
|
public static SQLiteHelper SQLiteHelpers = null; //定义数据库
|
|
private BDC_SQL.BDCSqlHelper bDCSqlHelper = new BDC_SQL.BDCSqlHelper();
|
|
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
|
public static SQLiteHelper SQLiteChartAdress = null; //定义数据库
|
|
private static readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
|
|
public static DataTable Machines = new DataTable(); //设备表缓存
|
|
// public static DataRow MachinesROW;
|
|
public static DataTable USER_data = new DataTable();
|
|
public static DataTable Dyelot_CALL = new DataTable();
|
|
public static DataTable Whole_dat = new DataTable();
|
|
public static UserControls.info[] inf = new UserControls.info[200]; //定义总览信息卡
|
|
public static int ERR_c = 0;//错误计数器
|
|
public bool UPort1, UPort2, UPort3;
|
|
public static bool[] USER_Capacity { set; get; } = new bool[99];
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
try
|
|
{
|
|
SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
|
SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
|
SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
|
SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
|
SQLPASWORD = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
|
SN_ID = Configini.IniReadvalue("SN", "SN2");
|
|
SN_KEY = Configini.IniReadvalue("SN", "SN1");
|
|
DyelotsDispenser = Convert.ToBoolean(Configini.IniReadvalue("SYS", "DyelotsDispenser"));
|
|
|
|
SQLiteChartAdress = new SQLiteHelper(ChartAdress); //数据库连接路径
|
|
SQLiteChartAdress.Open(); //打开数据库
|
|
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
|
SQLiteHelpers.Open(); //打开数据库
|
|
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
|
|
USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0];
|
|
Dyelot_CALL = SQLiteHelpers.ExecuteDataSet("select * from Dyelot", null).Tables[0].Clone();
|
|
|
|
Whole_dat.Columns.Add("Machine", Type.GetType("System.String"));
|
|
Whole_dat.Columns.Add("DateTime", Type.GetType("System.DateTime"));
|
|
Whole_dat.Columns.Add("DAT", Type.GetType("System.Double"));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.ERRDATA(ex);
|
|
}
|
|
|
|
USERCapacity(App.USER_Purview);//App.USER_Purview);
|
|
ClientNEW();
|
|
TcpClientNEW();
|
|
PortClientNEW();
|
|
SQL_LINK();
|
|
CountDown();
|
|
}
|
|
public static void USERCapacity(string user) //权限
|
|
{
|
|
if (user != "ENGINEER")
|
|
{
|
|
string USER_Cap = USER_data.Select("Name='" + user + "'").First().Field<string>("Capacity").ToString();
|
|
for (int i = 0; i < USER_Cap.Length; i++)
|
|
{
|
|
if (USER_Cap.Substring(i, 1) == "1")
|
|
{
|
|
USER_Capacity[i] = true;
|
|
}
|
|
else
|
|
{
|
|
USER_Capacity[i] = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < 99; i++)
|
|
{
|
|
USER_Capacity[i] = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public async void SQL_LINK()//连接dbc数据库
|
|
{
|
|
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
|
|
try
|
|
{
|
|
if (SQMOD == "Windows Authentication") //连接数据库测试
|
|
{
|
|
conn_SC = new SqlConnection("server=" + SQLIP + ";database=" + SQLNAME + ";Trusted_Connection=SSPI");
|
|
}
|
|
else
|
|
{
|
|
conn_SC = new SqlConnection("server=" + SQLIP + ";database=" + SQLNAME + ";User ID=" + SQLUSER + ";Password=" + SQLPASWORD);
|
|
}
|
|
await conn_SC.OpenAsync(); //连接数据库
|
|
conn_SC.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER");
|
|
ERR_c++;
|
|
}
|
|
|
|
if (SQMOD == "Windows Authentication") //连接数据库测试
|
|
{
|
|
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, true);
|
|
}
|
|
else
|
|
{
|
|
bDCSqlHelper.Config(SQLIP, SQLNAME, SQLUSER, SQLPASWORD, false);
|
|
}
|
|
}
|
|
|
|
public void CountDown()
|
|
{
|
|
DispatcherTimer dis1s = new DispatcherTimer
|
|
{
|
|
Interval = TimeSpan.FromSeconds(1) //秒
|
|
};
|
|
dis1s.Tick += new EventHandler(Tick_Main_1S);//每执行的方法
|
|
dis1s.Start();//计时开始
|
|
DispatcherTimer dis50ms = new DispatcherTimer
|
|
{
|
|
Interval = TimeSpan.FromMilliseconds(100) //毫秒
|
|
};
|
|
dis50ms.Tick += new EventHandler(DisTimer_50MS);//每执行的方法
|
|
dis50ms.Start();//计时开始
|
|
}//时间周期初始化
|
|
int Time5 = 0, Time30 = 0;
|
|
void DisTimer_50MS(object sender, EventArgs e)//Tick_Event周期执行事件50MS
|
|
{
|
|
int _id = -1;
|
|
if (stringQueue.Count > 0) //信息发送队列
|
|
{
|
|
QueueString t = stringQueue.Dequeue();
|
|
MachiensTcpClient[t.ID].SendAsync(t.DAT);
|
|
_id = t.ID;
|
|
}
|
|
if (stringQueueinf.Count > 0)
|
|
{
|
|
QueueString inf = stringQueueinf.Dequeue();
|
|
if (_id != inf.ID) MachiensTcpClient[inf.ID].SendAsync(inf.DAT);
|
|
}
|
|
/*if (stringQueueSerial.Count > 0) //ck信息发送队列
|
|
{
|
|
QueueSerial t = stringQueueSerial.Dequeue();
|
|
MachiensPortClient[t.ID].Send(t.DAT);
|
|
}*/
|
|
}
|
|
void Tick_Main_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
|
{
|
|
/*下传工单信息*/
|
|
DataTable WorkOrderstepdata = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='111' or State='112') AND EndTime >'" +
|
|
DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
|
|
for (int k = 0; k < WorkOrderstepdata.Rows.Count; k++)
|
|
{
|
|
string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString();
|
|
//string m= WorkOrderstepdata.Rows[k].Field<string>("Machines");
|
|
if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'")))
|
|
{//网络
|
|
//string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString();
|
|
DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" +
|
|
WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null).Tables[0];
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = index,
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.ToJsonString()
|
|
});
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 112 } },
|
|
"WorkOrder ='" + WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
|
|
}
|
|
else
|
|
{//串口
|
|
DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" +
|
|
WorkOrderstepdata.Select()[k].Field<object>("WorkOrder").ToString() + "' AND ReDye ='"+
|
|
WorkOrderstepdata.Select()[k].Field<object>("ReDye").ToString() + "' AND Mode<> '201'", null).Tables[0];
|
|
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
|
|
if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
}
|
|
/*下传工单总览*/
|
|
DataTable WorkOrderdata = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='100' or State='110') AND EndTime >'" +
|
|
DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
|
|
for (int k = 0; k < WorkOrderdata.Rows.Count; k++)
|
|
{
|
|
string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
|
|
//string m = WorkOrderdata.Rows[k].Field<string>("Machines");
|
|
if (Convert.ToBoolean( Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'")))
|
|
{//网络
|
|
//string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
|
|
string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString();
|
|
|
|
if ((State == "101") || (State == "201") || (State == "202") || (State == "309"))
|
|
{
|
|
DataTable dataTable = WorkOrderdata.Clone();
|
|
// WorkOrderdata.Columns.Remove("Machines");
|
|
DataRow dt_temp = WorkOrderdata.Select()[k];
|
|
dt_temp.BeginEdit();
|
|
dt_temp["State"] = "101";
|
|
dt_temp.EndEdit();
|
|
dataTable.Rows.Add(dt_temp.ItemArray);
|
|
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = index,
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString()
|
|
});
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
|
|
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
|
|
}
|
|
}
|
|
else
|
|
{//串口
|
|
//string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
|
|
string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString();
|
|
|
|
if ((State == "101") || (State == "201") || (State == "202") || (State == "309"))
|
|
{
|
|
DataTable dataTable = WorkOrderdata.Clone();
|
|
// WorkOrderdata.Columns.Remove("Machines");
|
|
DataRow dt_temp = WorkOrderdata.Select()[k];
|
|
dt_temp.BeginEdit();
|
|
dt_temp["State"] = "101";
|
|
dt_temp.EndEdit();
|
|
dataTable.Rows.Add(dt_temp.ItemArray);
|
|
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString());
|
|
if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString()
|
|
});
|
|
}
|
|
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
|
|
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
|
|
}
|
|
}
|
|
}
|
|
/*下传工单设置*/
|
|
DataTable WorkOrderset_ = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='113'or State='114') AND EndTime >'" +
|
|
DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
|
|
for (int k = 0; k < WorkOrderset_.Rows.Count; k++)
|
|
{
|
|
string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
|
|
//string m = WorkOrderset_.Rows[k].Field<string>("Machines");
|
|
if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderset_m + "'")))
|
|
{//网络
|
|
//string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
|
|
string WorkOrderset_w = WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString();
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString());
|
|
|
|
DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" +
|
|
WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存
|
|
if (WorkOrder_set.Rows.Count > 0)
|
|
{
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = index,
|
|
DAT = "SC812" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(WorkOrder_set).ToJsonString()
|
|
});
|
|
}
|
|
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 114 } },
|
|
"WorkOrder ='" + WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
|
|
}
|
|
else
|
|
{//串口
|
|
//string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
|
|
string WorkOrderset_w = WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString();
|
|
|
|
DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" +
|
|
WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存
|
|
if (WorkOrder_set.Rows.Count > 0)
|
|
{
|
|
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString());
|
|
if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC812[" +
|
|
Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" +
|
|
DataTableToDictionary(WorkOrder_set).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC812[" +
|
|
Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" +
|
|
DataTableToDictionary(WorkOrder_set).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC812[" +
|
|
Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" +
|
|
DataTableToDictionary(WorkOrder_set).ToJsonString()
|
|
});
|
|
}
|
|
else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = index,
|
|
DAT = "SC812[" +
|
|
Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" +
|
|
DataTableToDictionary(WorkOrder_set).ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
|
|
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
|
|
|
|
}
|
|
}
|
|
|
|
//系统时间
|
|
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
//更新机台状态与发送指令
|
|
foreach (DataRow MachinesRow in Machines.Rows)
|
|
{
|
|
if (Convert.ToBoolean(MachinesRow["Type"]))
|
|
{
|
|
if (MachinesRow["State"].ToString() == "802")
|
|
{
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = Convert.ToInt16( MachinesRow["ID"]),
|
|
DAT = "SC830" + MachinesRow["SYSKEY"]
|
|
});//信息插入队列
|
|
|
|
bool mode =Convert.ToBoolean( MachinesRow["LOCK"]) ;//发送锁定状态
|
|
if (mode)
|
|
{
|
|
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
|
|
dat_829.Clear();
|
|
dat_829.Add("NAME", "LOCK");
|
|
dat_829.Add("VALUE", "True");
|
|
DataRow drEmployee = Machines.Select("ID='" + MachinesRow["ID"] + "'").First();
|
|
int index = Convert.ToInt16(drEmployee.Field<object>("ID"));
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = index,
|
|
DAT = "SC829" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dat_829.ToJsonString()
|
|
});
|
|
}
|
|
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");
|
|
}
|
|
int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]);
|
|
if (m_run == 0)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态
|
|
}
|
|
else if (m_run == 1)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态
|
|
}
|
|
else if (m_run == 2)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行
|
|
}
|
|
|
|
if (Convert.ToBoolean(MachinesRow["ERR"]))
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误
|
|
}
|
|
|
|
string mac_s = MachinesRow["State"].ToString();
|
|
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
|
|
{
|
|
stringQueueinf.Enqueue(new QueueString
|
|
{
|
|
ID = Convert.ToInt16( MachinesRow["ID"]),
|
|
DAT = "SC830" + MachinesRow["SYSKEY"]
|
|
});//信息插入队列
|
|
}
|
|
}
|
|
else
|
|
{//串口发送
|
|
if (MachinesRow["State"].ToString() == "802")
|
|
{
|
|
if (MachinesRow["Serial"].ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
|
|
bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态
|
|
if (mode)
|
|
{
|
|
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
|
|
dat_829.Clear();
|
|
dat_829.Add("NAME", "LOCK");
|
|
dat_829.Add("VALUE", "True");
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
|
|
bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态
|
|
if (mode)
|
|
{
|
|
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
|
|
dat_829.Clear();
|
|
dat_829.Add("NAME", "LOCK");
|
|
dat_829.Add("VALUE", "True");
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
|
|
bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态
|
|
if (mode)
|
|
{
|
|
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
|
|
dat_829.Clear();
|
|
dat_829.Add("NAME", "LOCK");
|
|
dat_829.Add("VALUE", "True");
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
|
|
bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态
|
|
if (mode)
|
|
{
|
|
Dictionary<string, object> dat_829 = new Dictionary<string, object>();
|
|
dat_829.Clear();
|
|
dat_829.Add("NAME", "LOCK");
|
|
dat_829.Add("VALUE", "True");
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
}
|
|
int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]);
|
|
if (m_run == 0)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态
|
|
}
|
|
else if (m_run == 1)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态
|
|
}
|
|
else if (m_run == 2)
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行
|
|
}
|
|
|
|
if (Convert.ToBoolean(MachinesRow["ERR"]))
|
|
{
|
|
Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误
|
|
}
|
|
|
|
string mac_s = MachinesRow["State"].ToString();
|
|
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
|
|
{
|
|
if (MachinesRow["Serial"].ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC830[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Time5 > 5)
|
|
{
|
|
Tick_Event_5S();
|
|
Time5 = 0;
|
|
}
|
|
else { Time5++; }
|
|
if (Time30 > 30)
|
|
{
|
|
Tick_Event_30S();
|
|
Time30 = 0;
|
|
}
|
|
else { Time30++; }
|
|
}
|
|
async void Tick_Event_5S()//Tick_Event周期执行事件5S
|
|
{
|
|
foreach (DataRow MachinesRow in Machines.Rows)
|
|
{
|
|
/**发送800指令**/
|
|
if (MachinesRow["State"].ToString() == "801")
|
|
{
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC800:SCCM[" + MachinesRow["IP"] + ";" + MachinesRow["PORT"] + "]"
|
|
});//信息插入队列
|
|
}
|
|
|
|
/**染机用户信息**/
|
|
try
|
|
{
|
|
if (MachinesRow["UserInfoStart"].ToString() == "901")//打开用户提示信息
|
|
{
|
|
MainWindow.InfData.Rows.Add(new object[] {
|
|
MachinesRow["Name"],Properties.Resources.Pequest + MachinesRow["UserInfo"],
|
|
MachinesRow["SYSKEY"],MachinesRow["ID"]});
|
|
|
|
Updata_Machines(Machines, "UserInfoStart", "ID='" + MachinesRow["ID"] + "'", "900");
|
|
}
|
|
if (MachinesRow["UserInfoStart"].ToString() == "902")//删除用户提示信息
|
|
{
|
|
MainWindow.InfData.Select("ID='" + MachinesRow["ID"] + "'").First().Delete();
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
/**染机呼叫状态**/
|
|
try
|
|
{
|
|
if (Convert.ToBoolean(MachinesRow["CALL"]))
|
|
{
|
|
if (Convert.ToBoolean(MachinesRow["Type"]))
|
|
{//网络
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC827" + MachinesRow["SYSKEY"]
|
|
});
|
|
}
|
|
else
|
|
{//串口
|
|
if (MachinesRow["Serial"].ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC827[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC827[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC827[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC827[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
try
|
|
{//处理呼叫请求列表完成发送后(202》203)
|
|
if (Dyelot_CALL.Select("State='202'").Count() > 0)
|
|
{
|
|
DataRow row = Dyelot_CALL.Select("State='202'").First();
|
|
var r = await bDCSqlHelper.UPDATA("Machines", "Name = '" + row.Field<string>("Machine") + "'", row);
|
|
if (r > 0)
|
|
{
|
|
DataRow[] dataRows = Dyelot_CALL.Select("Dyelot='" + row.Field<string>("Dyelot") +
|
|
"' and Redye='" + row.Field<int>("Redye") +
|
|
"' and Step='" + row.Field<int>("Step") + "'");
|
|
foreach (DataRow dataRow in dataRows)
|
|
{
|
|
dataRow.BeginEdit();
|
|
dataRow["State"] = 203;
|
|
dataRow.EndEdit();
|
|
}
|
|
Dictionary<string, object> dat_ = new Dictionary<string, object>();//缓存函数
|
|
dat_.Add("State", 203);
|
|
SQLiteHelpers.Update("DyelotHistory", dat_,
|
|
"Dyelot='" + row.Field<string>("Dyelot") +
|
|
"' and Redye='" + row.Field<int>("Redye") +
|
|
"' and Step='" + row.Field<int>("Step") + "'", null);// 执行插入
|
|
}
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
try
|
|
{//检查呼叫回复列表确认是否完成(203=>301)
|
|
if (Dyelot_CALL.Select("State='203'").Count() > 0)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
// DataRow[] dataRows = Dyelot_CALL.Select("State='203'");
|
|
foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'"))
|
|
{
|
|
if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309"))
|
|
{
|
|
if (dataRow.Field<int>("Type") == 2)
|
|
{
|
|
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
|
|
"' AND (DyeState = 301 OR DyeState = 309)");
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Select("DyeState = 301").Count() > 0)
|
|
{
|
|
// Dyelot_CALL.Rows.Remove(dataRow);
|
|
|
|
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
|
|
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
|
|
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
|
|
" AND StepNumber = " + dataRow.Field<int>("Step"));
|
|
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
if (dr.Rows.Count > 0)
|
|
{
|
|
DataRow data = dr.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = data.Field<float>("Amount");
|
|
Row["DispenseStartTime"] = data.Field<DateTime>("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row["DispenseEndTime"] = data.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
else
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
else if (dt.Select("DyeState = 309").Count() > 0)
|
|
{
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 309;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (dataRow.Field<int>("Type") == 3)
|
|
{
|
|
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
|
|
"' AND (PowderState = 301 OR PowderState = 309)");
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Select("PowderState = 301").Count() > 0)
|
|
{
|
|
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
|
|
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
|
|
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
|
|
" AND StepNumber = " + dataRow.Field<int>("Step"));
|
|
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
if (dr.Rows.Count > 0)
|
|
{
|
|
DataRow data = dr.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = data.Field<float>("Amount");
|
|
Row["DispenseStartTime"] = data.Field<DateTime>("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row["DispenseEndTime"] = data.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
else
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
else if (dt.Select("PowderState = 309").Count() > 0)
|
|
{
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 309;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field<string>("Machine") +
|
|
"' AND (ChemicalState = 301 OR ChemicalState = 309)");
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Select("ChemicalState = 301").Count() > 0)
|
|
{
|
|
DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe",
|
|
"Dyelot = '" + dataRow.Field<string>("Dyelot") +
|
|
"' AND ReDye = " + dataRow.Field<int>("ReDye") +
|
|
" AND StepNumber = " + dataRow.Field<int>("Step"));
|
|
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
if (dr.Rows.Count > 0)
|
|
{
|
|
DataRow data = dr.Select("ProductCode='" + Row.Field<string>("ProductCode") + "'").First();
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = data.Field<float>("Amount");
|
|
Row["DispenseStartTime"] = data.Field<DateTime>("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row["DispenseEndTime"] = data.Field<DateTime>("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
else
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 301;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
else if (dt.Select("ChemicalState = 309").Count() > 0)
|
|
{
|
|
foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" +
|
|
dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'"))
|
|
{
|
|
Row.BeginEdit();
|
|
Row["State"] = 309;
|
|
Row["Amount"] = 0;
|
|
Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
Row.EndEdit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
try
|
|
{//301列表发送完成至染机(203=>301)
|
|
foreach (DataRow row in Dyelot_CALL.Select("State='301' OR State='309'"))
|
|
{
|
|
Dictionary<string, object> Product_ = new Dictionary<string, object>();//缓存函数
|
|
Product_.Add("State", row.Field<int>("State"));
|
|
Product_.Add("Step", row.Field<int>("Step"));
|
|
Product_.Add("Dyelot", row.Field<string>("Dyelot"));
|
|
Product_.Add("ProductCode", row.Field<string>("ProductCode"));
|
|
Product_.Add("Amount", row.Field<object>("Amount"));
|
|
Product_.Add("DispenseEndTime", row.Field<object>("DispenseEndTime"));
|
|
|
|
if (Convert.ToBoolean(MachinesRow["Type"]))
|
|
{//网络
|
|
stringQueue.Enqueue(new QueueString
|
|
{
|
|
ID = Convert.ToInt16(Selet_Machines(Machines,
|
|
"ID", "Name='" + row.Field<string>("Machine") + "'")),
|
|
DAT = "SC828" + Selet_Machines(Machines,
|
|
"SYSKEY", "Name='" + row.Field<string>("Machine") + "'") + Product_.ToJsonString()
|
|
});
|
|
}
|
|
else
|
|
{//串口
|
|
if (MachinesRow["Serial"].ToString() == "PORT1")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT2")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT3")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
|
|
});
|
|
}
|
|
else if (MachinesRow["Serial"].ToString() == "PORT4")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString()
|
|
});
|
|
}
|
|
}
|
|
|
|
if (row["State"].ToString() == "309")
|
|
{
|
|
MainWindow.InfData.Rows.Add(new object[] { row["Machine"],
|
|
Resources.Step + row["Step"]+ Resources.DispenseException,
|
|
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
|
|
Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")});
|
|
}
|
|
Dyelot_CALL.Rows.Remove(row);
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
}
|
|
}
|
|
void Tick_Event_30S()
|
|
{
|
|
try
|
|
{
|
|
/*曲线图*/
|
|
for (int i = 0; i < Machines.Rows.Count; i++)//曲线图
|
|
{
|
|
string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString();
|
|
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))
|
|
{
|
|
DataRow whole_Dat = Whole_dat.NewRow();
|
|
whole_Dat["Machine"] = Selet_Machines(Machines, "NAME", "ID='" + i + "'").ToString();
|
|
whole_Dat["DateTime"] = DateTime.Now;
|
|
whole_Dat["DAT"] = Convert.ToDouble(Selet_Machines(Machines, "Temperature", "ID='" + i + "'"));
|
|
Whole_dat.Rows.Add(whole_Dat);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception EX) { LogGing.ERRDATA(EX); }
|
|
}
|
|
|
|
public static TcpClient[] MachiensTcpClient = new TcpClient[99];
|
|
public static SerialPortClient[] MachiensPortClient = new SerialPortClient[4];
|
|
//public static DataRow[] machinesdata = new DataRow[999];
|
|
public void ClientNEW()
|
|
{
|
|
foreach (DataRow dataRow in Machines.Rows)
|
|
{
|
|
dataRow.BeginEdit();
|
|
dataRow["State"] = 800;
|
|
dataRow["Temperature"] = 0;
|
|
dataRow["WaterLevel"] = 0;
|
|
dataRow["WORK_RUN"] = -1;
|
|
dataRow["ERR"] = false;
|
|
dataRow["LOCK"] = false;
|
|
dataRow["AUTO"] = false;
|
|
dataRow["CALL"] = false;
|
|
dataRow["UserInfoStart"] = 900;
|
|
dataRow.EndEdit();
|
|
dataRow.AcceptChanges();
|
|
}
|
|
}
|
|
public void TcpClientNEW()
|
|
{
|
|
foreach (DataRow dataRow in Machines.Rows)
|
|
{
|
|
if (Convert.ToBoolean(dataRow["Type"]))
|
|
{
|
|
MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] = new TcpClient();
|
|
_ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接
|
|
, dataRow["IP"].ToString(), dataRow["PORT"].ToString());
|
|
}
|
|
}
|
|
}
|
|
public async void PortClientNEW()
|
|
{
|
|
if (Machines.Select("Type='false' AND Serial='PORT1'").Length > 0)
|
|
{
|
|
AsyncSerialPortClient.PortCOM1 = Configini.IniReadvalue("SYS", "COMP1");
|
|
MachiensPortClient[0] = new SerialPortClient();
|
|
|
|
await AsyncSerialPortClient.PortClient(MachiensPortClient[0] //建立连接
|
|
, Configini.IniReadvalue("SYS", "COMP1")
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1")));
|
|
AsyncSerialPortClient._responseEvent.Set();
|
|
|
|
Port1_link();
|
|
}
|
|
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
|
|
{
|
|
AsyncSerialPortClient.PortCOM2 = Configini.IniReadvalue("SYS", "COMP2");
|
|
MachiensPortClient[1] = new SerialPortClient();
|
|
|
|
await AsyncSerialPortClient.PortClient2(MachiensPortClient[1] //建立连接
|
|
, Configini.IniReadvalue("SYS", "COMP2")
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2")));
|
|
AsyncSerialPortClient._responseEvent2.Set();
|
|
|
|
Port2_link();
|
|
}
|
|
if (Machines.Select("Type='false' AND Serial='PORT3'").Length > 0)
|
|
{
|
|
AsyncSerialPortClient.PortCOM3 = Configini.IniReadvalue("SYS", "COMP3");
|
|
MachiensPortClient[2] = new SerialPortClient();
|
|
|
|
await AsyncSerialPortClient.PortClient3(MachiensPortClient[2] //建立连接
|
|
, Configini.IniReadvalue("SYS", "COMP3")
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3")));
|
|
AsyncSerialPortClient._responseEvent3.Set();
|
|
|
|
Port3_link();
|
|
}
|
|
if (Machines.Select("Type='false' AND Serial='PORT4'").Length > 0)
|
|
{
|
|
AsyncSerialPortClient.PortCOM4 = Configini.IniReadvalue("SYS", "COMP4");
|
|
MachiensPortClient[3] = new SerialPortClient();
|
|
|
|
await AsyncSerialPortClient.PortClient4(MachiensPortClient[3] //建立连接
|
|
, Configini.IniReadvalue("SYS", "COMP4")
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4")));
|
|
AsyncSerialPortClient._responseEvent4.Set();
|
|
|
|
Port4_link();
|
|
}
|
|
}
|
|
private async void Port1_link()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (MachiensPortClient[0].Online )
|
|
{
|
|
try
|
|
{
|
|
if (stringQueueSerial_1.Count > 0) //信息发送队列
|
|
{
|
|
if (AsyncSerialPortClient._responseEvent.IsSet)
|
|
{
|
|
QueueSerial t = stringQueueSerial_1.Dequeue();
|
|
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT + "\n");
|
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'"))
|
|
{
|
|
if (MachinesRow["State"].ToString() == "800")
|
|
{
|
|
stringQueueSerial_1.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
});
|
|
}//发送
|
|
private async void Port2_link()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (MachiensPortClient[1].Online)
|
|
{
|
|
try
|
|
{
|
|
if (stringQueueSerial_2.Count > 0) //信息发送队列
|
|
{
|
|
if (AsyncSerialPortClient._responseEvent2.IsSet)
|
|
{
|
|
QueueSerial t = stringQueueSerial_2.Dequeue();
|
|
AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT + "\n");
|
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'"))
|
|
{
|
|
if (MachinesRow["State"].ToString() == "800")
|
|
{
|
|
stringQueueSerial_2.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
});
|
|
}//发送
|
|
private async void Port3_link()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (MachiensPortClient[2].Online)
|
|
{
|
|
try
|
|
{
|
|
if (stringQueueSerial_3.Count > 0) //信息发送队列
|
|
{
|
|
if (AsyncSerialPortClient._responseEvent3.IsSet)
|
|
{
|
|
QueueSerial t = stringQueueSerial_3.Dequeue();
|
|
AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2], t.DAT + "\n");
|
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'"))
|
|
{
|
|
if (MachinesRow["State"].ToString() == "800")
|
|
{
|
|
stringQueueSerial_3.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
});
|
|
}//发送
|
|
private async void Port4_link()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (MachiensPortClient[3].Online)
|
|
{
|
|
try
|
|
{
|
|
if (stringQueueSerial_4.Count > 0) //信息发送队列
|
|
{
|
|
if (AsyncSerialPortClient._responseEvent4.IsSet)
|
|
{
|
|
QueueSerial t = stringQueueSerial_4.Dequeue();
|
|
AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3], t.DAT + "\n");
|
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'"))
|
|
{
|
|
if (MachinesRow["State"].ToString() == "800")
|
|
{
|
|
stringQueueSerial_4.Enqueue(new QueueSerial
|
|
{
|
|
ID = Convert.ToInt16(MachinesRow["ID"]),
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
});
|
|
}//发送
|
|
|
|
public static string SYS_WorkNumder; //工单号
|
|
public static int SYS_AT1; //附缸1-3
|
|
public static int SYS_AT2;
|
|
public static int SYS_AT3;
|
|
|
|
public string sys_Time; //显示系统时间
|
|
public string Sys_Time //通知UI控件参数改变
|
|
{
|
|
get { return sys_Time; }
|
|
set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
|
|
}
|
|
public static string MachineLOG;
|
|
/* public string sys_machine; //显示log
|
|
public string Sys_machine //通知UI控件参数改变
|
|
{
|
|
get { return sys_machine; }
|
|
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
|
|
}*/
|
|
|
|
public static object Selet_Machines(DataTable DB, string name, string key)//查询
|
|
{
|
|
try
|
|
{
|
|
lock (DB)
|
|
{
|
|
DataRow drEmployee = DB.Select(key).First();
|
|
object index = drEmployee.Field<object>(name);
|
|
return index;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
|
return "ERR";
|
|
}
|
|
}
|
|
public static void Updata_Machines(DataTable DB, string name, string key, string Value)//更新数据
|
|
{
|
|
try
|
|
{
|
|
lock (DB)
|
|
{
|
|
DataRow drEmployee = DB.Select(key).First();
|
|
drEmployee.BeginEdit();
|
|
drEmployee[name] = Value;
|
|
drEmployee.EndEdit();
|
|
drEmployee.AcceptChanges();
|
|
// drEmployee.ClearErrors();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogGing.LogGingDATA("SDTD:" + ex.ToString());
|
|
}
|
|
}
|
|
|
|
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_TM = new DataTable();
|
|
public static DataTable dt_TP = new DataTable();
|
|
public static DataTable dt_ParameterSet = new DataTable();
|
|
public static DataTable dt_SysSet = new DataTable();
|
|
public static bool TechnologicalProcess_bool =true;
|
|
// public static bool A_view =true;
|
|
// public static bool D_view =true;
|
|
public static bool IO_view;
|
|
// public static bool ParameterSet_view=true;
|
|
// public static bool SysSet_view=true;
|
|
public static string machine;
|
|
public static string workOrder;
|
|
public static string dyelot;
|
|
public static string machin_LOG;
|
|
|
|
//通讯队列
|
|
public static UInt32 RX=0;
|
|
public static UInt32 TX=0;
|
|
public class QueueSerial
|
|
{
|
|
public int ID { get; set; }
|
|
public string DAT { get; set; }
|
|
}
|
|
public class QueueString
|
|
{
|
|
public int ID { get; set; }
|
|
public string DAT { get; set; }
|
|
}
|
|
// 创建一个字符串类型的队列
|
|
public static Queue<QueueString> stringQueue = new Queue<QueueString>();
|
|
public static Queue<QueueString> stringQueueinf = new Queue<QueueString>();
|
|
public static Queue<QueueSerial> stringQueueSerial_1 = new Queue<QueueSerial>();
|
|
public static Queue<QueueSerial> stringQueueSerial_2 = new Queue<QueueSerial>();
|
|
public static Queue<QueueSerial> stringQueueSerial_3 = new Queue<QueueSerial>();
|
|
public static Queue<QueueSerial> stringQueueSerial_4 = new Queue<QueueSerial>();
|
|
|
|
/// <summary>
|
|
/// 将 DataTable 转换为 Dictionary 类型数据
|
|
/// </summary>
|
|
public Dictionary<string, object> DataTableToDictionary(DataTable dataTable)
|
|
{
|
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
|
if (dataTable != null)
|
|
{
|
|
foreach (DataRow dataRow in dataTable.Rows)
|
|
{
|
|
foreach (DataColumn dataColumn in dataTable.Columns)
|
|
{
|
|
result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString());
|
|
//result = Console.WriteLine(dataRow[dataColumn].ToString());
|
|
//result.Add(dataColumn.ColumnName, dataRow[dataColumn].ToString())(new RepeatDictionaryComparer());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = null;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|