using BZFAStandardLib; using Newtonsoft.Json; using System; using System.Threading.Tasks; namespace MainForm.ClassFile.XiaomiAPI { /// /// 小米 MqttClient类 - API拓展方法 /// 节拍⽇志(OEE) /// • 节拍发⽣时上传 /// 上料开始->上料结束->作业开始->作业结束->下料开始->下料结束 /// public partial class XiaomiMqttClient_Extend : XiaomiMqttClient { /// /// 节拍⽇志(OEE)- 事件Id /// 上料开始->上料结束->作业开始->作业结束->下料开始->下料结束 /// 上料开始:beat_log/business/OEE/station_input_begin /// 上料结束:beat_log/business/OEE/station_input_end /// 作业开始:beat_log/business/OEE/station_work_begin /// 作业结束:beat_log/business/OEE/station_work_end /// 下料开始:beat_log/business/OEE/station_output_begin /// 下料结束:beat_log/business/OEE/station_output_end /// private static string StationInputBeginId { get; set; } = "beat_log/business/OEE/{0}"; /// /// 节拍⽇志(OEE)- 事件方法 /// XiaomiDeviceState /// /// 事件数据;Json /// 自定义事件Id;如:guid /// public static (int, string) Write_StationInputBegin(StationInputBeginRequest request, string deviceCode = "") { int result = 0; string resultStr = ""; string msg = JsonConvert.SerializeObject(request); byte[] bytes = ToUTF8(msg); //request.action = string.Format(StationInputBeginId, request.action); // 发送 if (string.IsNullOrEmpty(deviceCode)) { bool isOk = Task.Run(() => { result = Write(request.action, bytes); }).Wait(10000); if (!isOk) // 无响应 return (-999, "上位机调用Iot的dll无响应[方法名Write]!"); } else { bool isOk = Task.Run(() => { result = WriteWithDeviceCode(request.action, bytes, deviceCode); }).Wait(10000); if (!isOk) // 无响应 return (-999, "上位机调用Iot的dll无响应[方法名WriteWithDeviceCode]!"); } 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.MqttInputBeginDir + "beatType" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; FileOperate.NewTxtFile(logPath, "MQTT【节拍日志】提交:" + msg + "\r\n==>提交结果:" + resultStr + ""); return (result, resultStr); } /// /// 节拍⽇志(OEE)- 参数 /// public class StationInputBeginRequest { /// /// 节拍动作(XiaomiDeviceOEE) /// string[1,64] /// 上料开始:beat_log/business/OEE/station_input_begin /// 上料结束:beat_log/business/OEE/station_input_end /// 作业开始:beat_log/business/OEE/station_work_begin /// 作业结束:beat_log/business/OEE/station_work_end /// 下料开始:beat_log/business/OEE/station_output_begin /// 下料结束:beat_log/business/OEE/station_output_end /// public string action { get; set; } = string.Empty; /// /// 节拍发⽣时间 /// string[1,32] /// 时间,精确到毫秒。如:2022-06-01 14:27:57.283 /// public string beat_tm { get; set; } = string.Empty; /// /// 该动作操作的⽬标对象(SN) /// string[1,64] /// public string action_subject { get; set; } = string.Empty; /// /// ⼤板SN/载具SN /// 若使用虚拟SN,虚拟SN格式为:SN-编号 /// string[1,64] /// public string action_subject_parent { get; set; } = string.Empty; /// /// 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01 /// string[1,32] /// ⼯位 /// public string action_location { get; set; } = string.Empty; /// /// 该动作的物料信息 /// string[1,256] /// 若动作的位置信息有多级,则考虑使⽤"_"分隔,如:"⼯位号_槽位号" /// public string action_material { get; set; } = string.Empty; /// /// 额外信息 /// ⽤于携带额外信息 /// public string extra { get; set; } = string.Empty; /// /// 数据字典中定义的分类层级1 /// string[1,64] /// public string class_level_1 { get; set; } = string.Empty; /// /// 数据字典中定义的分类层级2 /// string[1,64] /// public string class_level_2 { get; set; } = string.Empty; /// /// 数据字典中定义的分类层级3 /// string[1,64] /// public string class_level_3 { get; set; } = string.Empty; } } }