123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using BZFAStandardLib;
- using Newtonsoft.Json;
- using System;
- using System.Threading.Tasks;
- namespace MainForm.ClassFile.XiaomiAPI
- {
- /// <summary>
- /// 小米 MqttClient类 - API拓展方法
- /// 节拍⽇志(OEE)
- /// • 节拍发⽣时上传
- /// 上料开始->上料结束->作业开始->作业结束->下料开始->下料结束
- /// </summary>
- public partial class XiaomiMqttClient_Extend : XiaomiMqttClient
- {
- /// <summary>
- /// 节拍⽇志(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
- /// </summary>
- private static string StationInputBeginId { get; set; } = "beat_log/business/OEE/{0}";
- /// <summary>
- /// 节拍⽇志(OEE)- 事件方法
- /// XiaomiDeviceState
- /// </summary>
- /// <param name="msg">事件数据;Json</param>
- /// <param name="dataId">自定义事件Id;如:guid</param>
- /// <returns></returns>
- 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, DateTime.Now+"===>MQTT【节拍日志】提交:" + msg + "\r\n==>提交结果:" + resultStr + "");
- return (result, resultStr);
- }
- /// <summary>
- /// 节拍⽇志(OEE)- 参数
- /// </summary>
- public class StationInputBeginRequest
- {
- /// <summary>
- /// 节拍动作(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
- /// </summary>
- public string action { get; set; } = string.Empty;
- /// <summary>
- /// 节拍发⽣时间
- /// string[1,32]
- /// 时间,精确到毫秒。如:2022-06-01 14:27:57.283
- /// </summary>
- public string beat_tm { get; set; } = string.Empty;
- /// <summary>
- /// 该动作操作的⽬标对象(SN)
- /// string[1,64]
- /// </summary>
- public string action_subject { get; set; } = string.Empty;
- /// <summary>
- /// ⼤板SN/载具SN
- /// 若使用虚拟SN,虚拟SN格式为:SN-编号
- /// string[1,64]
- /// </summary>
- public string action_subject_parent { get; set; } = string.Empty;
- /// <summary>
- /// 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
- /// string[1,32]
- /// ⼯位
- /// </summary>
- public string action_location { get; set; } = string.Empty;
- /// <summary>
- /// 该动作的物料信息
- /// string[1,256]
- /// 若动作的位置信息有多级,则考虑使⽤"_"分隔,如:"⼯位号_槽位号"
- /// </summary>
- public string action_material { get; set; } = string.Empty;
- /// <summary>
- /// 额外信息
- /// ⽤于携带额外信息
- /// </summary>
- public string extra { get; set; } = string.Empty;
- /// <summary>
- /// 数据字典中定义的分类层级1
- /// string[1,64]
- /// </summary>
- public string class_level_1 { get; set; } = string.Empty;
- /// <summary>
- /// 数据字典中定义的分类层级2
- /// string[1,64]
- /// </summary>
- public string class_level_2 { get; set; } = string.Empty;
- /// <summary>
- /// 数据字典中定义的分类层级3
- /// string[1,64]
- /// </summary>
- public string class_level_3 { get; set; } = string.Empty;
- }
- }
- }
|