部分数据库及串口逻辑修改
This commit is contained in:
commit
48eb8a0ad1
4 files changed
+451
-174
No files matched your search
+158
-118
@@ -2,6 +2,7 @@
|
||||
using LiveChartsCore.Geo;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NModbus;
|
||||
using OpenTK.Graphics.ES11;
|
||||
using ScottPlot.Palettes;
|
||||
using ScottPlot.TickGenerators.TimeUnits;
|
||||
@@ -40,6 +41,7 @@ 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
|
||||
{
|
||||
@@ -81,6 +83,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
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();
|
||||
@@ -106,6 +110,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
}
|
||||
catch (Exception ex) { LogGing.ERRDATA(ex); }
|
||||
|
||||
SQLiteChartAdress = new SQLiteHelper(ChartAdress); //数据库连接路径
|
||||
SQLiteChartAdress.Open(); //打开数据库
|
||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
|
||||
@@ -642,47 +648,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
else { Time30++; }
|
||||
}
|
||||
async void Tick_Event_5S()//Tick_Event周期执行事件5S
|
||||
{
|
||||
DataTable Workorddr = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps ", null).Tables[0]; //读取表写入缓存
|
||||
int y = Workorddr.Rows.Count;
|
||||
object[] datal = new object[19];
|
||||
for (int i = 0; i < Workorddr.Rows.Count; i++)
|
||||
{
|
||||
|
||||
/*AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[2],
|
||||
"SC800[" + MachinesRow["Station"] + "]" + f);*/
|
||||
if (i >= 20) break;
|
||||
|
||||
datal[0] = Workorddr.Rows[i]["Step"];
|
||||
datal[1] = Workorddr.Rows[i]["StepID"];
|
||||
datal[2] = Workorddr.Rows[i]["Parameter1"] ?? 0;
|
||||
datal[3] = Workorddr.Rows[i]["Parameter2"] ?? 0;
|
||||
datal[4] = Workorddr.Rows[i]["Parameter3"] ?? 0;
|
||||
datal[5] = Workorddr.Rows[i]["Parameter4"] ?? 0;
|
||||
datal[6] = Workorddr.Rows[i]["Parameter5"] ?? 0;
|
||||
datal[7] = Workorddr.Rows[i]["StepID_S1"];
|
||||
datal[8] = Workorddr.Rows[i]["StepID_S2"];
|
||||
datal[9] = Workorddr.Rows[i].Field<double?>("Parameter1_S1") ?? 0;
|
||||
datal[10] = Workorddr.Rows[i].Field<double?>("Parameter1_S2") ?? 0;
|
||||
datal[11] = Workorddr.Rows[i].Field<double?>("Parameter2_S1") ?? 0;
|
||||
datal[12] = Workorddr.Rows[i].Field<double?>("Parameter2_S2") ?? 0;
|
||||
datal[13] = Workorddr.Rows[i].Field<double?>("Parameter3_S1") ?? 0;
|
||||
datal[14] = Workorddr.Rows[i].Field<double?>("Parameter3_S2") ?? 0;
|
||||
datal[15] = Workorddr.Rows[i].Field<double?>("Parameter4_S1") ?? 0;
|
||||
datal[16] = Workorddr.Rows[i].Field<double?>("Parameter4_S2") ?? 0;
|
||||
datal[17] = Workorddr.Rows[i].Field<double?>("Parameter5_S1") ?? 0;
|
||||
datal[18] = Workorddr.Rows[i].Field<double?>("Parameter5_S2") ?? 0;
|
||||
|
||||
stringQueueSerial_3.Enqueue(new QueueSerial
|
||||
{
|
||||
ID = 45,
|
||||
DAT = "SC810[" + 1 + "]" + datal.ToJsonString()
|
||||
});//信息插入队列
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Rows)
|
||||
{
|
||||
/**发送800指令**/
|
||||
@@ -1035,7 +1001,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
/*曲线图*/
|
||||
for (int i = 0; i < Machines.Rows.Count; i++)//曲线图
|
||||
{
|
||||
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() !="800")
|
||||
string st = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString();
|
||||
if (st != "800" && st != "801" && st != "802")
|
||||
{
|
||||
DataRow whole_Dat = Whole_dat.NewRow();
|
||||
whole_Dat["Machine"] = Selet_Machines(Machines, "NAME", "ID='" + i + "'").ToString();
|
||||
@@ -1089,7 +1056,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[0] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP1")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1")));
|
||||
Thread myThread1 = new Thread(Port1_link);
|
||||
AsyncSerialPortClient._responseEvent.Set();
|
||||
|
||||
Thread myThread1 = new Thread(Port1_link);
|
||||
myThread1.Start();
|
||||
}
|
||||
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
|
||||
@@ -1100,7 +1069,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
await AsyncSerialPortClient.PortClient2(MachiensPortClient[1] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP2")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2")));
|
||||
|
||||
AsyncSerialPortClient._responseEvent2.Set();
|
||||
|
||||
Thread myThread2 = new Thread(Port2_link);
|
||||
myThread2.Start();
|
||||
}
|
||||
@@ -1112,7 +1082,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
await AsyncSerialPortClient.PortClient3(MachiensPortClient[2] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP3")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3")));
|
||||
|
||||
AsyncSerialPortClient._responseEvent3.Set();
|
||||
|
||||
Thread myThread3 = new Thread(Port3_link);
|
||||
myThread3.Start();
|
||||
}
|
||||
@@ -1124,126 +1095,195 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
await AsyncSerialPortClient.PortClient4(MachiensPortClient[3] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP4")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4")));
|
||||
|
||||
AsyncSerialPortClient._responseEvent4.Set();
|
||||
|
||||
Thread myThread4 = new Thread(Port4_link);
|
||||
myThread4.Start();
|
||||
}
|
||||
}
|
||||
private void Port1_link()
|
||||
{
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'"))
|
||||
try
|
||||
{
|
||||
if (stringQueueSerial_1.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_1.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT+"\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
else
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[0],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
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
|
||||
{
|
||||
Port1_link();//回调
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
}//发送
|
||||
private void Port2_link()
|
||||
{
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'"))
|
||||
try
|
||||
{
|
||||
if (stringQueueSerial_2.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_2.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
else
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait2(
|
||||
MachiensPortClient[1],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
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
|
||||
{
|
||||
Port2_link();//回调
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
}//发送
|
||||
private void Port3_link()
|
||||
{
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'"))
|
||||
try
|
||||
{
|
||||
if (stringQueueSerial_3.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_3.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2],t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
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 if (MachinesRow["State"].ToString() == "800")
|
||||
else
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait3(
|
||||
MachiensPortClient[2],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
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
|
||||
{
|
||||
Port3_link();//回调
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
}//发送
|
||||
private void Port4_link()
|
||||
{
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'"))
|
||||
try
|
||||
{
|
||||
if (stringQueueSerial_4.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_4.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3],t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
else
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait4(
|
||||
MachiensPortClient[3],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
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
|
||||
{
|
||||
Port4_link();//回调
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
}//发送
|
||||
|
||||
public static string SYS_WorkNumder; //工单号
|
||||
|
||||
Reference in new issue
Block a user