串口通讯队列
This commit is contained in:
commit
157666d836
2 files changed
+277
-132
No files matched your search
@@ -8,11 +8,18 @@ using System.Threading.Tasks;
|
|||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using TouchSocket.SerialPorts;
|
using TouchSocket.SerialPorts;
|
||||||
using TouchSocket.Sockets;
|
using TouchSocket.Sockets;
|
||||||
|
using static SkiaSharp.HarfBuzz.SKShaper;
|
||||||
|
|
||||||
namespace SunlightCentralizedControlManagement_SCCM_.UserClass
|
namespace SunlightCentralizedControlManagement_SCCM_.UserClass
|
||||||
{
|
{
|
||||||
public class AsyncSerialPortClient
|
public class AsyncSerialPortClient
|
||||||
{
|
{
|
||||||
|
public static string PortCOM1 { get; set; }
|
||||||
|
public static string PortCOM2 { get; set; }
|
||||||
|
public static string PortCOM3 { get; set; }
|
||||||
|
public static string PortCOM4 { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public static async Task PortClient(SerialPortClient portclient, string com, int BAUD)
|
public static async Task PortClient(SerialPortClient portclient, string com, int BAUD)
|
||||||
{
|
{
|
||||||
//var client = new SerialPortClient();
|
//var client = new SerialPortClient();
|
||||||
@@ -43,43 +50,145 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
|
|||||||
{
|
{
|
||||||
//a.Add<MyPlugin>();
|
//a.Add<MyPlugin>();
|
||||||
}));
|
}));
|
||||||
|
await portclient.ConnectAsync();
|
||||||
|
}
|
||||||
|
public static async Task PortClient2(SerialPortClient portclient, string com, int BAUD)
|
||||||
|
{
|
||||||
|
//var client = new SerialPortClient();
|
||||||
|
portclient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到端口
|
||||||
|
portclient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
|
||||||
|
portclient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从端口断开连接。此处仅主动断开才有效。
|
||||||
|
portclient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从端口断开连接,当连接不成功时不会触发。
|
||||||
|
portclient.Received = (client, e) =>
|
||||||
|
{
|
||||||
|
_responseEvent2.Set();
|
||||||
|
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8);
|
||||||
|
//string DAT1 = CRCcheck16.ToCRC16(e.ByteBlock.Span.ToString(Encoding.UTF8));
|
||||||
|
|
||||||
|
return EasyTask.CompletedTask; ;
|
||||||
|
};
|
||||||
|
|
||||||
|
await portclient.SetupAsync(new TouchSocketConfig()
|
||||||
|
.SetSerialPortOption(new SerialPortOption()
|
||||||
|
{
|
||||||
|
BaudRate = BAUD,//波特率
|
||||||
|
DataBits = 8,//数据位
|
||||||
|
Parity = System.IO.Ports.Parity.None,//校验位
|
||||||
|
PortName = com,//COM
|
||||||
|
StopBits = System.IO.Ports.StopBits.One,//停止位
|
||||||
|
})
|
||||||
|
.SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(100) })
|
||||||
|
.ConfigurePlugins(a =>
|
||||||
|
{
|
||||||
|
//a.Add<MyPlugin>();
|
||||||
|
}));
|
||||||
|
await portclient.ConnectAsync();
|
||||||
|
}
|
||||||
|
public static async Task PortClient3(SerialPortClient portclient, string com, int BAUD)
|
||||||
|
{
|
||||||
|
//var client = new SerialPortClient();
|
||||||
|
portclient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到端口
|
||||||
|
portclient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
|
||||||
|
portclient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从端口断开连接。此处仅主动断开才有效。
|
||||||
|
portclient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从端口断开连接,当连接不成功时不会触发。
|
||||||
|
portclient.Received = (client, e) =>
|
||||||
|
{
|
||||||
|
_responseEvent3.Set();
|
||||||
|
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8);
|
||||||
|
//string DAT1 = CRCcheck16.ToCRC16(e.ByteBlock.Span.ToString(Encoding.UTF8));
|
||||||
|
|
||||||
|
return EasyTask.CompletedTask; ;
|
||||||
|
};
|
||||||
|
|
||||||
|
await portclient.SetupAsync(new TouchSocketConfig()
|
||||||
|
.SetSerialPortOption(new SerialPortOption()
|
||||||
|
{
|
||||||
|
BaudRate = BAUD,//波特率
|
||||||
|
DataBits = 8,//数据位
|
||||||
|
Parity = System.IO.Ports.Parity.None,//校验位
|
||||||
|
PortName = com,//COM
|
||||||
|
StopBits = System.IO.Ports.StopBits.One,//停止位
|
||||||
|
})
|
||||||
|
.SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(100) })
|
||||||
|
.ConfigurePlugins(a =>
|
||||||
|
{
|
||||||
|
//a.Add<MyPlugin>();
|
||||||
|
}));
|
||||||
|
await portclient.ConnectAsync();
|
||||||
|
}
|
||||||
|
public static async Task PortClient4(SerialPortClient portclient, string com, int BAUD)
|
||||||
|
{
|
||||||
|
//var client = new SerialPortClient();
|
||||||
|
portclient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到端口
|
||||||
|
portclient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
|
||||||
|
portclient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从端口断开连接。此处仅主动断开才有效。
|
||||||
|
portclient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从端口断开连接,当连接不成功时不会触发。
|
||||||
|
portclient.Received = (client, e) =>
|
||||||
|
{
|
||||||
|
_responseEvent4.Set();
|
||||||
|
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8);
|
||||||
|
//string DAT1 = CRCcheck16.ToCRC16(e.ByteBlock.Span.ToString(Encoding.UTF8));
|
||||||
|
|
||||||
|
return EasyTask.CompletedTask; ;
|
||||||
|
};
|
||||||
|
|
||||||
|
await portclient.SetupAsync(new TouchSocketConfig()
|
||||||
|
.SetSerialPortOption(new SerialPortOption()
|
||||||
|
{
|
||||||
|
BaudRate = BAUD,//波特率
|
||||||
|
DataBits = 8,//数据位
|
||||||
|
Parity = System.IO.Ports.Parity.None,//校验位
|
||||||
|
PortName = com,//COM
|
||||||
|
StopBits = System.IO.Ports.StopBits.One,//停止位
|
||||||
|
})
|
||||||
|
.SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(100) })
|
||||||
|
.ConfigurePlugins(a =>
|
||||||
|
{
|
||||||
|
//a.Add<MyPlugin>();
|
||||||
|
}));
|
||||||
await portclient.ConnectAsync();
|
await portclient.ConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static readonly ManualResetEventSlim _responseEvent = new ManualResetEventSlim(false);
|
private static readonly ManualResetEventSlim _responseEvent = new ManualResetEventSlim(false);
|
||||||
private static byte[] _receivedData;
|
private static readonly ManualResetEventSlim _responseEvent2 = new ManualResetEventSlim(false);
|
||||||
private static readonly object _sendLock = new object(); // 确保发送-等待过程原子性
|
private static readonly ManualResetEventSlim _responseEvent3 = new ManualResetEventSlim(false);
|
||||||
|
private static readonly ManualResetEventSlim _responseEvent4 = new ManualResetEventSlim(false);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送指令并等待响应,超时时间为500ms
|
/// 发送指令并等待响应,超时时间为500ms
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">要发送的指令字节数组</param>
|
/// <param name="command">要发送的指令字节数组</param>
|
||||||
/// <returns>从机的响应数据,超时则为null</returns>
|
/// <returns>从机的响应数据,超时则为null</returns>
|
||||||
public static byte[] SendCommandAndWait(SerialPortClient serialPortClients, string command)
|
public static void SendCommandAndWait(SerialPortClient serialPortClients, string command)
|
||||||
{
|
{
|
||||||
// lock (_sendLock) // 防止并发发送
|
_responseEvent.Reset();
|
||||||
{
|
serialPortClients.Send(command); // 发送指令
|
||||||
|
// 等待500毫秒或直到收到响应
|
||||||
_receivedData = null;
|
_responseEvent.Wait(TimeSpan.FromMilliseconds(1000));
|
||||||
_responseEvent.Reset(); // 重置事件状态
|
// 重置事件状态
|
||||||
|
}
|
||||||
serialPortClients.Send(command); // 发送指令
|
public static void SendCommandAndWait2(SerialPortClient serialPortClients, string command)
|
||||||
|
{
|
||||||
// 等待500毫秒或直到收到响应
|
_responseEvent2.Reset();
|
||||||
bool signaled = _responseEvent.Wait(TimeSpan.FromMilliseconds(1000));
|
serialPortClients.Send(command); // 发送指令
|
||||||
|
// 等待500毫秒或直到收到响应
|
||||||
if (signaled)
|
_responseEvent2.Wait(TimeSpan.FromMilliseconds(1000));
|
||||||
{
|
// 重置事件状态
|
||||||
return _receivedData; // 返回收到的数据
|
}
|
||||||
}
|
public static void SendCommandAndWait3(SerialPortClient serialPortClients, string command)
|
||||||
else
|
{
|
||||||
{
|
_responseEvent3.Reset();
|
||||||
// 超时处理,记录日志或抛出异常
|
serialPortClients.Send(command); // 发送指令
|
||||||
//Console.WriteLine("警告: 等待从机响应超时 (500ms)。");
|
// 等待500毫秒或直到收到响应
|
||||||
return null; // 或者可以抛出 TimeoutException
|
_responseEvent3.Wait(TimeSpan.FromMilliseconds(1000));
|
||||||
}
|
// 重置事件状态
|
||||||
}
|
}
|
||||||
|
public static void SendCommandAndWait4(SerialPortClient serialPortClients, string command)
|
||||||
|
{
|
||||||
|
_responseEvent4.Reset();
|
||||||
|
serialPortClients.Send(command); // 发送指令
|
||||||
|
// 等待500毫秒或直到收到响应
|
||||||
|
_responseEvent4.Wait(TimeSpan.FromMilliseconds(1000));
|
||||||
|
// 重置事件状态
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+142
-106
@@ -643,6 +643,46 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
|||||||
}
|
}
|
||||||
async void Tick_Event_5S()//Tick_Event周期执行事件5S
|
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)
|
foreach (DataRow MachinesRow in Machines.Rows)
|
||||||
{
|
{
|
||||||
/**发送800指令**/
|
/**发送800指令**/
|
||||||
@@ -984,7 +1024,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
|||||||
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
|
Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"),
|
||||||
Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")});
|
Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")});
|
||||||
}
|
}
|
||||||
|
|
||||||
Dyelot_CALL.Rows.Remove(row);
|
Dyelot_CALL.Rows.Remove(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1044,170 +1083,167 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
|
|||||||
{
|
{
|
||||||
if (Machines.Select("Type='false' AND Serial='PORT1'").Length > 0)
|
if (Machines.Select("Type='false' AND Serial='PORT1'").Length > 0)
|
||||||
{
|
{
|
||||||
|
AsyncSerialPortClient.PortCOM1 = Configini.IniReadvalue("SYS", "COMP1");
|
||||||
MachiensPortClient[0] = new SerialPortClient();
|
MachiensPortClient[0] = new SerialPortClient();
|
||||||
|
|
||||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[0] //建立连接
|
await AsyncSerialPortClient.PortClient(MachiensPortClient[0] //建立连接
|
||||||
, Configini.IniReadvalue("SYS", "COMP1")
|
, Configini.IniReadvalue("SYS", "COMP1")
|
||||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1")));
|
, 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)
|
if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0)
|
||||||
{
|
{
|
||||||
|
AsyncSerialPortClient.PortCOM2 = Configini.IniReadvalue("SYS", "COMP2");
|
||||||
MachiensPortClient[1] = new SerialPortClient();
|
MachiensPortClient[1] = new SerialPortClient();
|
||||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[1] //建立连接
|
|
||||||
|
await AsyncSerialPortClient.PortClient2(MachiensPortClient[1] //建立连接
|
||||||
, Configini.IniReadvalue("SYS", "COMP2")
|
, Configini.IniReadvalue("SYS", "COMP2")
|
||||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2")));
|
, 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)
|
if (Machines.Select("Type='false' AND Serial='PORT3'").Length > 0)
|
||||||
{
|
{
|
||||||
|
AsyncSerialPortClient.PortCOM3 = Configini.IniReadvalue("SYS", "COMP3");
|
||||||
MachiensPortClient[2] = new SerialPortClient();
|
MachiensPortClient[2] = new SerialPortClient();
|
||||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[2] //建立连接
|
|
||||||
|
await AsyncSerialPortClient.PortClient3(MachiensPortClient[2] //建立连接
|
||||||
, Configini.IniReadvalue("SYS", "COMP3")
|
, Configini.IniReadvalue("SYS", "COMP3")
|
||||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3")));
|
, 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)
|
if (Machines.Select("Type='false' AND Serial='PORT4'").Length > 0)
|
||||||
{
|
{
|
||||||
|
AsyncSerialPortClient.PortCOM4 = Configini.IniReadvalue("SYS", "COMP4");
|
||||||
MachiensPortClient[3] = new SerialPortClient();
|
MachiensPortClient[3] = new SerialPortClient();
|
||||||
await AsyncSerialPortClient.PortClient(MachiensPortClient[3] //建立连接
|
|
||||||
|
await AsyncSerialPortClient.PortClient4(MachiensPortClient[3] //建立连接
|
||||||
, Configini.IniReadvalue("SYS", "COMP4")
|
, Configini.IniReadvalue("SYS", "COMP4")
|
||||||
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4")));
|
, Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4")));
|
||||||
Port4_link();
|
|
||||||
|
Thread myThread4 = new Thread(Port4_link);
|
||||||
|
myThread4.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void Port1_link()
|
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);
|
AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT+"\n");
|
||||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||||
}
|
}
|
||||||
if (MachinesRow["State"].ToString() == "800")
|
if (MachinesRow["State"].ToString() == "800")
|
||||||
{
|
{
|
||||||
AsyncSerialPortClient.SendCommandAndWait(
|
AsyncSerialPortClient.SendCommandAndWait(
|
||||||
MachiensPortClient[0],
|
MachiensPortClient[0],
|
||||||
"SC800[" + MachinesRow["Station"] + "]");
|
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
{
|
catch (Exception)
|
||||||
}
|
{
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
// if (stringQueueSerial.Count == 0) return;
|
{
|
||||||
Port1_link();//回调
|
Port1_link();//回调
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}//发送
|
}//发送
|
||||||
private void Port2_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);
|
AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT+ "\n");
|
||||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||||
}
|
}
|
||||||
if (MachinesRow["State"].ToString() == "800")
|
if (MachinesRow["State"].ToString() == "800")
|
||||||
{
|
{
|
||||||
AsyncSerialPortClient.SendCommandAndWait(
|
AsyncSerialPortClient.SendCommandAndWait2(
|
||||||
MachiensPortClient[1],
|
MachiensPortClient[1],
|
||||||
"SC800[" + MachinesRow["Station"] + "]");
|
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
{
|
catch (Exception)
|
||||||
}
|
{
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
// if (stringQueueSerial.Count == 0) return;
|
{
|
||||||
Port2_link();//回调
|
Port2_link();//回调
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}//发送
|
}//发送
|
||||||
private void Port3_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);
|
AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2],t.DAT+ "\n");
|
||||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||||
}
|
}
|
||||||
if (MachinesRow["State"].ToString() == "800")
|
else if (MachinesRow["State"].ToString() == "800")
|
||||||
{
|
{
|
||||||
DataTable Workorddr = SQLiteHelpers.ExecuteDataSet("select * from Dyelot ", null).Tables[0]; //读取表写入缓存
|
AsyncSerialPortClient.SendCommandAndWait3(
|
||||||
|
MachiensPortClient[2],
|
||||||
AsyncSerialPortClient.SendCommandAndWait(
|
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||||
MachiensPortClient[2],
|
|
||||||
"SC800[" + MachinesRow["Station"] + "]"+Workorddr.ToJsonString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
{
|
catch (Exception)
|
||||||
}
|
{
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
// if (stringQueueSerial.Count == 0) return;
|
{
|
||||||
Port3_link();//回调
|
Port3_link();//回调
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}//发送
|
}//发送
|
||||||
private void Port4_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);
|
AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3],t.DAT+ "\n");
|
||||||
//MachiensPortClient[t.ID].Send(t.DAT);
|
//MachiensPortClient[t.ID].Send(t.DAT);
|
||||||
}
|
}
|
||||||
if (MachinesRow["State"].ToString() == "800")
|
if (MachinesRow["State"].ToString() == "800")
|
||||||
{
|
{
|
||||||
AsyncSerialPortClient.SendCommandAndWait(
|
AsyncSerialPortClient.SendCommandAndWait4(
|
||||||
MachiensPortClient[3],
|
MachiensPortClient[3],
|
||||||
"SC800[" + MachinesRow["Station"] + "]");
|
"SC800[" + MachinesRow["Station"] + "]\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
{
|
catch (Exception)
|
||||||
}
|
{
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
// if (stringQueueSerial.Count == 0) return;
|
{
|
||||||
Port4_link();//回调
|
Port4_link();//回调
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}//发送
|
}//发送
|
||||||
|
|
||||||
public static string SYS_WorkNumder; //工单号
|
public static string SYS_WorkNumder; //工单号
|
||||||
|
|||||||
Reference in new issue
Block a user