更改部分界面,更新ApiFormResult部分字段

This commit is contained in:
bnala 2025-02-19 13:39:14 +08:00
parent c322de2dd7
commit 16586d67aa
12 changed files with 936 additions and 263 deletions

View File

@ -38,8 +38,8 @@
<Reference Include="HslCommunication, Version=7.0.1.0, Culture=neutral, PublicKeyToken=cdb2261fa039ed67, processorArchitecture=MSIL">
<HintPath>..\packages\HslCommunication.7.0.1\lib\net451\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />

File diff suppressed because it is too large Load Diff

View File

@ -35,19 +35,16 @@ namespace WindowsFormsApp1
private void Form1_Load(object sender, EventArgs e)
{
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
label8.Visible = false;
LogExecute.logNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
LogExecute.PlclogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
LogExecute.ApilogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
Formrecover();
线别.Text = "线别:" + Init.t_Line.linename;
段别.Text = "段别:" + Init.t_Line.linemode;
机台编号.Text = "机台编号:" + Init.t_Line.linecode;
操作人员ID.Text = "操作人员ID:" + Init.t_User.username;
}
public void build(t_plc Plc, CancellationToken token)
{
@ -71,8 +68,9 @@ namespace WindowsFormsApp1
var openresult = siemensHelp.OpenConn();
if (!openresult.Success)
{
label8.Text = $"PLC:{Plc.id}:{Plc.plcip}建立S7连接失败";
//LogExecute.logNet.WriteError($"{Plc.plcip}建立S7连接失败");
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}建立S7连接失败");
continue;
}
@ -82,7 +80,8 @@ namespace WindowsFormsApp1
var resdresult = siemensHelp.ReadAddress(plcaddress, PlcData);
if (!resdresult.Success)
{
label8.Text = $"PLC:{Plc.id}:{Plc.plcip}读取全部地址处理错误";
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}读取全部地址处理错误:处理停止");
continue;
}
@ -92,16 +91,18 @@ namespace WindowsFormsApp1
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
label8.Text = $"PLC:{Plc.id}:{Plc.plcip}写入心跳错误";
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入心跳错误:处理停止");
continue;
}
Plc.dateTime = DateTime.Now;
DateTime Plc_Time = DateTime.Now;
PLC链接状态.Text = "PLC链接状态:OK";
PLC链接状态.BackColor = SystemColors.Control;
PLC通讯时间.Text = "PLC通讯时间:" + Plc_Time.ToString("MM-dd HH:mm:ss");
label8.Text = Plc.dateTime.ToString();
if (PlcData.Read_Trigger == 0 && PlcData.Write_Status == 0)
{
continue;
@ -116,49 +117,110 @@ namespace WindowsFormsApp1
var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!writeresult.Success)
{
label8.Text = $"PLC:{Plc.id}:{Plc.plcip}写入地址处理错误";
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
}
continue;
}
ApiClient apiClient = new ApiClient();
otherdata otherdata = new otherdata();
otherdata.JS_SN = "12345";
//状态+报警
if (Init.Plcstatus != PlcData.Read_Status || (Plc_Time - Init.Plcstatus_LastTime).TotalSeconds > 15)
{
//反馈状态
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
{
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);
}
else
{
MES链接状态.Text = "MES链接状态:NG";
MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
}
}
if (Init.Plcstatus == (short)plcstatus.运行 && PlcData.Read_Status == (short)plcstatus.停机)
{
机台状态.BackColor = Color.Red;
//反馈报警
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
if (statusresult.Success)
{
MES链接状态.Text = "MES链接状态:OK";
MES链接状态.BackColor = SystemColors.Control;
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
MES_MsgfORM("Alarm", statusresult.Mesresult, statusresult.Requesttime);
}
else
{
MES链接状态.Text = "MES链接状态:NG";
MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
}
continue;
}
else
{
机台状态.BackColor = SystemColors.Control;
}
Init.Plcstatus = PlcData.Read_Status;
Init.Plcstatus_LastTime = DateTime.Now;
机台状态.Text = Enum.GetName(typeof(plcstatus), Init.Plcstatus);
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
if (nowflow == null)
{
label8.Text = $"PLC:{Plc.id}:未找到当前触发字{PlcData.Read_Trigger},对应的流程";
LogExecute.logNet.WriteError($"未找到当前触发字{PlcData.Read_Trigger},对应的流程!");
continue;
}
var nowinterface = Init.t_Interfaces.FirstOrDefault(a => a.id == nowflow.hopeinterfaceid);
if (nowinterface == null)
{
label8.Text = $"PLC:{Plc.id}:未找到当前期望接口ID {nowflow.hopeinterfaceid},对应的接口";
LogExecute.logNet.WriteError($"未找到当前期望接口ID {nowflow.hopeinterfaceid},对应的接口!");
continue;
}
otherdata otherdata = new otherdata();
otherdata.JS_SN = "12345";
ApiClient apiClient = new ApiClient();
var result = apiClient.CallFunctionByName(nowinterface.code,PlcData, otherdata);
if (result.Success)
{
var writeresult = siemensHelp.WriteAddress(Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id),PlcData);
if (!writeresult.Success)
{
label8.Text = $"PLC:{Plc.id}:{Plc.plcip}写入地址处理错误";
PLC链接状态.Text = "PLC链接状态:NG";
PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
continue;
}
else
{
MES链接状态.Text = "MES链接状态:OK";
MES链接状态.BackColor = SystemColors.Control;
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
}
else
{
label8.Text = $"MES通讯异常!";
MES链接状态.Text = "MES链接状态:NG";
MES链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"MES通讯异常!");
}
}
@ -253,20 +315,6 @@ namespace WindowsFormsApp1
开始处理.Text = "停止处理";
开始处理.BackColor = Color.Red;
label1.Text = "MES站名:" + Init.t_Line.linename;
label2.Text = "MES站名:" + Init.t_Line.linecode;
label3.Text = "类型:" + Init.t_Line.linetype;
label4.Text = "模组:" + Init.t_Line.linemode;
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
label8.Visible = true;
LogExecute.logNet.WriteInfo($"用户{Init.t_User.username},开始处理!");
}
else
@ -290,10 +338,9 @@ namespace WindowsFormsApp1
Thread.Sleep(500);
开始处理.Text = "开始处理";
开始处理.BackColor = Color.Green;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
Formrecover();
LogExecute.logNet.WriteInfo($"用户{Init.t_User.username},停止处理!");
}
}
@ -387,6 +434,130 @@ namespace WindowsFormsApp1
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
当前时间.Text = "当前时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
}
#endregion
public void Formrecover()
{
MES链接状态.Text = "MES链接状态:None";
MES链接状态.BackColor = SystemColors.Control;
MES通讯时间.Text = "MES通讯时间:None";
MES通讯时间.BackColor = SystemColors.Control;
PLC链接状态.Text = "PLC链接状态:None";
PLC链接状态.BackColor = SystemColors.Control;
PLC通讯时间.Text = "PLC通讯时间:None";
PLC通讯时间.BackColor = SystemColors.Control;
机台状态.Text = "机台状态:None";
机台状态.BackColor = SystemColors.Control;
请扫描LOT号.Enabled = false;
LOT号.Visible = false;
Tray盘二维码.Visible = false;
事件1.Visible = false;
事件1结果.Visible = false;
事件1时间.Visible = false;
事件2.Visible = false;
事件2结果.Visible = false;
事件2时间.Visible = false;
事件3.Visible = false;
事件3结果.Visible = false;
事件3时间.Visible = false;
事件4.Visible = false;
事件4结果.Visible = false;
事件4时间.Visible = false;
底部注释1.Visible = false;
底部注释2.Visible = false;
底部注释3.Visible = false;
底部注释4.Visible = false;
底部注释5.Visible = false;
}
public void MES_MsgfORM(string name,mesresult result,DateTime dateTime)
{
if (事件1.Text.Contains("事件"))
{
事件1.Visible = true;
事件1结果.Visible = true;
事件1时间.Visible = true;
事件1.Text = name;
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
事件1结果.Text = result.ToString();
}
else if (事件2.Text.Contains("事件"))
{
事件2.Visible = true;
事件2结果.Visible = true;
事件2时间.Visible = true;
事件2.Text = name;
事件2时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
事件2结果.Text = result.ToString();
}
else if (事件3.Text.Contains("事件"))
{
事件3.Visible = true;
事件3结果.Visible = true;
事件3时间.Visible = true;
事件3.Text = name;
事件3时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
事件3结果.Text = result.ToString();
}
else if (事件4.Text.Contains("事件"))
{
事件4.Visible = true;
事件4结果.Visible = true;
事件4时间.Visible = true;
事件4.Text = name;
事件4时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
事件4结果.Text = result.ToString();
}
else
{
事件1.Visible = true;
事件1结果.Visible = true;
事件1时间.Visible = true;
事件1.Text = name;
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
事件1结果.Text = result.ToString();
事件2.Visible = false;
事件2结果.Visible = false;
事件2时间.Visible = false;
事件2.Text = "事件2";
事件2时间.Text = "事件2时间";
事件2结果.Text = "OK";
事件3.Visible = false;
事件3结果.Visible = false;
事件3时间.Visible = false;
事件3.Text = "事件3";
事件3时间.Text = "事件3时间";
事件3结果.Text = "OK";
事件4.Visible = false;
事件4结果.Visible = false;
事件4时间.Visible = false;
事件4.Text = "事件4";
事件4时间.Text = "事件4时间";
事件4结果.Text = "OK";
}
}
}
}

View File

@ -120,6 +120,9 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>205, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>79</value>
</metadata>

View File

@ -50,5 +50,9 @@ namespace WindowsFormsApp1
public static int errinterface1 = 0;
public static int errinterface2 = 0;
public static short Plcstatus = 0;
public static DateTime Plcstatus_LastTime = DateTime.Now;
}
}

Binary file not shown.

View File

@ -16,8 +16,8 @@ namespace WindowsFormsApp1.mod
public string plcip { get; set; }
public int timeout { get; set; }
[Ignore]
public DateTime dateTime { get; set; }
//[Ignore]
//public DateTime dateTime { get; set; }
[Ignore]
public SiemensHelp plchelp { get; set; }
}

View File

@ -8,8 +8,24 @@ namespace WindowsFormsApp1.mod
{
public enum mesresult
{
pass,
fail,
none
PASS,
FAIL,
NONE
};
public enum plcstatus
{
运行 = (short)1,
停机 = (short)2,
保养 = (short)3,
MESReset = (short)4,
准备或休息 = (short)5,
欠载具 = (short)6,
欠物料 = (short)7,
其他机台计划停机 = (short)8,
其他机台非计划停机 = (short)9,
点检 = (short)10,
换料 = (short)11,
未知 = (short)0,
};
}

View File

@ -9,9 +9,14 @@ namespace WindowsFormsApp1.mod.server
public class otherdata
{
/// <summary>
/// MES返回的SN
/// PLC反馈的机台状态
/// </summary>
public string MES_SN { get; set; }
public plcstatus Plc_Status { get; set; }
/// <summary>
/// PLC反馈的机台报警
/// </summary>
public string Plc_ErrorMsg { get; set; }
/// <summary>
/// 文件上传地址

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HslCommunication" version="7.0.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="sqlite-net" version="1.6.292" targetFramework="net48" />
</packages>

View File

@ -15,68 +15,68 @@ namespace WindowsFormsApp1.server
{
public ApiFormResult SN_CheckIN(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Carrier_Check(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult SN_FeedingCheck(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Link_Comp(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult SN_Release(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Glue_CheckOut(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Get_Para(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult DispatchPara(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Data_Collection(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Status(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult Alarm(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult OEEDataCollection(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass, false, "", PlcData);
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
}
public ApiFormResult SN_FileUpload(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass, false, "", PlcData);
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
}
public ApiFormResult Test(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass, false, "", PlcData);
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
}
public ApiFormResult SN_Checkout(plcdata PlcData, otherdata OtherData)
{
return ApiFormResult.Sucess(mesresult.pass, false, "", PlcData);
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData,DateTime.Now);
}
public ApiFormResult Initialization(plcdata PlcData, otherdata OtherData)
{
PlcData.Write_Status = 3;
return ApiFormResult.Sucess(mesresult.pass,false,"", PlcData);
return ApiFormResult.Sucess(mesresult.PASS,false,"", PlcData,DateTime.Now);
}
public ApiFormResult CallFunctionByName(string functionName, plcdata plcdata,otherdata otherdata)
@ -95,7 +95,7 @@ namespace WindowsFormsApp1.server
else
{
LogExecute.logNet.WriteError($"未找到对应的函数{functionName}");
return ApiFormResult.Error(mesresult.none, false, $"未找到对应的函数{functionName}", null);
return ApiFormResult.Error(mesresult.NONE, false, $"未找到对应的函数{functionName}", null,DateTime.Now);
}
}
}

View File

@ -11,13 +11,14 @@ namespace WindowsFormsApp1.server
{
public class ApiFormResult
{
private ApiFormResult(bool success, mesresult mesresult, bool isShow, string msg, plcdata data)
private ApiFormResult(bool success, mesresult mesresult, bool isShow, string msg, plcdata data,DateTime requesttime)
{
Success = success;
Msg = msg;
Data = data;
Mesresult = mesresult;
IsShow = isShow;
Requesttime = requesttime;
}
public bool Success { get; set; }
@ -28,15 +29,17 @@ namespace WindowsFormsApp1.server
public bool IsShow { get; set; }
public static ApiFormResult Sucess(mesresult mesresult, bool isShow, string msg, plcdata data)
public DateTime Requesttime { get; set; }
public static ApiFormResult Sucess(mesresult mesresult, bool isShow, string msg, plcdata data, DateTime requesttime)
{
return new ApiFormResult(true, mesresult, isShow, msg, data);
return new ApiFormResult(true, mesresult, isShow, msg, data, requesttime);
}
public static ApiFormResult Error(mesresult mesresult, bool isShow, string msg, plcdata data)
public static ApiFormResult Error(mesresult mesresult, bool isShow, string msg, plcdata data, DateTime requesttime)
{
return new ApiFormResult(false, mesresult, isShow, msg, data);
return new ApiFormResult(false, mesresult, isShow, msg, data,requesttime);
}
}