|
@@ -13,6 +13,7 @@ using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
|
|
|
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
|
|
|
using System.IO;
|
|
|
using MainForm.ClassFile.FALibraryClass;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
namespace MainForm
|
|
|
{
|
|
@@ -351,37 +352,37 @@ namespace MainForm
|
|
|
passStaResultRequ.device_code = GlobalContext.S2_device_code; // 装备编码
|
|
|
passStaResultRequ.station = GlobalContext.S2_station; // ⼯位Id
|
|
|
break;
|
|
|
- case "[S3]值板机":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S3_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S3_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S3_station; // ⼯位Id
|
|
|
- break;
|
|
|
- case "[S4_1]载具下线装备":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S4_1_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S4_1_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S4_1_station; // ⼯位Id
|
|
|
- break;
|
|
|
- case "[S4_3]提升机1":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S4_3_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S4_3_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S4_3_station; // ⼯位Id
|
|
|
- break;
|
|
|
- case "[S4_4]提升机2":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S4_4_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S4_4_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S4_4_station; // ⼯位Id
|
|
|
- break;
|
|
|
- case "[S4_5]载具上线装备":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S4_5_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S4_5_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S4_5_station; // ⼯位Id
|
|
|
- break;
|
|
|
- case "[S5]Tray盘下料装备":
|
|
|
- passStaResultRequ.work_station = GlobalContext.S5_work_station; // ⼯站
|
|
|
- passStaResultRequ.device_code = GlobalContext.S5_device_code; // 装备编码
|
|
|
- passStaResultRequ.station = GlobalContext.S5_station; // ⼯位Id
|
|
|
- break;
|
|
|
- default:
|
|
|
+ //case "[S3]值板机":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S3_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S3_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S3_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //case "[S4_1]载具下线装备":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S4_1_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S4_1_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S4_1_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //case "[S4_3]提升机1":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S4_3_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S4_3_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S4_3_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //case "[S4_4]提升机2":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S4_4_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S4_4_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S4_4_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //case "[S4_5]载具上线装备":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S4_5_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S4_5_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S4_5_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //case "[S5]Tray盘下料装备":
|
|
|
+ // passStaResultRequ.work_station = GlobalContext.S5_work_station; // ⼯站
|
|
|
+ // passStaResultRequ.device_code = GlobalContext.S5_device_code; // 装备编码
|
|
|
+ // passStaResultRequ.station = GlobalContext.S5_station; // ⼯位Id
|
|
|
+ // break;
|
|
|
+ //default:
|
|
|
break;
|
|
|
}
|
|
|
passStaResultRequ.process_time = processData.Test_time; // 过站时间
|
|
@@ -721,6 +722,7 @@ namespace MainForm
|
|
|
/// 记录上次保存 设备状态数据CSV 的时间
|
|
|
/// </summary>
|
|
|
private DateTime dtSaveDeviceStateCSV_Old = DateTime.Now.AddMinutes(-5);
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 上传设备状态数据
|
|
|
/// 上传IOT + 5分钟记录一次数据到txt中
|
|
@@ -730,7 +732,6 @@ namespace MainForm
|
|
|
/// <param name="fault_code">故障编码</param>
|
|
|
/// <param name="fault_tm">故障发⽣时间</param>
|
|
|
/// <returns>上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;</returns>
|
|
|
-
|
|
|
public (int, string) SaveDeviceStateData(string stationNameStr, XiaomiDeviceState deviceState, string fault_code = "A40000", string fault_tm = "")
|
|
|
{
|
|
|
int result = 0;
|
|
@@ -743,20 +744,28 @@ namespace MainForm
|
|
|
if (GlobalContext.IsUseIot && GlobalContext.IsMqttDeviceState)
|
|
|
{
|
|
|
DeviceStateDataRequest request = new DeviceStateDataRequest();
|
|
|
+ DeviceStateDataRequest2Station request2 = new DeviceStateDataRequest2Station();
|
|
|
+
|
|
|
if (GlobalContext.IsUsePLC1)
|
|
|
request.station = GlobalContext.S1_station; // 工位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC2)
|
|
|
request.station = GlobalContext.S2_station; // 工位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC3)
|
|
|
- request.station = GlobalContext.S3_station; // 工位ID(可配置)
|
|
|
+ request2.left.station = GlobalContext.s3_1_station; // 工位ID(可配置)
|
|
|
+ request2.left.station = GlobalContext.s3_2_station; // ⼯位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC4)
|
|
|
- request.station = GlobalContext.S4_1_station; // ⼯位ID(可配置)
|
|
|
+ request.station = GlobalContext.s4_station; // 工位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC5)
|
|
|
- request.station = GlobalContext.S5_station; // 工位ID(可配置)
|
|
|
+ request.station = GlobalContext.s5_station; // 工位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC6)
|
|
|
- request.station = GlobalContext.S6_station; // 工位ID(可配置)
|
|
|
+ request.station = GlobalContext.s6_station; // 工位ID(可配置)
|
|
|
if (GlobalContext.IsUsePLC7)
|
|
|
- request.station = GlobalContext.S7_station; // ⼯位ID(可配置)
|
|
|
+ request2.left.station = GlobalContext.s7_1_station; // ⼯位ID(可配置)
|
|
|
+ request2.right.station = GlobalContext.s7_2_station; // ⼯位ID(可配置)
|
|
|
+ if (GlobalContext.IsUsePLC8)
|
|
|
+ request.station = GlobalContext.s8_station; // ⼯位ID(可配置)
|
|
|
+ if (GlobalContext.IsUsePLC9)
|
|
|
+ request.station = GlobalContext.s9_station; // ⼯位ID(可配置)
|
|
|
|
|
|
request.state = deviceState.ToString(); // 设备状态
|
|
|
request.time = dtNow.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 状态切换时的时间 2022-06-01 14:27:57.283
|
|
@@ -765,32 +774,27 @@ namespace MainForm
|
|
|
request.fault_code = fault_code; // 对应的故障编码
|
|
|
request.fault_tm = fault_tm; // 故障发⽣时间(需要实际的发生时间)
|
|
|
}
|
|
|
-
|
|
|
// 上传
|
|
|
- (int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
|
|
|
-
|
|
|
- result = iotResult.Item1 == 0 ? 1 : 2;
|
|
|
- msg = $"[{iotResult.Item1}]{iotResult.Item2}";
|
|
|
-
|
|
|
- // 5分钟记录一次数据到txt中
|
|
|
- if (dtSaveDeviceStateCSV_Old < dtNow)
|
|
|
+ if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
|
|
|
{
|
|
|
- string fileDir = GlobalContext.MqttDeviceStateDir + dtNow.ToString("yyyy_MM"); // 文件夹路径
|
|
|
- if (!Directory.Exists(fileDir))
|
|
|
- Directory.CreateDirectory(fileDir);
|
|
|
-
|
|
|
- string filePath = fileDir + dtNow.ToString("yyyy_MM_dd"); // 文件路径
|
|
|
+ (int, string) iotResultL = XiaomiMqttClient_Extend.Write_DeviceStateData(request2.left);
|
|
|
+ (int, string) iotResultR = XiaomiMqttClient_Extend.Write_DeviceStateData(request2.right);
|
|
|
|
|
|
- StringBuilder sbData = new StringBuilder();
|
|
|
- if (!File.Exists(filePath))
|
|
|
- sbData.AppendLine("工位ID,设备状态,状态切换时的时间,故障编码,故障发生时间,上传结果");
|
|
|
+ if (iotResultL.Item1 == 0 || iotResultR.Item1 == 0)
|
|
|
+ result = 1;
|
|
|
+ else
|
|
|
+ result = 2;
|
|
|
|
|
|
- string iotResultMsg = $"[{iotResult.Item1}]{iotResult.Item2}";
|
|
|
- sbData.AppendLine($"{request.station},{request.state},{request.time},{request.fault_code},{request.fault_tm},{iotResultMsg}"); // 文件内容
|
|
|
-
|
|
|
- // 保存到CSV文件中
|
|
|
- string newLineData = sbData.ToString(); // 文件内容
|
|
|
- CSVHelper.CSVFile_AddLog(filePath, newLineData);
|
|
|
+ msg = $"[{iotResultL.Item1}]{iotResultL.Item2};[{iotResultR.Item1}]{iotResultR.Item2}";
|
|
|
+ SaveDeviceStateDataLog(iotResultL, request, dtNow);
|
|
|
+ SaveDeviceStateDataLog(iotResultR, request, dtNow);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ (int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
|
|
|
+ result = iotResult.Item1 == 0 ? 1 : 2;
|
|
|
+ msg = $"[{iotResult.Item1}]{iotResult.Item2}";
|
|
|
+ SaveDeviceStateDataLog(iotResult, request, dtNow);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -805,6 +809,33 @@ namespace MainForm
|
|
|
}
|
|
|
return (result, msg);
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 5分钟记录一次数据到txt中
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="iotResult"></param>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ private void SaveDeviceStateDataLog((int, string) iotResult, DeviceStateDataRequest request,DateTime dtNow) {
|
|
|
+ if (dtSaveDeviceStateCSV_Old < dtNow)
|
|
|
+ {
|
|
|
+ string fileDir = GlobalContext.MqttDeviceStateDir + dtNow.ToString("yyyy_MM"); // 文件夹路径
|
|
|
+ if (!Directory.Exists(fileDir))
|
|
|
+ Directory.CreateDirectory(fileDir);
|
|
|
+
|
|
|
+ string filePath = fileDir + dtNow.ToString("yyyy_MM_dd"); // 文件路径
|
|
|
+
|
|
|
+ StringBuilder sbData = new StringBuilder();
|
|
|
+ if (!File.Exists(filePath))
|
|
|
+ sbData.AppendLine("工位ID,设备状态,状态切换时的时间,故障编码,故障发生时间,上传结果");
|
|
|
+
|
|
|
+ string iotResultMsg = $"[{iotResult.Item1}]{iotResult.Item2}";
|
|
|
+ sbData.AppendLine($"{request.station},{request.state},{request.time},{request.fault_code},{request.fault_tm},{iotResultMsg}"); // 文件内容
|
|
|
+
|
|
|
+ // 保存到CSV文件中
|
|
|
+ string newLineData = sbData.ToString(); // 文件内容
|
|
|
+ CSVHelper.CSVFile_AddLog(filePath, newLineData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion 设备状态数据
|
|
|
|
|
|
#region 报警数据
|
|
@@ -834,8 +865,18 @@ namespace MainForm
|
|
|
/// <summary>
|
|
|
/// 上传节拍数据
|
|
|
/// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEProductSN)
|
|
|
+ /// <param name="plcNo"></param>
|
|
|
+ /// <param name="stationNameStr"></param>
|
|
|
+ /// <param name="deviceOEE"></param>
|
|
|
+ /// <param name="oEEPartNo"></param>
|
|
|
+ /// <param name="oEEVSN"></param>
|
|
|
+ /// <param name="extra"></param>
|
|
|
+ /// <param name="class_level_1"></param>
|
|
|
+ /// <param name="class_level_2"></param>
|
|
|
+ /// <param name="class_level_3"></param>
|
|
|
+ /// <returns>上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;</returns>
|
|
|
+ public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEVSN, string extra = ""
|
|
|
+ , string class_level_1 = "beat_log", string class_level_2 = "business", string class_level_3 = "OEE")
|
|
|
{
|
|
|
// 上传OEE
|
|
|
if (GlobalContext.IsMqttStationInputBegin)
|
|
@@ -848,52 +889,61 @@ namespace MainForm
|
|
|
oee.action = deviceOEE.ToString(); // 节拍动作(XiaomiDeviceOEE)
|
|
|
oee.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间
|
|
|
oee.action_subject = oEEPartNo; // 该动作操作的⽬标对象(SN)
|
|
|
- oee.action_subject_parent = oEEProductSN; // ⼤板SN/载具SN
|
|
|
- oee.action_location = GlobalContext.S1_station; // 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
|
|
|
+ oee.action_subject_parent = oEEVSN; // ⼤板SN/载具SN
|
|
|
switch (stationNameStr)
|
|
|
{
|
|
|
- case "[S1]Tray盘上料装备":
|
|
|
+ case "[OP10]壳体清洁上料":
|
|
|
oee.action_location = GlobalContext.S1_station;
|
|
|
break;
|
|
|
- case "[S2]FCT":
|
|
|
+ case "[OP20]上盖板上料装备":
|
|
|
oee.action_location = GlobalContext.S2_station;
|
|
|
break;
|
|
|
- case "[S3]值板机":
|
|
|
- oee.action_location = GlobalContext.S3_station;
|
|
|
+ case "[OP30]点散热胶装备_Left":
|
|
|
+ oee.action_location = GlobalContext.s3_1_station;
|
|
|
+ break;
|
|
|
+ case "[OP30]点散热胶装备_Right":
|
|
|
+ oee.action_location = GlobalContext.s3_2_station;
|
|
|
+ break;
|
|
|
+ case "[OP40]胶线检测":
|
|
|
+ oee.action_location = GlobalContext.s4_station;
|
|
|
+ break;
|
|
|
+ case "[OP50]ADD板上料组装装备":
|
|
|
+ oee.action_location = GlobalContext.s5_station;
|
|
|
break;
|
|
|
- case "[S4_1]载具下线装备":
|
|
|
- oee.action_location = GlobalContext.S4_1_station;
|
|
|
+ case "[OP60]组上盖板":
|
|
|
+ oee.action_location = GlobalContext.s6_station;
|
|
|
break;
|
|
|
- case "[S4_3]提升机1":
|
|
|
- oee.action_location = GlobalContext.S4_3_station;
|
|
|
+ case "[OP70]上盖板锁螺丝_Left":
|
|
|
+ oee.action_location = GlobalContext.s7_1_station;
|
|
|
break;
|
|
|
- case "[S4_4]提升机2":
|
|
|
- oee.action_location = GlobalContext.S4_4_station;
|
|
|
+ case "[OP70]上盖板锁螺丝_Right":
|
|
|
+ oee.action_location = GlobalContext.s7_2_station;
|
|
|
break;
|
|
|
- case "[S4_5]载具上线装备":
|
|
|
- oee.action_location = GlobalContext.S4_5_station;
|
|
|
+ case "[OP80]NG下料":
|
|
|
+ oee.action_location = GlobalContext.s8_station;
|
|
|
break;
|
|
|
- case "[S5]Tray盘下料装备":
|
|
|
- oee.action_location = GlobalContext.S5_station;
|
|
|
+ case "[OP90]半成品下料":
|
|
|
+ oee.action_location = GlobalContext.s8_station;
|
|
|
break;
|
|
|
}
|
|
|
- oee.action_material = string.Empty; // 该动作的物料信息
|
|
|
- oee.extra = string.Empty; // 额外信息
|
|
|
- oee.class_level_1 = string.Empty; // 分类层级1
|
|
|
- oee.class_level_2 = string.Empty; // 分类层级2
|
|
|
- oee.class_level_3 = string.Empty; // 分类层级3
|
|
|
-
|
|
|
- int result = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
|
|
|
-
|
|
|
- string msg = $"[{result}]";
|
|
|
- bool errCodeParse = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode);
|
|
|
- msg += errCodeParse ? errCode.ToString() : "ERR_UNKOWN";
|
|
|
- AddMessage(LogType.Info, stationNameStr + $"_异步上传节拍接口;接口结果:-- {msg}");
|
|
|
+ oee.action_material = oee.action_location + "_1"; // 该动作的物料信息
|
|
|
+ oee.extra = extra; // 额外信息
|
|
|
+ oee.class_level_1 = class_level_1; // 分类层级1
|
|
|
+ oee.class_level_2 = class_level_2; // 分类层级2
|
|
|
+ oee.class_level_3 = class_level_3; // 分类层级3
|
|
|
+
|
|
|
+ var iotResult = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
|
|
|
+ int result = iotResult.Item1;
|
|
|
+ string msg = $"[{iotResult.Item1}]{iotResult.Item2}";
|
|
|
+ if (result == 0)
|
|
|
+ OnMessage(LogType.Info, stationNameStr + $"_异步上传Iot节拍数据[SN:{oEEPartNo}]成功!iot接口返回结果:{msg}");
|
|
|
+ else
|
|
|
+ AddMessage(LogType.Info, stationNameStr + $"_异步上传Iot节拍数据[SN:{oEEPartNo}]失败!iot接口返回结果:{msg}");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
string str = ex.StackTrace;
|
|
|
- AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 异步上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
|
|
|
+ AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr}_[{oEEPartNo}]异步上传Iot节拍数据失败!报错信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
|
|
|
}
|
|
|
});
|
|
|
|