Browse Source

串口通讯部分修改

master
sc 2 weeks ago
parent
commit
ebcd5b7182
  1. 32
      UserClass/AsyncSerialPortClient.cs
  2. 2
      ViewModel/MainWindowViewModel.cs

32
UserClass/AsyncSerialPortClient.cs

@ -47,7 +47,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
int contentLength = endIndex - startIndex - 1; int contentLength = endIndex - startIndex - 1;
return contentLength > 0 ? source.Substring(contentStart, contentLength) : string.Empty; return contentLength > 0 ? source.Substring(contentStart, contentLength) : string.Empty;
} }
} }//获取字符串指定字符的范围的值
public static string PortCOM1 { get; set; } public static string PortCOM1 { get; set; }
public static string PortCOM2 { get; set; } public static string PortCOM2 { get; set; }
@ -231,17 +231,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee["ERR"] = _new.GetValue("ERR"); drEmployee["ERR"] = _new.GetValue("ERR");
drEmployee["LOCK"] = _new.GetValue("LOCK"); drEmployee["LOCK"] = _new.GetValue("LOCK");
drEmployee["Message"] = _new.GetValue("Status"); drEmployee["Message"] = _new.GetValue("Status");
drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); drEmployee["WorkOrder"] = _new.GetValue("Work");
drEmployee["Temperature"] = _new.GetValue("MTT"); drEmployee["Temperature"] = _new.GetValue("MTT");
drEmployee["WaterLevel"] = _new.GetValue("MTL"); drEmployee["WaterLevel"] = _new.GetValue("MTL");
drEmployee["Process"] = _new.GetValue("Process"); drEmployee["Process"] = _new.GetValue("Process");
drEmployee["Step"] = _new.GetValue("Step"); drEmployee["Step"] = _new.GetValue("Step");
drEmployee["UserButton"] = _new.GetValue("UserButton"); drEmployee["UserButton"] = _new.GetValue("User");
if (_new.GetValue("UserInfoStart").ToString() != "900") if (_new.GetValue("InfoS").ToString() != "900")
{ drEmployee["UserInfoStart"] = _new.GetValue("UserInfoStart"); } { drEmployee["UserInfoStart"] = _new.GetValue("InfoS"); }
drEmployee["UserInfo"] = _new.GetValue("UserInfo"); drEmployee["UserInfo"] = _new.GetValue("Info");
drEmployee["WORK_RUN"] = _new.GetValue("WORK_RUN"); drEmployee["WORK_RUN"] = _new.GetValue("RUN");
drEmployee["RUN_STEPID"] = _new.GetValue("RUN_STEPID"); drEmployee["RUN_STEPID"] = _new.GetValue("STEPID");
drEmployee["CALL"] = _new.GetValue("CALL"); drEmployee["CALL"] = _new.GetValue("CALL");
drEmployee.EndEdit(); drEmployee.EndEdit();
drEmployee.AcceptChanges(); drEmployee.AcceptChanges();
@ -250,9 +250,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
if (_new.GetValue("Status").ToString() != "----------") if (_new.GetValue("Status").ToString() != "----------")
{ {
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数 Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
Chart_new.Add("WorkOrder", _new.GetValue("WorkNumder")); Chart_new.Add("WorkOrder", _new.GetValue("Work"));
Chart_new.Add("Machine", mac); Chart_new.Add("Machine", mac);
Chart_new.Add("Time", _new.GetValue("Time")); Chart_new.Add("Time", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
Chart_new.Add("MST", _new.GetValue("MST")); Chart_new.Add("MST", _new.GetValue("MST"));
Chart_new.Add("MTT", _new.GetValue("MTT")); Chart_new.Add("MTT", _new.GetValue("MTT"));
Chart_new.Add("MTL", _new.GetValue("MTL")); Chart_new.Add("MTL", _new.GetValue("MTL"));
@ -602,14 +602,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{ {
try try
{ {
var t = CRCcheck16.ToCRC16(command); // var t = CRCcheck16.ToCRC16(command);
_responseEvent.Reset(); _responseEvent.Reset();
serialPortClients.Send(command); // 发送指令 serialPortClients.Send(command); // 发送指令
// 等待500毫秒或直到收到响应 // 等待500毫秒或直到收到响应
_responseEvent.Wait(TimeSpan.FromMilliseconds(1000)); _responseEvent.Wait(TimeSpan.FromMilliseconds(1000));
// 重置事件状态 if (!_responseEvent.IsSet)
_responseEvent.Set(); {
//清楚了解状态 //清机台状态
string Station = ClipBetween(command, '[', ']'); string Station = ClipBetween(command, '[', ']');
lock (MainWindowViewModel.Machines.Rows.SyncRoot) lock (MainWindowViewModel.Machines.Rows.SyncRoot)
{ {
@ -633,7 +633,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee.AcceptChanges(); drEmployee.AcceptChanges();
} }
} }
}
// 重置事件状态
_responseEvent.Set();
} }
catch (Exception) { } catch (Exception) { }
} }

2
ViewModel/MainWindowViewModel.cs

@ -771,7 +771,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
} }
} }
} }
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息 if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309")|| (mac_s == "802"))//获取信息
{ {
if (MachinesRow["Serial"].ToString() == "PORT1") if (MachinesRow["Serial"].ToString() == "PORT1")
{ {

Loading…
Cancel
Save