5.12 OEE相关日志放到右侧

螺丝添加NG的统计
This commit is contained in:
gf zhou committed 2025-05-12 14:01:46 +08:00
1 parent e8001a81bb
commit 817b66ad53
4 files changed
+117 -78

No files matched your search

+48 -30
View File
@@ -17,6 +17,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using HslCommunication.LogNet;
using Newtonsoft.Json.Linq;
using WindowsFormsApp1.db;
using WindowsFormsApp1.form;
using WindowsFormsApp1.mod;
@@ -131,10 +132,10 @@ namespace WindowsFormsApp1
statusReportTimer.Interval = 1000 * 15;
statusReportTimer.Tick += StatusReportTimer_Tick;
screwReportTimer.Interval = 1000 * 60 * 15;
screwReportTimer.Interval = 1000 * 60 * 5;
screwReportTimer.Tick += ScrewReportTimer_Tick;
fileUploadTimer.Interval = 1000 * 60 * 15;
fileUploadTimer.Interval = 1000 * 60 * 2;
fileUploadTimer.Tick += FileUploadTimer_Tick;
}
@@ -210,7 +211,6 @@ namespace WindowsFormsApp1
continue;
}*/
if (Init.t_Lineplcs.Count >= 2 && Plc.id == Init.t_Lineplcs.First().plcid)
{
LOT号.Text = PlcData.Write_stSN;
@@ -338,7 +338,7 @@ namespace WindowsFormsApp1
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
if (statusresult.Success)
{
LogExecute.OEElogNet.WriteDebug($"上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)} {Init.ErrorCode}");
LogExecute.OEElogNet.WriteDebug($"上报机台状态成功: {plcstatus.GetName(typeof(plcstatus), Init.Plcstatus)} {otherdata.Plc_Status}");
//beginScrewReportTimer = 0;
if (!statusReportTimer.Enabled)
{
@@ -403,7 +403,7 @@ namespace WindowsFormsApp1
siemensHelp.WriteAddress(plcaddress, PlcData);
}
}
continue;
//continue;
}
else
{
@@ -424,6 +424,8 @@ namespace WindowsFormsApp1
OldPlcTrigger[Plc.id] = PlcData.Read_Trigger;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.plcname}:{Plc.id}-{PlcData.Read_Trigger}");
if (PlcData.Read_Trigger == 0 && PlcData.Write_Status == 0)
{
continue;
@@ -442,9 +444,10 @@ namespace WindowsFormsApp1
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止");
}
LogExecute.logNet.WriteDebug($"写入状态字0");
continue;
}
LogExecute.logNet.WriteDebug($"读取状态字{Plc.id}-{PlcData.Read_Trigger}");
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
if (nowflow == null)
@@ -580,23 +583,21 @@ namespace WindowsFormsApp1
}
otherdata.FinalPressureCurve = pressurecurveaddress_result.Data;
}
//if (nowflow.finaltorquecurve)
//{
// //扭力曲线(这里不处理,后端API获取)
//}
//螺丝扭力
if (nowflow.finaltorquevalue)
{
//螺丝枪扭力数据
var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
/* var finaltorquevalue_result = siemensHelp.ReadAddress(torqueaddress);
if (!finaltorquevalue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪扭力数据地址处理错误:处理停止");
continue;
}
otherdata.FinalTorqueValue = finaltorquevalue_result.Data;
*/
}
//气密
if (nowflow.airtight)
@@ -611,12 +612,14 @@ namespace WindowsFormsApp1
var finalanglevaluue_result = siemensHelp.ReadAddress(angleaddress);
if (!finalanglevaluue_result.Success)
{
//PLC链接状态.Text = "PLC链接状态:NG";
//PLC链接状态.BackColor = Color.Red;
LogExecute.logNet.WriteError($"{Plc.plcip}螺丝枪角度数据地址处理错误:处理停止");
continue;
}
otherdata.FinalAngleValue = finalanglevaluue_result.Data;
otherdata.FinalAngleValue = Enumerable
.Range(0, (finalanglevaluue_result.Data.Count + 3) / 4) // 计算组数
.Select(i => finalanglevaluue_result.Data.Skip(i * 4).Take(4).ToList())
.ToList();
}
if (nowflow.fileupload)
{
@@ -793,7 +796,7 @@ namespace WindowsFormsApp1
PlcData.Write_Status = 1001;
}
siemensHelp.WriteAddress(plcaddress, PlcData);
LogExecute.logNet.WriteDebug($"上位机写入触发字:{PlcData.Write_Status}");
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
continue;
}
else
@@ -804,7 +807,8 @@ namespace WindowsFormsApp1
PlcData.Write_stSN = "";
}
}
LogExecute.logNet.WriteDebug($"上位机写入触发字:{PlcData.Write_Status}");
LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}上位机写入触发字:{PlcData.Write_Status}");
}
}
else
@@ -1868,7 +1872,7 @@ namespace WindowsFormsApp1
if (material_sqlresult.Success)
{
ApiClient apiClient = new ApiClient();
var materialList = material_sqlresult.Data.Where(x => (DateTime.Now - x.outtime).TotalHours > 1).Take(5);
var materialList = material_sqlresult.Data.Where(x => (DateTime.Now - x.outtime).TotalMinutes > 20).Take(5);
foreach (var material in materialList)
{
otherdata OtherData = new otherdata();
@@ -1929,7 +1933,8 @@ namespace WindowsFormsApp1
material.vedioUploaded = 2;
sQLiteHelper_upload.Update(material);
LogExecute.logNet.WriteDebug($"{material.sn} 文件上传成功!");
}else if (result.Mesresult == mesresult.NONE)
}
else if (result.Mesresult == mesresult.NONE)
{
//标记该物料已上传
if (material.imageUploaded == 1)
@@ -2007,7 +2012,10 @@ namespace WindowsFormsApp1
{
SiemensHelp siemensHelp = Plc.plchelp;
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code.Contains("Heartbeat") || a.code == "NowDateTime");
&& a.code == "Write_Heartbeat");
List<t_plcaddress> timeplcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
&& a.code == "NowDateTime");
plcdata PlcData = new plcdata();
@@ -2019,12 +2027,22 @@ namespace WindowsFormsApp1
//写入心跳
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
PlcData.NowDateTime = DateTime.Now.AddSeconds(3);
//LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}写入心跳{PlcData.Write_Heartbeat}!");
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
if (!haertresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳错误!");
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入心跳失败!");
}
//写入时间
var timeData = new plcdata
{
NowDateTime = DateTime.Now.AddSeconds(3)
};
var timeresult = siemensHelp.WriteAddress(timeplcaddress, timeData);
if (!timeresult.Success)
{
LogExecute.logNet.WriteError($"{Plc.plcname}:{Plc.plcip}写入时间失败!");
}
}
catch (Exception)
+1 -1
View File
@@ -51,7 +51,7 @@ namespace WindowsFormsApp1.mod.server
/// <summary>
/// 螺丝枪角度
/// </summary>
public List<float> FinalAngleValue { get; set; }
public List<List<dynamic>> FinalAngleValue { get; set; }
/// <summary>
/// 螺丝枪扭力曲线
+60 -42
View File
@@ -143,7 +143,14 @@ namespace WindowsFormsApp1.server
PlcData.Write_Status = (short)statusCode;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = "TEST MODE testsn";
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
}
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
}
#endregion test
@@ -169,13 +176,20 @@ namespace WindowsFormsApp1.server
// 访问动态对象的属性
if (res != null)
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
//oee相关日志单独存
if (eventName == "Status" || eventName == "Alarm" || eventName == "OEEDataCollection")
{
LogExecute.OEElogNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
else
{
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
}
// 成功!
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
{
var result = res.Result.Value == "PASS";
if(!string.IsNullOrEmpty( res?.Need_Work?.Value) && res?.Need_Work?.Value == "PASS")
if (!string.IsNullOrEmpty(res?.Need_Work?.Value) && res?.Need_Work?.Value == "PASS")
result = true;
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
PlcData.Write_stSN = res.SN.Value;
@@ -527,7 +541,7 @@ namespace WindowsFormsApp1.server
else if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(station))
{
// 扭力 读马头服务器
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date.Substring(0,10)}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date.Substring(0, 10)}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
//var geturl = "http://10.50.12.41/getdata/v2/tighteningresults?startTime=2025-04-11&endTime=2025-04-12&vin=ok&controllerName=OP1260%4010.50.247.110&includeCurve=true&includeSteps=false";
var res = _httpClient.GetAsync(geturl).Result;
@@ -588,7 +602,7 @@ namespace WindowsFormsApp1.server
{
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
if(request.DC_INFO.Count == 0)
if (request.DC_INFO.Count == 0)
{
return ApiFormResult.Sucess(mesresult.NONE, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
}
@@ -646,8 +660,8 @@ namespace WindowsFormsApp1.server
var day = "";
if (OtherData.material.imageUploaded == 1)
{
month = OtherData.material.date.Substring(0, 6);
day =OtherData.material.date.Substring(6, 2);
month = OtherData.material.date.Replace("-", "").Substring(0, 6);
day = OtherData.material.date.Replace("-", "").Substring(6, 2);
}
else
{
@@ -702,7 +716,7 @@ namespace WindowsFormsApp1.server
{
// 图片
// 组装路径 可能需要从数据库读 result和sn和日期
sourceFolder = Path.Combine(OtherData.ImageAddress, OtherData.material.date, "DCDC", result);
sourceFolder = Path.Combine(OtherData.ImageAddress, OtherData.material.date.Replace("-", ""), "DCDC", result);
}
else
{
@@ -871,36 +885,40 @@ namespace WindowsFormsApp1.server
//扭力,角度
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".Contains(stationid))
{
var count = OtherData.FinalAngleValue.Count(x => x > 0);
for (int i = 0; i < count; i++)
Dictionary<int, int> countDict = new Dictionary<int, int>();
foreach (var item in OtherData.FinalAngleValue)
{
CsvLogger.Log($"{PlcData.Write_stSN},{OtherData.FinalAngleValue[i]},{OtherData.FinalTorqueValue[i]}");
if (item[0] > 0)
{
var value = item[3];
if (!countDict.ContainsKey(value))
{
countDict[value] = 1;
}
else
{
countDict[value]++;
}
var scewResult = item[2] == 1 ? "PASS" : "FAIL";
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{item[3]}_{countDict[value]}";
dcInfo.Value = item[1].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{item[3]}_{countDict[value]}";
dcInfo.Value = item[0].ToString();
dcInfo.Result = scewResult;
sninfo.DC_INFO.Add(dcInfo);
CsvLogger.Log($"{PlcData.Write_stSN},{item[1]},{item[0]}");
}
}
var AngleCount = 1;
foreach (var item in OtherData.FinalAngleValue.Where(x => x > 0))
{
//角度
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Angle{AngleCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
AngleCount++;
}
var TorqueCount = 1;
foreach (var item in OtherData.FinalTorqueValue.Where(x => x > 0))
{
//扭力
dcInfo = new DCInfoItem();
dcInfo.Item = $"{Init.t_Line.lineremark2}_Torque{TorqueCount}";
dcInfo.Value = item.ToString();
dcInfo.Result = result;
sninfo.DC_INFO.Add(dcInfo);
TorqueCount++;
}
if (!_isTestMode)
{
@@ -1064,7 +1082,7 @@ namespace WindowsFormsApp1.server
sn = PlcData.Write_stSN,
imageUploaded = 1,
result = logresult,
date = DateTime.Now.ToString("yyyyMMdd"),
date = DateTime.Now.ToString("yyyy-MM-dd"),
outtime = DateTime.Now
};
materialuploadHelper.Insert(material);
@@ -1260,7 +1278,7 @@ namespace WindowsFormsApp1.server
try
{
// 打印调用开始日志
LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"开始调用API: {functionName}...");
// 检查API URL是否存在
if (!apiUrlDict.ContainsKey(functionName))
@@ -1272,13 +1290,13 @@ namespace WindowsFormsApp1.server
// 使用同步方法调用API,并结合重试策略
var result = retryPolicy.Execute(() =>
{
LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
//LogExecute.logNet.WriteDebug($"正在尝试调用API: {functionName}...");
// 调用该方法
return (ApiFormResult)methodInfo.Invoke(this, new object[] { apiUrlDict[functionName], plcdata, otherdata });
});
// 打印调用结束日志
LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
//LogExecute.logNet.WriteDebug($"API调用成功: {functionName}");
return result;
}
catch (Exception ex)
@@ -1363,8 +1381,8 @@ namespace WindowsFormsApp1.server
#endregion
#region checkout class
// 根对象类
public class CheckOutObject
// 根对象类
public class CheckOutObject
{
public List<SNInfoItem> SNInfo { get; set; }
public string Qty { get; set; }
+8 -5
View File
@@ -487,7 +487,7 @@ namespace WindowsFormsApp1.server
#endregion
#region 读取角度
public BllResult<List<float>> ReadAddress(List<t_angleaddress> address)
public BllResult<List<dynamic>> ReadAddress(List<t_angleaddress> address)
{
var ulist = address.GroupBy(a => a.dbaddress).ToList();
foreach (var u in ulist)
@@ -495,15 +495,18 @@ namespace WindowsFormsApp1.server
var readresult = ReadOneDB(u.ToList());
if (!readresult.Success)
{
return BllResult<List<float>>.Error(readresult.Msg);
return BllResult<List<dynamic>>.Error(readresult.Msg);
}
}
List<float> list = new List<float>();
List<dynamic> list = new List<dynamic>();
foreach (var add in address.OrderBy(a => a.addressoffset))
{
list.Add(float.Parse(add.value));
if(add.addresstype == "real")
list.Add(float.Parse(add.value));
else
list.Add(short.Parse(add.value));
}
return BllResult<List<float>>.Sucess(list, "成功");
return BllResult<List<dynamic>>.Sucess(list, "成功");
}
private BllResult ReadOneDB(List<t_angleaddress> address)
{