|
|
@ -1062,8 +1062,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1"))); |
|
|
|
AsyncSerialPortClient._responseEvent.Set(); |
|
|
|
|
|
|
|
Thread myThread1 = new Thread(Port1_link); |
|
|
|
myThread1.Start(); |
|
|
|
Port1_link(); |
|
|
|
} |
|
|
|
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0) |
|
|
|
{ |
|
|
@ -1075,8 +1074,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2"))); |
|
|
|
AsyncSerialPortClient._responseEvent2.Set(); |
|
|
|
|
|
|
|
Thread myThread2 = new Thread(Port2_link); |
|
|
|
myThread2.Start(); |
|
|
|
Port2_link(); |
|
|
|
} |
|
|
|
if (Machines.Select("Type='false' AND Serial='PORT3'").Length > 0) |
|
|
|
{ |
|
|
@ -1087,9 +1085,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
|
, Configini.IniReadvalue("SYS", "COMP3") |
|
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3"))); |
|
|
|
AsyncSerialPortClient._responseEvent3.Set(); |
|
|
|
|
|
|
|
Thread myThread3 = new Thread(Port3_link); |
|
|
|
myThread3.Start(); |
|
|
|
|
|
|
|
Port3_link(); |
|
|
|
} |
|
|
|
if (Machines.Select("Type='false' AND Serial='PORT4'").Length > 0) |
|
|
|
{ |
|
|
@ -1100,194 +1097,205 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel |
|
|
|
, Configini.IniReadvalue("SYS", "COMP4") |
|
|
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4"))); |
|
|
|
AsyncSerialPortClient._responseEvent4.Set(); |
|
|
|
|
|
|
|
Thread myThread4 = new Thread(Port4_link); |
|
|
|
myThread4.Start(); |
|
|
|
|
|
|
|
Port4_link(); |
|
|
|
} |
|
|
|
} |
|
|
|
private void Port1_link() |
|
|
|
private async void Port1_link() |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
await Task.Run(() => |
|
|
|
{ |
|
|
|
try |
|
|
|
while (MachiensPortClient[0].Online ) |
|
|
|
{ |
|
|
|
if (stringQueueSerial_1.Count > 0) //信息发送队列
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (AsyncSerialPortClient._responseEvent.IsSet) |
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) |
|
|
|
{ |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) |
|
|
|
{ |
|
|
|
stringQueueSerial_1.Enqueue(new QueueSerial |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5)); |
|
|
|
stringQueueSerial_1.Enqueue(new QueueSerial |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}//发送
|
|
|
|
private void Port2_link() |
|
|
|
private async void Port2_link() |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
await Task.Run(() => |
|
|
|
{ |
|
|
|
try |
|
|
|
while (MachiensPortClient[1].Online) |
|
|
|
{ |
|
|
|
if (stringQueueSerial_2.Count > 0) //信息发送队列
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (AsyncSerialPortClient._responseEvent2.IsSet) |
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(50)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) |
|
|
|
{ |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) |
|
|
|
{ |
|
|
|
stringQueueSerial_2.Enqueue(new QueueSerial |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5)); |
|
|
|
stringQueueSerial_2.Enqueue(new QueueSerial |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(TimeSpan.FromMilliseconds(5)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}//发送
|
|
|
|
private void Port3_link() |
|
|
|
private async void Port3_link() |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
await Task.Run(() => |
|
|
|
{ |
|
|
|
try |
|
|
|
while (MachiensPortClient[2].Online) |
|
|
|
{ |
|
|
|
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 |
|
|
|
try |
|
|
|
{ |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'")) |
|
|
|
if (stringQueueSerial_3.Count > 0) //信息发送队列
|
|
|
|
{ |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
if (AsyncSerialPortClient._responseEvent3.IsSet) |
|
|
|
{ |
|
|
|
stringQueueSerial_3.Enqueue(new QueueSerial |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
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 |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}//发送
|
|
|
|
private void Port4_link() |
|
|
|
private async void Port4_link() |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
await Task.Run(() => |
|
|
|
{ |
|
|
|
try |
|
|
|
while (MachiensPortClient[3].Online) |
|
|
|
{ |
|
|
|
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 |
|
|
|
try |
|
|
|
{ |
|
|
|
foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'")) |
|
|
|
if (stringQueueSerial_4.Count > 0) //信息发送队列
|
|
|
|
{ |
|
|
|
if (MachinesRow["State"].ToString() == "800") |
|
|
|
if (AsyncSerialPortClient._responseEvent4.IsSet) |
|
|
|
{ |
|
|
|
stringQueueSerial_4.Enqueue(new QueueSerial |
|
|
|
{ |
|
|
|
ID = Convert.ToInt16(MachinesRow["ID"]), |
|
|
|
DAT = "SC800[" + MachinesRow["Station"] + "]" |
|
|
|
}); |
|
|
|
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 |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}//发送
|
|
|
|
|
|
|
|
public static string SYS_WorkNumder; //工单号
|
|
|
|