using BZFAStandardLib; using Newtonsoft.Json; using System; using static System.Runtime.CompilerServices.RuntimeHelpers; namespace MainForm.ClassFile.XiaomiAPI { /// /// 小米 MqttClient类 - API拓展方法 /// 过站结果 /// public partial class XiaomiMqttClient_Extend : XiaomiMqttClient { /// /// 过站结果- 事件Id /// private static string PassStationResultId { get; set; } = "pass_details_log/passing_station_log"; /// /// 过站结果- 事件方法 /// /// 事件数据;Json /// 自定义事件Id;如:guid /// public static (int, string) Write_PassStationResult(PassStationResultRequest request, string dataId = "") { int result = 0; string resultStr = ""; string msg = JsonConvert.SerializeObject(request); byte[] bytes = ToUTF8(msg); // 发送 if (string.IsNullOrEmpty(dataId)) result = Write(PassStationResultId, bytes); else result = WriteWithDataId(PassStationResultId, bytes, dataId); var try1 = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode); if (try1) resultStr = errCode.ToString(); else resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString(); string logPath = GlobalContext.MqttAlarmLogDir + "PassStationResult" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; FileOperate.NewTxtFile(logPath, "MQTT【过站结果】提交:" + msg + "\r\n==>提交结果:" + resultStr + ""); return (result, resultStr); } /// /// 过站结果- 参数 /// public class PassStationResultRequest { /// /// 过站唯⼀标识(36位) /// string[1,64] /// 要确保唯⼀性,每次过站时⽣成的ID必须唯⼀。 /// • 对于同⼀次过站⽽⾔,过站明细中的pass_station_id字段值与过站结果中的pass_station_id字段值是⼀样的。 /// • 与mes中的过站明细uuid字段uuidInspection要求⼀致(这两个值需确保是⼀致的,以MES为主,如果关闭MES⽣产,则此项传空字符串) /// public string pass_station_id { get; set; } = Guid.NewGuid().ToString(); /// /// 项⽬编码 /// string[1,32] /// public string project_code { get; set; } = string.Empty; /// /// ⼯⼚Id /// string[1,64] /// public string factory_code { get; set; } = string.Empty; /// /// ⼯段编码 /// string[1,32] /// public string process_section_code { get; set; } = string.Empty; /// /// 线体编码 /// string[1,32] /// public string line_code { get; set; } = string.Empty; /// /// ⼯站 /// string[1,32] /// public string work_station { get; set; } = string.Empty; /// /// 装备编码 /// string[1,32] /// public string device_code { get; set; } = string.Empty; /// /// ⼯位Id /// string[1,32] /// 与MES那边的stationId保持⼀致 /// public string station { get; set; } = string.Empty; /// /// 过站时间 /// string[1,32] /// 日期格式:2022-06-01 14:27:57.283 /// public string process_time { get; set; } = string.Empty; /// /// 槽位编码 /// string[1,32] /// public string slot { get; set; } = string.Empty; /// /// 产品SN /// string[1,32] /// public string sn { get; set; } = string.Empty; /// /// 进站状态:PASS/FAIL /// string[1,32] /// MES进站接⼝调⽤状态 /// public string enter_status { get; set; } = "PASS"; /// /// 过站结果 /// string[1,32] /// PASS/FAIL /// public string result { get; set; } = "PASS"; /// /// 作业类型 /// string[1,32] /// PRESSURE_TEST(压测) /// POINT_CHECK(点检) /// OUT_STATION(正常跑料数据) /// public string work_type { get; set; } = "OUT_STATION"; } /// /// 过站明细- 事件方法 /// /// 事件数据;Json /// 自定义事件Id;如:guid /// public static (int, string) Write_PassStationDetail(PassStationDetailRequest request, string dataId = "") { int result = 0; string resultStr = ""; string msg = JsonConvert.SerializeObject(request); byte[] bytes = ToUTF8(msg); // 发送 if (string.IsNullOrEmpty(dataId)) result = Write(PassStationResultId, bytes); else result = WriteWithDataId(PassStationResultId, bytes, dataId); var try1 = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode); if (try1) resultStr = errCode.ToString(); else resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString(); string logPath = GlobalContext.MqttPassResultLogDir + "PassStationDetail" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; FileOperate.NewTxtFile(logPath, "MQTT【过站明细】提交:" + msg + "\r\n==>提交结果:" + resultStr + ""); return (result, resultStr); } /// /// 过站结果- 参数 /// public class PassStationDetailRequest { /// /// 过站唯⼀标识(36位) /// string[1,64] /// 要确保唯⼀性,每次过站时⽣成的ID必须唯⼀。 /// • 对于同⼀次过站⽽⾔,过站明细中的pass_station_id字段值与过站结果中的pass_station_id字段值是⼀样的。 /// • 与mes中的过站明细uuid字段uuidInspection要求⼀致(这两个值需确保是⼀致的,以MES为主,如果关闭MES⽣产,则此项传空字符串) /// public string pass_station_id { get; set; } = Guid.NewGuid().ToString(); /// /// 项⽬编码 /// string[1,32] /// public string sn { get; set; } = string.Empty; /// /// ⼯⼚Id /// string[1,64] /// public string slot { get; set; } = string.Empty; /// /// 测试项序号 /// string[1,32] /// public string test_item_num { get; set; } = string.Empty; /// /// 功能名称 /// string[1,32] /// ⼤类(可以是检测⼤类或加⼯项⼤类),枚举值如下: /// • Machine_加⼯模块,加⼯相关的⼯艺参 /// • Test_测试模块,检测项相关 /// • Fixture_Process,治具信息 /// • Material_Process,物料信息 /// • Tool_Process,软件版本信息 /// • File_Process,⽂件相关信息 /// public string function_name { get; set; } = string.Empty; /// /// 测试项 /// string[1,32] /// public string test_item { get; set; } = string.Empty; /// /// 测试值/输出值 /// string[1,32] /// value(和测试项对应的值,可以是检测值/算法的输出值/⼯艺参数值) /// public string result_val { get; set; } = string.Empty; /// /// 上限值 /// string[1,32] /// public string hi_limit { get; set; } = string.Empty; /// /// 下限值 /// string[1,32] /// public string low_limit { get; set; } = string.Empty; /// /// 测试状态 /// string[1,32] /// PASS/FAIL /// public string status { get; set; } = "PASS"; /// /// 单项测试时间 /// public string test_time { get; set; } = string.Empty; /// /// 错误码 /// public string error_code { get; set; } = string.Empty; /// /// 描述 /// string[1,32] /// 中⽂描述或说明备注信息 /// public string description { get; set; } = string.Empty; } } }