串口通讯队列
This commit is contained in:
commit
157666d836
2 files changed
+279
-134
No files matched your search
+142
-106
@@ -643,6 +643,46 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
}
|
||||
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指令**/
|
||||
@@ -984,7 +1024,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
|
||||
Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")});
|
||||
}
|
||||
|
||||
Dyelot_CALL.Rows.Remove(row);
|
||||
}
|
||||
}
|
||||
@@ -1044,170 +1083,167 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
||||
{
|
||||
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")));
|
||||
Port1_link();
|
||||
Thread myThread1 = new Thread(Port1_link);
|
||||
myThread1.Start();
|
||||
}
|
||||
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
|
||||
{
|
||||
AsyncSerialPortClient.PortCOM2 = Configini.IniReadvalue("SYS", "COMP2");
|
||||
MachiensPortClient[1] = new SerialPortClient();
|
||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[1] //建立连接
|
||||
|
||||
await AsyncSerialPortClient.PortClient2(MachiensPortClient[1] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP2")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2")));
|
||||
Port2_link();
|
||||
|
||||
Thread myThread2 = new Thread(Port2_link);
|
||||
myThread2.Start();
|
||||
}
|
||||
if (Machines.Select("Type='false' AND Serial='PORT3'").Length > 0)
|
||||
{
|
||||
AsyncSerialPortClient.PortCOM3 = Configini.IniReadvalue("SYS", "COMP3");
|
||||
MachiensPortClient[2] = new SerialPortClient();
|
||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[2] //建立连接
|
||||
|
||||
await AsyncSerialPortClient.PortClient3(MachiensPortClient[2] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP3")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3")));
|
||||
Port3_link();
|
||||
|
||||
Thread myThread3 = new Thread(Port3_link);
|
||||
myThread3.Start();
|
||||
}
|
||||
if (Machines.Select("Type='false' AND Serial='PORT4'").Length > 0)
|
||||
{
|
||||
AsyncSerialPortClient.PortCOM4 = Configini.IniReadvalue("SYS", "COMP4");
|
||||
MachiensPortClient[3] = new SerialPortClient();
|
||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[3] //建立连接
|
||||
|
||||
await AsyncSerialPortClient.PortClient4(MachiensPortClient[3] //建立连接
|
||||
, Configini.IniReadvalue("SYS", "COMP4")
|
||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4")));
|
||||
Port4_link();
|
||||
|
||||
Thread myThread4 = new Thread(Port4_link);
|
||||
myThread4.Start();
|
||||
}
|
||||
}
|
||||
private void Port1_link()
|
||||
{
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'"))
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'"))
|
||||
if (stringQueueSerial_1.Count > 0) //信息发送队列
|
||||
{
|
||||
if (stringQueueSerial_1.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_1.Dequeue();
|
||||
QueueSerial t = stringQueueSerial_1.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT);
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[0],
|
||||
"SC800[" + MachinesRow["Station"] + "]");
|
||||
}
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT+"\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[0],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if (stringQueueSerial.Count == 0) return;
|
||||
Port1_link();//回调
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
Port1_link();//回调
|
||||
}
|
||||
}//发送
|
||||
private void Port2_link()
|
||||
{
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'"))
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'"))
|
||||
if (stringQueueSerial_2.Count > 0) //信息发送队列
|
||||
{
|
||||
if (stringQueueSerial_2.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_2.Dequeue();
|
||||
QueueSerial t = stringQueueSerial_2.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[1], t.DAT);
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[1],
|
||||
"SC800[" + MachinesRow["Station"] + "]");
|
||||
}
|
||||
AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait2(
|
||||
MachiensPortClient[1],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if (stringQueueSerial.Count == 0) return;
|
||||
Port2_link();//回调
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
Port2_link();//回调
|
||||
}
|
||||
}//发送
|
||||
private void Port3_link()
|
||||
{
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'"))
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'"))
|
||||
if (stringQueueSerial_3.Count > 0) //信息发送队列
|
||||
{
|
||||
if (stringQueueSerial_3.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_3.Dequeue();
|
||||
QueueSerial t = stringQueueSerial_3.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[2], t.DAT);
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
DataTable Workorddr = SQLiteHelpers.ExecuteDataSet("select * from Dyelot ", null).Tables[0]; //读取表写入缓存
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[2],
|
||||
"SC800[" + MachinesRow["Station"] + "]"+Workorddr.ToJsonString());
|
||||
}
|
||||
AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2],t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
else if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait3(
|
||||
MachiensPortClient[2],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if (stringQueueSerial.Count == 0) return;
|
||||
Port3_link();//回调
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
Port3_link();//回调
|
||||
}
|
||||
}//发送
|
||||
private void Port4_link()
|
||||
{
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'"))
|
||||
{
|
||||
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'"))
|
||||
if (stringQueueSerial_4.Count > 0) //信息发送队列
|
||||
{
|
||||
if (stringQueueSerial_4.Count > 0) //信息发送队列
|
||||
{
|
||||
QueueSerial t = stringQueueSerial_4.Dequeue();
|
||||
QueueSerial t = stringQueueSerial_4.Dequeue();
|
||||
|
||||
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[3], t.DAT);
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait(
|
||||
MachiensPortClient[3],
|
||||
"SC800[" + MachinesRow["Station"] + "]");
|
||||
}
|
||||
AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3],t.DAT+ "\n");
|
||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||
}
|
||||
if (MachinesRow["State"].ToString() == "800")
|
||||
{
|
||||
AsyncSerialPortClient.SendCommandAndWait4(
|
||||
MachiensPortClient[3],
|
||||
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if (stringQueueSerial.Count == 0) return;
|
||||
Port4_link();//回调
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
Port4_link();//回调
|
||||
}
|
||||
}//发送
|
||||
|
||||
public static string SYS_WorkNumder; //工单号
|
||||
|
||||
Reference in new issue
Block a user