串口读取数据修改

apiclient现场测试
This commit is contained in:
zhougf committed 2025-03-07 22:07:51 +08:00
1 parent 6c7278ed45
commit 2bd24f5316
3 files changed
+176 -107

No files matched your search

+42 -28
View File
@@ -121,37 +121,40 @@ namespace WindowsFormsApp1
//机台状态
机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
int oldstatus = Init.Plcstatus;
DateTime oldPlcstatus_LastTime = Init.Plcstatus_LastTime;
//状态+报警
if (oldstatus != PlcData.Read_Status || (Plc_Time - oldPlcstatus_LastTime).TotalSeconds > 5)
if (PlcData.Read_Status != 0)
{
//反馈状态
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
otherdata.Plc_Status = PlcData.Read_Status;
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
DateTime oldPlcstatus_LastTime = Init.Plcstatus_LastTime;
//状态+报警
if (oldstatus != PlcData.Read_Status || (Plc_Time - oldPlcstatus_LastTime).TotalSeconds > 5)
{
MES链接状态.Text = "MES链接状态:OK";
MES链接状态.BackColor = SystemColors.Control;
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
MES_MsgfORM("Status", statusresult.Mesresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
//反馈状态
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
otherdata.Plc_Status = PlcData.Read_Status;
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
MES链接状态.Text = "MES链接状态:OK";
MES链接状态.BackColor = SystemColors.Control;
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
MES_MsgfORM("Status", statusresult.Mesresult, statusresult.Requesttime);
if (statusresult.Mesresult != mesresult.PASS)
{
PlcData.Write_Status = 1001;
siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
MES链接状态.Text = "MES链接状态:NG";
MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
var errresult = siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
else
{
MES链接状态.Text = "MES链接状态:NG";
MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
PlcData.Write_Status = 1002;
var errresult = siemensHelp.WriteAddress(plcaddress, PlcData);
continue;
}
}
//机台报警
if (PlcData.Read_Status == (short)plcstatus.停机)
@@ -201,7 +204,7 @@ namespace WindowsFormsApp1
{
continue;
}
else if (PlcData.Read_Trigger != 0 && PlcData.Write_Status != 0)
else if (PlcData.Read_Trigger == PlcData.Write_Status)
{
continue;
}
@@ -217,6 +220,8 @@ namespace WindowsFormsApp1
}
continue;
}
LogExecute.logNet.WriteDebug($"读取状态字{PlcData.Read_Trigger}");
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
if (nowflow == null)
{
@@ -229,6 +234,7 @@ namespace WindowsFormsApp1
LogExecute.logNet.WriteError($"未找到当前期望接口ID {nowflow.hopeinterfaceid},对应的接口!");
continue;
}
#endregion
#region 根据流程,判断是否需要扫码、气密、扭力等
if (nowflow.scan)
@@ -602,7 +608,7 @@ namespace WindowsFormsApp1
int textLength = richTextBox1.TextLength;
int lineCount = richTextBox1.GetLineFromCharIndex(textLength);
if (lineCount >= 20)
if (lineCount >= 200)
{
richTextBox1.Clear();
}
@@ -820,7 +826,15 @@ namespace WindowsFormsApp1
Init.AirtightPort?.Open();
}
// 读取串口接收到的数据
string ReturnValue = Init.AirtightPort.ReadExisting();
// 读取串口接收到的数据
var dataBuilder = new StringBuilder();
while (Init.AirtightPort.BytesToRead > 0)
{
System.Threading.Thread.Sleep(100);
dataBuilder.Append(Init.AirtightPort.ReadExisting());
}
var ReturnValue = dataBuilder.ToString();
LogExecute.logNet.WriteDebug($"通过气密仪获取到 {ReturnValue}");
int index1 = 1;
int index2 = 1;