Browse Source

故障数据上传iot

WIN-GH9CEESPLTB\Administrator 4 months ago
parent
commit
795cb6f677

+ 7 - 3
MainForm/ClassFile/ProjectClass/GlobalContext.cs

@@ -160,7 +160,9 @@ namespace MainForm
         public static bool MESIsConnect;  // MES是否正常连接
         public static string MESLaserLPath;   // 三点激光数据本地存放地址
         public static string MESLaserRPath;   // 三点激光数据本地存放地址
-
+        public static string UpFileUrl;  // 文档库地址
+        public static string UpFilePath;  // 本地文件路径
+        public static bool IsSendUpFile;    // 启用上传文件
 
         // IOT - MQTT
         public static bool IsUseIot;  // 是否 启用IOT
@@ -358,8 +360,6 @@ namespace MainForm
                 AtlasAddressRight = IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressRight", "");
                 AtlasAddressPort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressPort", ""));
 
-
-
                 QrCodeTCPAddress1 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress1", "127.0.0.1");
                 QrCodeTCPPort1 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort1", "0"));
                 QrCodeTCPAddress2 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress2", "127.0.0.1");
@@ -380,6 +380,10 @@ namespace MainForm
                 StationInMESUrl = string.Format(StationInMESUrl, ServerHost);
                 StationOutMESUrl = IniFile.INIGetStringValue(FilePath, "MES", "StationOutMESUrl", "");
                 StationOutMESUrl = string.Format(StationOutMESUrl, ServerHost);
+                UpFileUrl = IniFile.INIGetStringValue(FilePath, "MES", "UpFileUrl", "");
+                UpFilePath = IniFile.INIGetStringValue(FilePath, "MES", "UpFilePath", "");
+                IsSendUpFile = bool.Parse(IniFile.INIGetStringValue(FilePath, "MES", "IsSendUpFile", ConstIsSend));
+
                 if (ServerHost.Contains(":"))
                 {
                     string[] mesServers = ServerHost.Split(':');

+ 1 - 1
MainForm/ClassFile/XiaomiAPI_IOT/Extend/XiaomiMqttClient_DeviceStateData.cs

@@ -45,7 +45,7 @@ namespace MainForm.ClassFile.XiaomiAPI
             else
                 resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString();
             string logPath = GlobalContext.MqttDeviceStateDir + "macState" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
-            FileOperate.NewTxtFile(logPath, "MQTT【设备状态】提交:"+ msg + "\r\n==>提交结果:" + resultStr+ "");
+            FileOperate.NewTxtFile(logPath, "【设备状态】MQTT提交:" + msg + "\r\n==>提交结果:" + resultStr+ "");
             return (result, resultStr);
         }
 

+ 15 - 6
MainForm/ClassFile/XiaomiAPI_IOT/XiaomiMqttClient.cs

@@ -68,7 +68,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <param name="addr">IP地址</param>
         /// <param name="port">端口</param>
         /// <returns></returns>
-        public static int OpenWithMqttServer(string addr, int port, string mqttServerPath, string mqttName)
+        public static (int, string) OpenWithMqttServer(string addr, int port, string mqttServerPath, string mqttName)
         {
             // 检测MqttServer有没有开启,未开启时启动MqttServer
             if (!ProcessHelper.CheckProcessActivityByProcessName(mqttName))  // 进程名QIMITest.exe
@@ -81,9 +81,13 @@ namespace MainForm.ClassFile.XiaomiAPI
                     throw new Exception($"未找到{mqttServerPath}文件,请文件检查路径!");
                 }
             }
-            int result = Open(addr, port);
+            int result = -999;
+            bool isOk = Task.Run(() => { result = Open(addr, port); }).Wait(10000);
+            if (!isOk)  // 无响应
+                return (-999, "上位机调用Iot的dll无响应[方法名Open]!");
+
             IsOpen = result == 0;
-            return result;
+            return (result, result.ToString());
         }
 
 
@@ -110,11 +114,16 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// </summary>
         /// <param name="parameterJson">参数</param>
         /// <returns></returns>
-        public static int ParameterConfig(XiaomiMqttLoginFunAndParam parameter)
+        public static (int, string) ParameterConfig(XiaomiMqttLoginFunAndParam parameter)
         {
             string funAndParamJson = JsonConvert.SerializeObject(parameter);
-            int result = ParameterConfig(funAndParamJson);
-            return result;
+
+            int result = -999;
+            bool isOk = Task.Run(() => { result = ParameterConfig(funAndParamJson); }).Wait(10000);
+            if (!isOk)  // 无响应
+                return (-999, "上位机调用Iot的dll无响应[方法名ParameterConfig]!");
+
+            return (result, result.ToString());
         }
 
 

+ 476 - 0
MainForm/ClassFile/XiaomiAPI_MES/XiaomiMESHttp_UpLoadFile.cs

@@ -0,0 +1,476 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Security.Cryptography;
+using System.Security.Policy;
+using System.Text;
+using System.Threading.Tasks;
+using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
+using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
+
+namespace MainForm.ClassFile.XiaomiAPI_MES
+{
+    /// <summary>
+    /// 小米MES - 进站接⼝
+    /// 接口地址:
+    /// 接口方法:UnitConfirmDataSetIn
+    /// </summary>
+    public class XiaomiMESHttp_UpLoadFile : XiaomiMESHttp_X5
+    {
+        #region 变量
+        /// <summary>
+        /// 接口地址
+        /// </summary>
+        protected new static string UpFileUrl { set; get; } = GlobalContext.UpFileUrl;
+
+        /// <summary>
+        /// 接口方法
+        /// </summary>
+        protected new static string Method { set; get; } = "UploadMqtt";
+        #endregion 变量
+        /// <summary>
+        /// 文件上传到 MES 系统
+        /// </summary>
+        /// <param name="wJPath">文件路径</param>
+        /// <param name="fileUpload_X5">文件上传参数</param>
+        /// <param name="fileMqttPayload">MQTT 负载参数</param>
+        /// <returns>(状态码, 结果信息)</returns>
+        public static async Task<(int, string)> FileUoladToMes(string wJPath, FileUpload_X5 fileUpload_X5, FileMqttPayload fileMqttPayload)
+        {
+            try
+            {
+                // 基础参数
+                string url = "http://cm.pre.mi.com/file/x5/file/upload/mqtt";
+                url = "http://im.pre.mi.com/file/x5/file/upload/mqtt";
+                //这个之后要加到配置文件config中
+                string appid = "Auto-Soft";
+                //这个之后要加到配置文件config中
+                string appkey = "5984710e-bb38-4806-b94d-7a9a727e3880";
+                string method = "UploadMqtt";
+
+                // 检查文件是否存在
+                if (!System.IO.File.Exists(wJPath))
+                {
+                    return (-1, "文件不存在");
+                }
+                // 获取文件信息
+                FileInfo file = new FileInfo(wJPath);
+
+                // 构造 body
+                string body = BuildBody(fileUpload_X5, fileMqttPayload);
+
+                // 计算 sign
+                string sign = GetSign(appid + body + appkey); // MD5 加密
+
+                // 构造 header
+                Dictionary<string, string> header = BuildHeader(url, appid, method, sign);
+
+                // 构造 data 参数
+                Dictionary<string, object> dataParam = new Dictionary<string, object>
+                {
+                    { "header", header },
+                    { "body", body }
+                };
+                string jsonStr = JsonConvert.SerializeObject(dataParam);
+                // 将 data 参数序列化为 Base64 编码的字符串
+                string data = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonStr));
+
+                // 调用上传方法
+                var uploadResult = await UploadFile(url, data, wJPath);
+
+                // 判断上传结果
+                if (!string.IsNullOrEmpty(uploadResult) && !uploadResult.StartsWith("异常:") && !uploadResult.StartsWith("HTTP 错误:"))
+                {
+                    //删除文件
+                    (bool, string) newResult = DeleteFile(wJPath);
+                    if (!newResult.Item1)
+                    {
+                        return (0, fileUpload_X5.name+newResult.Item2);
+
+                    }
+                    return (0, fileUpload_X5.name+"文件上传成功");
+                }
+                else
+                {
+                    return (-2, fileUpload_X5.name+$"文件上传失败: {uploadResult}");
+                }
+            }
+            catch (Exception ex)
+            {
+                return (-3, fileUpload_X5.name+$"发生异常: {ex.Message}");
+            }
+        }
+
+        /// <summary>
+        /// 将文件复制到目标文件夹,并删除源文件
+        /// </summary>
+        /// <param name="sourceFilePath">源文件路径</param>
+        /// <param name="destinationFolderPath">目标文件夹路径</param>
+        static string CopyAndDeleteFile(string sourceFilePath, string destinationFolderPath)
+        {
+            try
+            {
+                // 检查目标文件夹是否存在,如果不存在则创建
+                if (!Directory.Exists(destinationFolderPath))
+                {
+                    Directory.CreateDirectory(destinationFolderPath);
+                }
+
+                // 构建目标文件的完整路径
+                string fileName = Path.GetFileName(sourceFilePath); // 获取源文件的文件名
+                string destinationFilePath = Path.Combine(destinationFolderPath, fileName);
+
+                // 如果目标文件已存在,则删除已有文件以避免冲突
+                if (File.Exists(destinationFilePath))
+                {
+                    File.Delete(destinationFilePath); // 删除已有文件
+                }
+
+                // 检查文件是否准备好
+                if (!IsFileReady(sourceFilePath))
+                {
+                    throw new IOException($"文件 {sourceFilePath} 正被其他进程占用,无法进行复制和删除操作。");
+                }
+
+                // 复制文件到目标文件夹
+                File.Copy(sourceFilePath, destinationFilePath);
+
+                // 删除源文件
+                File.Delete(sourceFilePath);
+
+                Console.WriteLine($"文件已从 {sourceFilePath} 成功复制到 {destinationFilePath} 并删除原文件。");
+
+                // 返回目标文件路径
+                return destinationFilePath;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"文件转移失败: {ex.Message}");
+                return null; // 或者返回空字符串,根据需求决定
+            }
+        }
+
+        /// <summary>
+        /// 删除文件
+        /// </summary>
+        /// <param name="sourceFilePath">文件路径</param>
+        static (bool,string) DeleteFile(string sourceFilePath)
+        {
+            try
+            {
+                // 构建目标文件的完整路径
+                string fileName = Path.GetFileName(sourceFilePath); // 获取源文件的文件名
+
+                // 检查文件是否准备好
+                if (!IsFileReady(sourceFilePath))
+                {
+                    throw new IOException($"文件 {sourceFilePath} 正被其他进程占用,无法进行复制和删除操作。");
+                }
+                // 删除源文件
+                File.Delete(sourceFilePath);
+
+                return (true, "文件删除成功!");
+            }
+            catch (Exception ex)
+            {
+                return (false, "文件删除失败!"+ex.Message);
+            }
+        }
+        public static bool IsFileReady(string filePath)
+        {
+            try
+            {
+                using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
+                {
+                    stream.Close();
+                }
+                return true;
+            }
+            catch (IOException)
+            {
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 文件MD5加密
+        /// </summary>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public static string GetMD5Hex(FileInfo file)
+        {
+            using (MD5 md5 = MD5.Create())
+            {
+                using (FileStream stream = file.OpenRead())
+                {
+                    byte[] hashBytes = md5.ComputeHash(stream);
+                    StringBuilder sb = new StringBuilder();
+                    for (int i = 0; i < hashBytes.Length; i++)
+                    {
+                        sb.Append(hashBytes[i].ToString("x2"));
+                    }
+                    return sb.ToString();
+                }
+            }
+        }
+        /// <summary>
+        /// 数据pin接
+        /// </summary>
+        /// <param name="file"></param>
+        /// <param name="fileMd5Hex"></param>
+        /// <returns></returns>
+        public static string BuildBody(FileUpload_X5 file, FileMqttPayload payload)
+        {
+            Dictionary<string, object> fileMetadata = new Dictionary<string, object>();
+            Dictionary<string, string> mqttPayLoad = new Dictionary<string, string>();
+            mqttPayLoad.Add("factory", payload.factory);
+            mqttPayLoad.Add("project_name", payload.project_name);
+            mqttPayLoad.Add("product_mode", payload.product_mode);
+            mqttPayLoad.Add("line_no", payload.line_no);
+            mqttPayLoad.Add("work_station_no", payload.work_station_no);
+            mqttPayLoad.Add("equipment_no", payload.equipment_no);
+            mqttPayLoad.Add("station_no", payload.station_no);
+            mqttPayLoad.Add("file_id", payload.file_id);
+            mqttPayLoad.Add("file_name", payload.file_name);
+            mqttPayLoad.Add("sn", payload.sn);
+            mqttPayLoad.Add("opt_time", payload.opt_time);
+            mqttPayLoad.Add("file_type", payload.file_type);
+            mqttPayLoad.Add("file_category", payload.file_category);
+            mqttPayLoad.Add("tag", payload.tag);
+            mqttPayLoad.Add("reference_info", Newtonsoft.Json.JsonConvert.SerializeObject(new object[] { new { pass_station_id = payload.pass_station_id } }));
+
+
+            fileMetadata.Add("bucket", file.bucket);
+            fileMetadata.Add("name", file.name);
+            fileMetadata.Add("uuid", file.uuid);
+            fileMetadata.Add("md5", file.md5);
+            fileMetadata.Add("uploadCloud", file.uploadCloud);
+            fileMetadata.Add("informMqtt", file.informMqtt);
+            fileMetadata.Add("mqttPayload", Newtonsoft.Json.JsonConvert.SerializeObject(mqttPayLoad));
+            string body = Newtonsoft.Json.JsonConvert.SerializeObject(fileMetadata);
+            return body;
+        }
+        /// <summary>
+        /// 数据头拼接
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="appid"></param>
+        /// <param name="method"></param>
+        /// <param name="sign"></param>
+        /// <returns></returns>
+        public static Dictionary<string, string> BuildHeader(string url, string appid, string method, string sign)
+        {
+            Dictionary<string, string> header = new Dictionary<string, string>();
+            header.Add("appid", appid);
+            header.Add("method", method);
+            header.Add("sign", sign);
+            header.Add("url", url);
+            return header;
+        }
+
+        public static string GetGuid()
+        {
+            return (System.Guid.NewGuid().ToString("N"));
+        }
+
+        /// <summary>
+        /// 异步文件上传
+        /// </summary>
+        /// <param name="url">上传地址</param>
+        /// <param name="file">文件路径</param>
+        /// <param name="data">上传的数据</param>
+        /// <returns>返回上传结果</returns>
+        public static async Task<string> UploadFile(string url, string data, string imageFile)
+        {
+            using (var httpClient = new HttpClient())
+            {
+                var formData = new MultipartFormDataContent();
+
+                try
+                {
+                    // 获取文件名
+                    string filename = Path.GetFileName(imageFile);
+
+                    // 创建 StreamContent 对象
+                    using (var fileStream = File.OpenRead(imageFile))
+                    using (var streamContent = new StreamContent(fileStream))
+                    {
+                        // 设置 Content-Type(根据实际文件类型设置)
+                        streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
+
+                        // 添加文件到 formData
+                        formData.Add(streamContent, "file", filename);
+
+                        // 添加其他数据到 formData
+                        formData.Add(new StringContent(data), "data");
+
+                        // 发送 POST 请求
+                        var response = await httpClient.PostAsync(url, formData);
+                        if (response.IsSuccessStatusCode)
+                        {
+                            // 读取响应内容
+                            string result = await response.Content.ReadAsStringAsync();
+
+                            // 删除图片文件
+                            try
+                            {
+                                File.Delete(imageFile);
+                            }
+                            catch (Exception ex)
+                            {
+                                return $"上传成功,删除图片文件时出错: {ex.Message}";
+                            }
+
+                            return result; // 返回上传成功的响应
+                        }
+                        else
+                        {
+                            return $"HTTP 错误: {response.StatusCode}";
+                        }
+                    }
+                }
+                catch (Exception e)
+                {
+                    return $"异常: {e.Message}";
+                }
+            }
+        }
+
+        /// <summary>
+        /// MD5加密
+        /// </summary>
+        /// <param name="data"></param>
+        /// <returns></returns>
+        public static string GetSign(string data)
+        {
+            // 实例化一个md5对像
+            MD5 md5 = MD5.Create();
+            // MD5加密
+            byte[] encodingMd5Data = md5.ComputeHash(Encoding.UTF8.GetBytes(data));
+            // 生成签名字段
+            string sign = "";
+            for (int i = 0; i < encodingMd5Data.Length; i++)
+            {
+                // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
+                sign += encodingMd5Data[i].ToString("X2");
+            }
+            return sign;
+        }
+
+
+        public class FileUpload_X5
+        {
+            /// <summary>
+            /// ⽂件所属包
+            /// 必填
+            /*
+             ${file_category}/${file_type}/${项⽬号}/${⽣
+                产阶段}/${运⾏模式}/${过站结果}/${装备编
+                码}/${sn}/${pass_station_id}
+                • 其中file_category的枚举值为:
+                ◦ IMAGE
+                ◦ TEXT
+                • 若对应字段的值为空,则使⽤默认值
+                UNKNOWN
+                注意:⾸位不能出现/,否则会出现路径错误
+                问题。
+                如:
+                正确⽰例
+                IMAGE/IMAGE/N3/debug/online/PASS/MPA-0001/P320N000006B/382f55e9-c2bb 
+             */
+            /// </summary>
+            public string bucket { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件名
+            /// </summary>
+            public string name { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件唯一标识符
+            /// </summary>
+            public string uuid { get; set; } = string.Empty;
+            /// <summary>
+            /// md5 传空
+            /// </summary>
+            public string md5 { get; set; } = string.Empty;
+            /// <summary>
+            /// 是否上云 默认true
+            /// </summary>
+            public Boolean uploadCloud { get; set; }
+            /// <summary>
+            /// 是否通知Mqtt 默认true
+            /// </summary>
+            public Boolean informMqtt { get; set; }
+
+        }
+
+        public class FileMqttPayload
+        {
+            /// <summary>
+            /// 工厂编码
+            /// </summary>
+            public string factory { get; set; } = string.Empty;
+            /// <summary>
+            /// 项目号
+            /// </summary>
+            public string project_name { get; set; } = string.Empty;
+            /// <summary>
+            /// 生产阶段
+            /// </summary>
+            public string product_mode { get; set; } = string.Empty;
+            /// <summary>
+            /// 线体
+            /// </summary>
+            public string line_no { get; set; } = string.Empty;
+            /// <summary>
+            /// 工站
+            /// </summary>
+            public string work_station_no { get; set; } = string.Empty;
+            /// <summary>
+            /// 装备
+            /// </summary>
+            public string equipment_no { get; set; } = string.Empty;
+            /// <summary>
+            /// 工位
+            /// </summary>
+            public string station_no { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件ID
+            /// </summary>
+            public string file_id { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件名
+            /// </summary>
+            public string file_name { get; set; } = string.Empty;
+            /// <summary>
+            /// 产品sn    
+            /// </summary>
+            public string sn { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件生成时间
+            /// </summary>
+            public string opt_time { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件类型
+            /// </summary>
+            public string file_type { get; set; } = string.Empty;
+            /// <summary>
+            /// 文件类别
+            /// </summary>
+            public string file_category { get; set; } = string.Empty;
+            /// <summary>
+            /// 自定义标签信息
+            /// </summary>
+            public string tag { get; set; } = string.Empty;
+            /// <summary>
+            /// 关联业务信息
+            /// </summary>
+            public string pass_station_id { get; set; } = string.Empty;
+        }
+
+    }
+
+
+}

+ 287 - 83
MainForm/FaForm/Form_Home.cs

@@ -41,6 +41,8 @@ using BZFAStandardLib;
 using MainForm.ClassFile;
 using NPOI.SS.Formula.Functions;
 using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
+using System.Net.Http;
+using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
 
 /*
  * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
@@ -106,6 +108,7 @@ namespace MainForm
         /// 设备报警数据
         /// </summary>
         uint[] _FaultDatas;
+        uint[] _FaultDatas_Old = { };
 
         // 软件状态
         private bool IsRun = true;
@@ -338,9 +341,8 @@ namespace MainForm
                         string addr = GlobalContext.MQTTServerHost;
                         int port = GlobalContext.MQTTServerPort;
                         //生产环境需要修改
-                        int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
-                            GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
-                        XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
+                        (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
+                        XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
                         if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
                         {
                             picIot.Image = imageListState.Images[1];
@@ -421,9 +423,9 @@ namespace MainForm
 
                             param.parameter.equipment.project = GlobalContext.Project_Code;
                             param.parameter.equipment.productMode = "debug";
-                            // 
+                           
                             param.parameter.other.logLevel = 0;
-                            param.parameter.other.LogPath = GlobalContext.WorkLogDir;
+                            param.parameter.other.LogPath = GlobalContext.MqttLogDir;
                             XiaomiMqttClient_Extend.ParameterConfig(param);
                         }
                         else
@@ -761,8 +763,6 @@ namespace MainForm
         private string _DeviceStates2 = "未知状态";
         private string _DeviceStates_Old2 = "未知状态";
 
-        private object dicAlarms_Cur_PLC1_Old;
-
         /// <summary>
         /// 获取设备报警数据与获取设备运行信息
         /// </summary>
@@ -775,86 +775,24 @@ namespace MainForm
             {
                 try
                 {
-                    DateTime dtNow = DateTime.Now;
-
                     #region 报警数据
                     try
                     {
-                        List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>();  // 同步到报警页面用传输载体
-
-                        _FaultDatas=new uint[] { 4,0,0,10};
-
-
-                        bool isNeedUpdUI = false;  // 是否需要更新历史报警UI
-                        //解析报警信息
-                        List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
+                        //_FaultDatas = new uint[] { 4, 0, 30, 10 };
                         if (_FaultDatas.Length>0)
                         {
-                            string binaryString = "";
-                            for (int i = 0; i <= _FaultDatas.Length-1; i++)
-                            {
-                                var num = 0;
-                                if (_FaultDatas[i]>0)
-                                {
-                                    binaryString = Convert.ToString(_FaultDatas[i], 2);
-                                    for (int j = binaryString.Length - 1; j >= 0; j--)
-                                    {
-                                        num++;
-                                        char s = binaryString[j];
-                                        if (binaryString[j]=='1')
-                                        {
-                                            AlarmIndexList.Add((i, num-1));
-                                        }
-                                    }
-                                }
-                            }
+                            ReadPLCAlarmToIot(_FaultDatas, stationNameStr);
                         }
-                        
-                        // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
-                        var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
-                        int AlarmsLine = 0;//记录总循环行数
-                        foreach ((int index, int row) in AlarmIndexList)
-                        {
-                            var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
-                            for (int i = 0; i < tempDic.Count -1; i++)  // 读取
-                            {
-                                if (tempDic[i].group_index == index && i == row)
-                                {
-                                    dicAlarms_Cur_PLC1[AlarmsLine].报警数据 = new AlarmData()
-                                    {
-                                        GUID = Guid.NewGuid().ToString(),
-                                        LineName = GlobalContext.IsUseStationName,       // 工站
-                                        PlcStation = tempDic[i].plcName,   // 工站全称;[S1]
-                                        Type1 = tempDic[i].type1,  // 故障层级1
-                                        Type2 = tempDic[i].type2,  // 故障层级2
-                                        Type3 = tempDic[i].type3,  // 故障层级3
-                                        Type4 = tempDic[i].type4,  // 故障层级4
-                                        AlarmType = tempDic[i].fault_code,    // 报警类型
-                                        AlarmDesc = tempDic[i].fault_name,    // 报警内容
-                                        StartTime = dtNow  // 开始时间
-                                    };
-                                }
-                                AlarmsLine += 1;
-                            }
-
-
+                        else
+                        {
+                            AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!" );
                         }
 
-
-                        //FaultLogRequest request = new FaultLogRequest();
-                        //request.station = mesStation;        // 工位
-                        //request.fault_name = xmFaultName;    // 故障名称(同数据字典中的事件名称)
-                        //request.fault_code = xmFaultCode2;   // 故障编码(A,B,C,D,E)
-                        //request.fault_cmpnt = xmFaultCmpnt;  // 故障部件
-                        //request.fault_desc = xmFaultDesc;    // 故障描述
-                        //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 故障发生时间 2022-06-01 14:27:57.283
-                        //                                                                      // 上传
-                        //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
                     }
                     catch (Exception ex)
                     {
                         string str = ex.StackTrace;
-                        AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
+                        AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
                     }
                     #endregion 报警数据
 
@@ -913,11 +851,11 @@ namespace MainForm
                                     {
                                         _DeviceStates_Old = _DeviceStates;
                                         AddMessage_Station(stationNameStr, LogType.Info,
-                                            stationNameStr + $"_上传设备状态到Iot成功!");
+                                            "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
                                     }
                                     else
                                         AddMessage_Station(stationNameStr, LogType.Info,
-                                            stationNameStr +
+                                            "【设备状态】"+stationNameStr +
                                             $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
                                 }
 
@@ -968,12 +906,12 @@ namespace MainForm
                                         {
                                             _DeviceStates_Old2 = _DeviceStates2;
                                             AddMessage_Station(stationNameStr, LogType.Info,
-                                                stationNameStr + $"_上传设备状态到Iot成功!");
+                                                "【设备状态】" + stationNameStr + $"_上传Iot成功!");
                                         }
                                         else
                                             AddMessage_Station(stationNameStr, LogType.Info,
-                                                stationNameStr +
-                                                $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
+                                                "【设备状态】" + stationNameStr +
+                                                $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
                                     }
                                 }
 
@@ -2202,6 +2140,137 @@ namespace MainForm
             }
         }
 
+        /// <summary>
+        /// 上传文件
+        /// </summary>
+        /// <param name="BarcodeSet_t">条码集合</param>
+        /// <param name="stationCode">工站编号</param>
+        /// <param name="stationName">工站名称</param>
+        /// <param name="path">文件路径</param>
+        public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode, string stationName,string path)
+        {
+            string sql, filename = "";
+            Guid guid;
+            int result = 0;
+            var formData = new MultipartFormDataContent();
+
+            // 获取所有图片文件
+            List<string> imageFiles = GetAllImageFiles(path);
+            try
+            {
+                if (imageFiles.Count>0)
+                {
+                    foreach (string imageFile in imageFiles)
+                    {
+                        guid = Guid.NewGuid();
+                        filename = Path.GetFileName(imageFile);
+                        sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
+                            "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
+                            , stationCode
+                            , stationName
+                            , BarcodeSet.strCarrierBarcode
+                            , BarcodeSet.strProductBarcode
+                            , "/mesCommToPC/pic/left"
+                            , filename
+                            , ""
+                            , guid.ToString()
+                            , ""
+                            , 0
+                            , ""
+                            , DateTime.Now
+                            );
+                        string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
+
+                        FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
+                        string bucket = string.Empty;
+                        //bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
+                        bucket = "/mesCommToPC/pic/left";
+                        fileUpload_X5.bucket = bucket;
+                        fileUpload_X5.name = imageFile;
+                        fileUpload_X5.md5 = "";
+                        fileUpload_X5.uploadCloud = true;
+                        fileUpload_X5.informMqtt = true;
+
+                        FileMqttPayload fileMqttPayload = new FileMqttPayload();
+                        //fileMqttPayload.factory = "";
+                        //fileMqttPayload.project_name = "";
+                        //fileMqttPayload.product_mode = "";
+                        //fileMqttPayload.line_no = "";
+                        //fileMqttPayload.work_station_no = "";
+                        //fileMqttPayload.equipment_no = "";
+                        //fileMqttPayload.station_no = "";
+                        //fileMqttPayload.file_id = "";
+                        //fileMqttPayload.file_name = "";
+                        //fileMqttPayload.sn = "";
+                        //fileMqttPayload.opt_time = "";
+                        //fileMqttPayload.file_type = "";
+                        //fileMqttPayload.file_category = "";
+                        //fileMqttPayload.tag = "";
+                        //fileMqttPayload.pass_station_id = "";
+
+                        //FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
+                        //FileMqttPayload fileMqttPayload = new FileMqttPayload();
+                        //fileUpload_X5.bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
+                        //fileUpload_X5.name = "test";
+                        //fileUpload_X5.md5 = "";
+                        //fileUpload_X5.uploadCloud = true;
+                        //fileUpload_X5.informMqtt = true;
+
+                        var fileresult = XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
+                        if (fileresult.Result.Item1 == 0)
+                        {
+                            return (1, fileresult.Result.Item2);
+                        }
+
+                        sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
+                        string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
+                        return fileresult.Result;
+                    }
+                    return (1, "程序错误!");
+                }
+                else
+                {
+                    return (1,"文件不存在!");
+                }
+            }
+            catch (Exception e)
+            {
+                return (1, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" + e.Message);
+                //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
+            }
+
+        }
+
+        /// <summary>
+        /// 获取路径下的所有图片
+        /// </summary>
+        /// <param name="directoryPath"></param>
+        /// <returns></returns>
+        public List<string> GetAllImageFiles(string directoryPath)
+        {
+            var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
+            var imageFiles = new List<string>();
+
+            try
+            {
+                // 遍历目录及子目录中的所有文件
+                foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
+                {
+                    // 获取文件扩展名并检查是否为图片格式
+                    string extension = Path.GetExtension(file);
+                    if (imageExtensions.Contains(extension))
+                    {
+                        imageFiles.Add(file);
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
+            }
+            return imageFiles;
+        }
+
         /// <summary>
         /// 实例化报警字典
         /// </summary>
@@ -2354,6 +2423,143 @@ namespace MainForm
             return (true, "报警字典表初始化成功!");
         }
 
+        private async void ReadPLCAlarmToIot(uint[] FaultData,string stationNameStr)
+        {
+            DateTime dtNow = DateTime.Now;
+            try
+            {
+                List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>();  // 同步到报警页面用传输载体
+                List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
+
+                AlarmData alarmData = new AlarmData();
+
+                bool isNeedUpdUI = false;  // 是否需要更新历史报警UI
+                bool isNoAlarm = false;//是否有报警
+                string binaryString = "";
+                bool isNoNewAlarm = false;//是否有新的报警
+
+
+                if (FaultData.Length > 0)
+                {
+
+                }
+                foreach (var item in FaultData)
+                {
+                    isNoAlarm = item > 0 ? true : false;
+                }
+                if (!FaultData.SequenceEqual(_FaultDatas_Old))
+                {
+                    isNoNewAlarm = true;
+                    isNeedUpdUI = true;
+                }
+                if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
+                {
+                    //解析报警信息,分析当前报警在字典中的定位
+                    for (int i = 0; i <= FaultData.Length - 1; i++)
+                    {
+                        var num = 0;
+                        if (FaultData[i] > 0)
+                        {
+                            //转换二进制
+                            binaryString = Convert.ToString(FaultData[i], 2);
+                            for (int j = binaryString.Length - 1; j >= 0; j--)
+                            {
+                                num++;
+                                char s = binaryString[j];
+                                if (binaryString[j] == '1')
+                                {
+                                    //记录1的位置
+                                    AlarmIndexList.Add((i, num - 1));
+                                }
+                            }
+                        }
+                    }
+                    // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
+                    var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
+                    foreach ((int index, int row) in AlarmIndexList)
+                    {
+                        var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
+                        for (int i = 0; i < tempDic.Count - 1; i++)  // 读取
+                        {
+                            //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
+                            if (tempDic[i].group_index == index && i == row)
+                            {
+                                dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 = new AlarmData()
+                                {
+                                    GUID = Guid.NewGuid().ToString(),
+                                    LineName = GlobalContext.IsUseStationName,       // 工站
+                                    PlcStation = tempDic[i].plcName,   // 工站全称;[S1]
+                                    Type1 = tempDic[i].type1,  // 故障层级1
+                                    Type2 = tempDic[i].type2,  // 故障层级2
+                                    Type3 = tempDic[i].type3,  // 故障层级3
+                                    Type4 = tempDic[i].type4,  // 故障层级4
+                                    AlarmType = tempDic[i].fault_code,    // 报警类型
+                                    AlarmDesc = tempDic[i].fault_name,    // 报警内容
+                                    StartTime = dtNow  // 开始时间
+                                };
+                                // 传输到页面
+                                deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
+                                {
+                                    线体名称 = tempDic[i].plcName,
+                                    报警类型 = tempDic[i].fault_code,
+                                    报警内容 = tempDic[i].fault_name,
+                                    开始时间 = dtNow
+                                });
+                                // 新增到数据库
+                                //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
+                                //SaveAlarmDataByDB(stationNameStr, data1, false);
+                                //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
+                            }
+                        }
+                    }
+                    //筛选含报警数据的字典
+                    var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
+                    if (dicAlarms_Cur.Count > 0)
+                    {
+                        foreach (var item in dicAlarms_Cur)
+                        {
+                            //上传
+                            SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
+                        }
+                    }
+
+                    // 有新报警则更新
+                    if (isNeedUpdUI)
+                        // UI展示 - 展示到设备状态页
+                        await Task.Run(() =>
+                        {
+                            try
+                            {
+                                if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
+                                {
+                                    Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs);  // 报警UI 更新
+                                    if (Form_Main.formDevAlarm.Visible)
+                                        Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H();  //  历史报警UI 更新
+                                }
+                            }
+                            catch { }
+                        });
+                    _FaultDatas_Old = FaultData.ToArray();
+                }
+
+
+                //FaultLogRequest request = new FaultLogRequest();
+                //request.station = mesStation;        // 工位
+                //request.fault_name = xmFaultName;    // 故障名称(同数据字典中的事件名称)
+                //request.fault_code = xmFaultCode2;   // 故障编码(A,B,C,D,E)
+                //request.fault_cmpnt = xmFaultCmpnt;  // 故障部件
+                //request.fault_desc = xmFaultDesc;    // 故障描述
+                //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 故障发生时间 2022-06-01 14:27:57.283
+                //                                                                      // 上传
+                //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
+            }
+            catch (Exception ex)
+            {
+                string str = ex.StackTrace;
+                AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
+            }
+        }
+
         #endregion
 
         #region S1
@@ -13460,9 +13666,7 @@ namespace MainForm
         /// <param name="snNumber">产品数字SN</param>
         public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
         {
-            if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
-                  && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
-                ))
+            if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
             {
                 AddMessage(logType, message); // 首页展示+日志记录
             }

+ 32 - 9
MainForm/FaForm/Form_Home_SaveData.cs

@@ -794,7 +794,7 @@ namespace MainForm
                 result = 4;
                 string str = ex.StackTrace;
                 msg = $"错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1);
-                OnMessage(LogType.Error, stationNameStr + $"_PLC上传Iot设备状态数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
+                OnMessage(LogType.Error, "【设备状态】"+stationNameStr + $"_PLC上传Iot设备状态数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
             }
             return (result, msg);
         }
@@ -835,18 +835,41 @@ namespace MainForm
         /// <param name="isUpd">更新而不是新增</param>
         public void SaveAlarmDataByDB(string stationNameStr, AlarmData alarmData, bool isUpd)
         {
-            if (isUpd)
+            try
             {
-                string sql = alarmData.ToStringUpdate();
-                SQLHelper_New.ExecuteSQL(sql, null);
-                AddMessage_Station(stationNameStr, LogType.Info, "消除报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]完毕!");
+                if (isUpd)
+                {
+                    string sql = alarmData.ToStringUpdate();
+                    SQLHelper_New.ExecuteSQL(sql, null);
+                    //OnMessage(LogType.Info, "【报警日志】消除报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]完毕!");
+                }
+                else
+                {
+                    string sql = alarmData.ToStringInsert();
+                    SQLHelper_New.ExecuteSQL(sql, null);
+                    //OnMessage(LogType.Info, "【报警日志】发生了报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]!");
+
+                    FaultLogRequest request = new FaultLogRequest();
+                    request.station = alarmData.LineName;   // ⼯位
+                    request.fault_name = alarmData.AlarmDesc;    // 故障名称(同数据字典中的事件名称)
+                    request.fault_code = alarmData.AlarmType;   // 故障编码(A,B,C,D,E)
+                    request.fault_cmpnt = alarmData.Type4;  // 故障部件
+                    request.fault_desc = alarmData.AlarmDesc;    // 故障描述
+                    request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 故障发⽣时间 2022-06-01 14:27:57.283
+                                                                                          // 上传
+                    (int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request);
+                    if (iotResult.Item1 == 0)
+                        AddMessage_Station(stationNameStr, LogType.Info, "【报警日志】[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]上传IOT成功!");
+                    else
+                        AddMessage_Station(stationNameStr, LogType.Info, "【报警日志】[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]上传IOT失败,错误原因:"+ iotResult.Item2 + "!");
+                }
             }
-            else
+            catch (Exception e)
             {
-                string sql = alarmData.ToStringInsert();
-                SQLHelper_New.ExecuteSQL(sql, null);
-                AddMessage_Station(stationNameStr, LogType.Info, "发生了报警[" + alarmData.LineName + "-" + alarmData.AlarmDesc + "]!");
+
+                throw e;
             }
+            
         }
         #endregion 报警数据
 

+ 231 - 153
MainForm/FaForm/Form_MESTest.Designer.cs

@@ -35,10 +35,22 @@
             this.txtInfo_Iot = new System.Windows.Forms.TextBox();
             this.groupBox2 = new System.Windows.Forms.GroupBox();
             this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
-            this.pnlDeviceState6 = new System.Windows.Forms.Panel();
+            this.pnlFileUp = new System.Windows.Forms.Panel();
             this.pnlDeviceState8 = new System.Windows.Forms.Panel();
             this.pnlDeviceState7 = new System.Windows.Forms.Panel();
             this.pnlPassStationDetail = new System.Windows.Forms.Panel();
+            this.label42 = new System.Windows.Forms.Label();
+            this.pnlPassStationDetail_status = new System.Windows.Forms.ComboBox();
+            this.pnlPassStationDetail_resultVal = new System.Windows.Forms.TextBox();
+            this.label41 = new System.Windows.Forms.Label();
+            this.pnlPassStationDetail_testItem = new System.Windows.Forms.TextBox();
+            this.label40 = new System.Windows.Forms.Label();
+            this.pnlPassStationDetail_functionNname = new System.Windows.Forms.ComboBox();
+            this.label12 = new System.Windows.Forms.Label();
+            this.PassStationDetail_SN = new System.Windows.Forms.TextBox();
+            this.label10 = new System.Windows.Forms.Label();
+            this.label11 = new System.Windows.Forms.Label();
+            this.PassStationDetail_slot = new System.Windows.Forms.TextBox();
             this.pnlPassStation = new System.Windows.Forms.Panel();
             this.cmbResult = new System.Windows.Forms.ComboBox();
             this.label39 = new System.Windows.Forms.Label();
@@ -118,21 +130,16 @@
             this.label1 = new System.Windows.Forms.Label();
             this.btnStationIn = new System.Windows.Forms.Button();
             this.tabControl1 = new System.Windows.Forms.TabControl();
-            this.PassStationDetail_SN = new System.Windows.Forms.TextBox();
-            this.label10 = new System.Windows.Forms.Label();
-            this.PassStationDetail_slot = new System.Windows.Forms.TextBox();
-            this.label11 = new System.Windows.Forms.Label();
-            this.label12 = new System.Windows.Forms.Label();
-            this.pnlPassStationDetail_functionNname = new System.Windows.Forms.ComboBox();
-            this.label40 = new System.Windows.Forms.Label();
-            this.pnlPassStationDetail_testItem = new System.Windows.Forms.TextBox();
-            this.pnlPassStationDetail_resultVal = new System.Windows.Forms.TextBox();
-            this.label41 = new System.Windows.Forms.Label();
-            this.label42 = new System.Windows.Forms.Label();
-            this.pnlPassStationDetail_status = new System.Windows.Forms.ComboBox();
+            this.pnlFileUp_sn = new System.Windows.Forms.TextBox();
+            this.label43 = new System.Windows.Forms.Label();
+            this.label44 = new System.Windows.Forms.Label();
+            this.pnlFileUp_slot = new System.Windows.Forms.TextBox();
+            this.pnlFileUp_path = new System.Windows.Forms.TextBox();
+            this.label45 = new System.Windows.Forms.Label();
             this.tabPage3.SuspendLayout();
             this.groupBox2.SuspendLayout();
             this.tableLayoutPanel1.SuspendLayout();
+            this.pnlFileUp.SuspendLayout();
             this.pnlPassStationDetail.SuspendLayout();
             this.pnlPassStation.SuspendLayout();
             this.pnlOperateLog.SuspendLayout();
@@ -230,7 +237,7 @@
             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
-            this.tableLayoutPanel1.Controls.Add(this.pnlDeviceState6, 0, 2);
+            this.tableLayoutPanel1.Controls.Add(this.pnlFileUp, 0, 2);
             this.tableLayoutPanel1.Controls.Add(this.pnlDeviceState8, 1, 2);
             this.tableLayoutPanel1.Controls.Add(this.pnlDeviceState7, 0, 2);
             this.tableLayoutPanel1.Controls.Add(this.pnlPassStationDetail, 2, 1);
@@ -250,16 +257,22 @@
             this.tableLayoutPanel1.Size = new System.Drawing.Size(1528, 509);
             this.tableLayoutPanel1.TabIndex = 31;
             // 
-            // pnlDeviceState6
-            // 
-            this.pnlDeviceState6.BackColor = System.Drawing.Color.Gray;
-            this.pnlDeviceState6.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.pnlDeviceState6.Enabled = false;
-            this.pnlDeviceState6.Location = new System.Drawing.Point(4, 342);
-            this.pnlDeviceState6.Margin = new System.Windows.Forms.Padding(2);
-            this.pnlDeviceState6.Name = "pnlDeviceState6";
-            this.pnlDeviceState6.Size = new System.Drawing.Size(502, 163);
-            this.pnlDeviceState6.TabIndex = 8;
+            // pnlFileUp
+            // 
+            this.pnlFileUp.BackColor = System.Drawing.Color.Gray;
+            this.pnlFileUp.Controls.Add(this.pnlFileUp_path);
+            this.pnlFileUp.Controls.Add(this.label45);
+            this.pnlFileUp.Controls.Add(this.pnlFileUp_sn);
+            this.pnlFileUp.Controls.Add(this.label43);
+            this.pnlFileUp.Controls.Add(this.label44);
+            this.pnlFileUp.Controls.Add(this.pnlFileUp_slot);
+            this.pnlFileUp.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.pnlFileUp.Enabled = false;
+            this.pnlFileUp.Location = new System.Drawing.Point(4, 342);
+            this.pnlFileUp.Margin = new System.Windows.Forms.Padding(2);
+            this.pnlFileUp.Name = "pnlFileUp";
+            this.pnlFileUp.Size = new System.Drawing.Size(502, 163);
+            this.pnlFileUp.TabIndex = 8;
             // 
             // pnlDeviceState8
             // 
@@ -306,6 +319,135 @@
             this.pnlPassStationDetail.Size = new System.Drawing.Size(504, 163);
             this.pnlPassStationDetail.TabIndex = 5;
             // 
+            // label42
+            // 
+            this.label42.AutoSize = true;
+            this.label42.Location = new System.Drawing.Point(12, 131);
+            this.label42.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label42.Name = "label42";
+            this.label42.Size = new System.Drawing.Size(80, 18);
+            this.label42.TabIndex = 93;
+            this.label42.Text = "测试状态";
+            // 
+            // pnlPassStationDetail_status
+            // 
+            this.pnlPassStationDetail_status.BackColor = System.Drawing.Color.WhiteSmoke;
+            this.pnlPassStationDetail_status.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.pnlPassStationDetail_status.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.pnlPassStationDetail_status.FormattingEnabled = true;
+            this.pnlPassStationDetail_status.Items.AddRange(new object[] {
+            "PASS",
+            "FAIL"});
+            this.pnlPassStationDetail_status.Location = new System.Drawing.Point(100, 128);
+            this.pnlPassStationDetail_status.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlPassStationDetail_status.Name = "pnlPassStationDetail_status";
+            this.pnlPassStationDetail_status.Size = new System.Drawing.Size(140, 26);
+            this.pnlPassStationDetail_status.TabIndex = 92;
+            // 
+            // pnlPassStationDetail_resultVal
+            // 
+            this.pnlPassStationDetail_resultVal.Location = new System.Drawing.Point(345, 85);
+            this.pnlPassStationDetail_resultVal.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlPassStationDetail_resultVal.Name = "pnlPassStationDetail_resultVal";
+            this.pnlPassStationDetail_resultVal.Size = new System.Drawing.Size(140, 28);
+            this.pnlPassStationDetail_resultVal.TabIndex = 91;
+            // 
+            // label41
+            // 
+            this.label41.AutoSize = true;
+            this.label41.Location = new System.Drawing.Point(256, 89);
+            this.label41.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label41.Name = "label41";
+            this.label41.Size = new System.Drawing.Size(62, 18);
+            this.label41.TabIndex = 90;
+            this.label41.Text = "测试值";
+            // 
+            // pnlPassStationDetail_testItem
+            // 
+            this.pnlPassStationDetail_testItem.Location = new System.Drawing.Point(100, 84);
+            this.pnlPassStationDetail_testItem.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlPassStationDetail_testItem.Name = "pnlPassStationDetail_testItem";
+            this.pnlPassStationDetail_testItem.Size = new System.Drawing.Size(140, 28);
+            this.pnlPassStationDetail_testItem.TabIndex = 89;
+            this.pnlPassStationDetail_testItem.Text = "抛料次数";
+            // 
+            // label40
+            // 
+            this.label40.AutoSize = true;
+            this.label40.Location = new System.Drawing.Point(12, 87);
+            this.label40.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label40.Name = "label40";
+            this.label40.Size = new System.Drawing.Size(62, 18);
+            this.label40.TabIndex = 88;
+            this.label40.Text = "测试项";
+            // 
+            // pnlPassStationDetail_functionNname
+            // 
+            this.pnlPassStationDetail_functionNname.BackColor = System.Drawing.Color.WhiteSmoke;
+            this.pnlPassStationDetail_functionNname.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.pnlPassStationDetail_functionNname.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.pnlPassStationDetail_functionNname.FormattingEnabled = true;
+            this.pnlPassStationDetail_functionNname.Items.AddRange(new object[] {
+            "Machine_加⼯模块",
+            "Test_测试模块",
+            "Fixture_Process",
+            "Material_Process",
+            "Tool_Process",
+            "File_Process"});
+            this.pnlPassStationDetail_functionNname.Location = new System.Drawing.Point(100, 46);
+            this.pnlPassStationDetail_functionNname.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlPassStationDetail_functionNname.Name = "pnlPassStationDetail_functionNname";
+            this.pnlPassStationDetail_functionNname.Size = new System.Drawing.Size(140, 26);
+            this.pnlPassStationDetail_functionNname.TabIndex = 81;
+            // 
+            // label12
+            // 
+            this.label12.AutoSize = true;
+            this.label12.Location = new System.Drawing.Point(12, 49);
+            this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label12.Name = "label12";
+            this.label12.Size = new System.Drawing.Size(80, 18);
+            this.label12.TabIndex = 87;
+            this.label12.Text = "功能名称";
+            // 
+            // PassStationDetail_SN
+            // 
+            this.PassStationDetail_SN.Location = new System.Drawing.Point(100, 5);
+            this.PassStationDetail_SN.Margin = new System.Windows.Forms.Padding(4);
+            this.PassStationDetail_SN.Name = "PassStationDetail_SN";
+            this.PassStationDetail_SN.Size = new System.Drawing.Size(140, 28);
+            this.PassStationDetail_SN.TabIndex = 86;
+            this.PassStationDetail_SN.Text = "4B180055";
+            // 
+            // label10
+            // 
+            this.label10.AutoSize = true;
+            this.label10.Location = new System.Drawing.Point(256, 10);
+            this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label10.Name = "label10";
+            this.label10.Size = new System.Drawing.Size(80, 18);
+            this.label10.TabIndex = 85;
+            this.label10.Text = "载具穴位";
+            // 
+            // label11
+            // 
+            this.label11.AutoSize = true;
+            this.label11.Location = new System.Drawing.Point(12, 11);
+            this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label11.Name = "label11";
+            this.label11.Size = new System.Drawing.Size(62, 18);
+            this.label11.TabIndex = 83;
+            this.label11.Text = "产品SN";
+            // 
+            // PassStationDetail_slot
+            // 
+            this.PassStationDetail_slot.Location = new System.Drawing.Point(345, 4);
+            this.PassStationDetail_slot.Margin = new System.Windows.Forms.Padding(4);
+            this.PassStationDetail_slot.Name = "PassStationDetail_slot";
+            this.PassStationDetail_slot.Size = new System.Drawing.Size(140, 28);
+            this.PassStationDetail_slot.TabIndex = 84;
+            this.PassStationDetail_slot.Text = "4B1400103";
+            // 
             // pnlPassStation
             // 
             this.pnlPassStation.BackColor = System.Drawing.Color.Gray;
@@ -1243,134 +1385,62 @@
             this.tabControl1.Size = new System.Drawing.Size(1566, 842);
             this.tabControl1.TabIndex = 16;
             // 
-            // PassStationDetail_SN
-            // 
-            this.PassStationDetail_SN.Location = new System.Drawing.Point(100, 5);
-            this.PassStationDetail_SN.Margin = new System.Windows.Forms.Padding(4);
-            this.PassStationDetail_SN.Name = "PassStationDetail_SN";
-            this.PassStationDetail_SN.Size = new System.Drawing.Size(140, 28);
-            this.PassStationDetail_SN.TabIndex = 86;
-            this.PassStationDetail_SN.Text = "4B180055";
-            // 
-            // label10
-            // 
-            this.label10.AutoSize = true;
-            this.label10.Location = new System.Drawing.Point(256, 10);
-            this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label10.Name = "label10";
-            this.label10.Size = new System.Drawing.Size(80, 18);
-            this.label10.TabIndex = 85;
-            this.label10.Text = "载具穴位";
-            // 
-            // PassStationDetail_slot
-            // 
-            this.PassStationDetail_slot.Location = new System.Drawing.Point(345, 4);
-            this.PassStationDetail_slot.Margin = new System.Windows.Forms.Padding(4);
-            this.PassStationDetail_slot.Name = "PassStationDetail_slot";
-            this.PassStationDetail_slot.Size = new System.Drawing.Size(140, 28);
-            this.PassStationDetail_slot.TabIndex = 84;
-            this.PassStationDetail_slot.Text = "4B1400103";
-            // 
-            // label11
-            // 
-            this.label11.AutoSize = true;
-            this.label11.Location = new System.Drawing.Point(12, 11);
-            this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label11.Name = "label11";
-            this.label11.Size = new System.Drawing.Size(62, 18);
-            this.label11.TabIndex = 83;
-            this.label11.Text = "产品SN";
-            // 
-            // label12
-            // 
-            this.label12.AutoSize = true;
-            this.label12.Location = new System.Drawing.Point(12, 49);
-            this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label12.Name = "label12";
-            this.label12.Size = new System.Drawing.Size(80, 18);
-            this.label12.TabIndex = 87;
-            this.label12.Text = "功能名称";
-            // 
-            // pnlPassStationDetail_functionNname
-            // 
-            this.pnlPassStationDetail_functionNname.BackColor = System.Drawing.Color.WhiteSmoke;
-            this.pnlPassStationDetail_functionNname.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-            this.pnlPassStationDetail_functionNname.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.pnlPassStationDetail_functionNname.FormattingEnabled = true;
-            this.pnlPassStationDetail_functionNname.Items.AddRange(new object[] {
-            "Machine_加⼯模块",
-            "Test_测试模块",
-            "Fixture_Process",
-            "Material_Process",
-            "Tool_Process",
-            "File_Process"});
-            this.pnlPassStationDetail_functionNname.Location = new System.Drawing.Point(100, 46);
-            this.pnlPassStationDetail_functionNname.Margin = new System.Windows.Forms.Padding(4);
-            this.pnlPassStationDetail_functionNname.Name = "pnlPassStationDetail_functionNname";
-            this.pnlPassStationDetail_functionNname.Size = new System.Drawing.Size(140, 26);
-            this.pnlPassStationDetail_functionNname.TabIndex = 81;
-            // 
-            // label40
-            // 
-            this.label40.AutoSize = true;
-            this.label40.Location = new System.Drawing.Point(12, 87);
-            this.label40.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label40.Name = "label40";
-            this.label40.Size = new System.Drawing.Size(62, 18);
-            this.label40.TabIndex = 88;
-            this.label40.Text = "测试项";
-            // 
-            // pnlPassStationDetail_testItem
-            // 
-            this.pnlPassStationDetail_testItem.Location = new System.Drawing.Point(100, 84);
-            this.pnlPassStationDetail_testItem.Margin = new System.Windows.Forms.Padding(4);
-            this.pnlPassStationDetail_testItem.Name = "pnlPassStationDetail_testItem";
-            this.pnlPassStationDetail_testItem.Size = new System.Drawing.Size(140, 28);
-            this.pnlPassStationDetail_testItem.TabIndex = 89;
-            this.pnlPassStationDetail_testItem.Text = "抛料次数";
-            // 
-            // pnlPassStationDetail_resultVal
-            // 
-            this.pnlPassStationDetail_resultVal.Location = new System.Drawing.Point(345, 85);
-            this.pnlPassStationDetail_resultVal.Margin = new System.Windows.Forms.Padding(4);
-            this.pnlPassStationDetail_resultVal.Name = "pnlPassStationDetail_resultVal";
-            this.pnlPassStationDetail_resultVal.Size = new System.Drawing.Size(140, 28);
-            this.pnlPassStationDetail_resultVal.TabIndex = 91;
-            // 
-            // label41
-            // 
-            this.label41.AutoSize = true;
-            this.label41.Location = new System.Drawing.Point(256, 89);
-            this.label41.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label41.Name = "label41";
-            this.label41.Size = new System.Drawing.Size(62, 18);
-            this.label41.TabIndex = 90;
-            this.label41.Text = "测试值";
-            // 
-            // label42
-            // 
-            this.label42.AutoSize = true;
-            this.label42.Location = new System.Drawing.Point(12, 131);
-            this.label42.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label42.Name = "label42";
-            this.label42.Size = new System.Drawing.Size(80, 18);
-            this.label42.TabIndex = 93;
-            this.label42.Text = "测试状态";
-            // 
-            // pnlPassStationDetail_status
-            // 
-            this.pnlPassStationDetail_status.BackColor = System.Drawing.Color.WhiteSmoke;
-            this.pnlPassStationDetail_status.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-            this.pnlPassStationDetail_status.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.pnlPassStationDetail_status.FormattingEnabled = true;
-            this.pnlPassStationDetail_status.Items.AddRange(new object[] {
-            "PASS",
-            "FAIL"});
-            this.pnlPassStationDetail_status.Location = new System.Drawing.Point(100, 128);
-            this.pnlPassStationDetail_status.Margin = new System.Windows.Forms.Padding(4);
-            this.pnlPassStationDetail_status.Name = "pnlPassStationDetail_status";
-            this.pnlPassStationDetail_status.Size = new System.Drawing.Size(140, 26);
-            this.pnlPassStationDetail_status.TabIndex = 92;
+            // pnlFileUp_sn
+            // 
+            this.pnlFileUp_sn.Location = new System.Drawing.Point(92, 16);
+            this.pnlFileUp_sn.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlFileUp_sn.Name = "pnlFileUp_sn";
+            this.pnlFileUp_sn.Size = new System.Drawing.Size(140, 28);
+            this.pnlFileUp_sn.TabIndex = 90;
+            this.pnlFileUp_sn.Text = "4B180055";
+            // 
+            // label43
+            // 
+            this.label43.AutoSize = true;
+            this.label43.Location = new System.Drawing.Point(248, 21);
+            this.label43.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label43.Name = "label43";
+            this.label43.Size = new System.Drawing.Size(80, 18);
+            this.label43.TabIndex = 89;
+            this.label43.Text = "载具穴位";
+            // 
+            // label44
+            // 
+            this.label44.AutoSize = true;
+            this.label44.Location = new System.Drawing.Point(4, 22);
+            this.label44.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label44.Name = "label44";
+            this.label44.Size = new System.Drawing.Size(62, 18);
+            this.label44.TabIndex = 87;
+            this.label44.Text = "产品SN";
+            // 
+            // pnlFileUp_slot
+            // 
+            this.pnlFileUp_slot.Location = new System.Drawing.Point(337, 15);
+            this.pnlFileUp_slot.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlFileUp_slot.Name = "pnlFileUp_slot";
+            this.pnlFileUp_slot.Size = new System.Drawing.Size(140, 28);
+            this.pnlFileUp_slot.TabIndex = 88;
+            this.pnlFileUp_slot.Text = "4B1400103";
+            // 
+            // pnlFileUp_path
+            // 
+            this.pnlFileUp_path.Location = new System.Drawing.Point(92, 63);
+            this.pnlFileUp_path.Margin = new System.Windows.Forms.Padding(4);
+            this.pnlFileUp_path.Name = "pnlFileUp_path";
+            this.pnlFileUp_path.Size = new System.Drawing.Size(385, 28);
+            this.pnlFileUp_path.TabIndex = 93;
+            this.pnlFileUp_path.Text = "D:\\Temp\\VisionLog\\Pic\\Left";
+            // 
+            // label45
+            // 
+            this.label45.AutoSize = true;
+            this.label45.Location = new System.Drawing.Point(3, 67);
+            this.label45.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label45.Name = "label45";
+            this.label45.Size = new System.Drawing.Size(80, 18);
+            this.label45.TabIndex = 92;
+            this.label45.Text = "文件路径";
             // 
             // Form_MESTest
             // 
@@ -1388,6 +1458,8 @@
             this.tabPage3.PerformLayout();
             this.groupBox2.ResumeLayout(false);
             this.tableLayoutPanel1.ResumeLayout(false);
+            this.pnlFileUp.ResumeLayout(false);
+            this.pnlFileUp.PerformLayout();
             this.pnlPassStationDetail.ResumeLayout(false);
             this.pnlPassStationDetail.PerformLayout();
             this.pnlPassStation.ResumeLayout(false);
@@ -1417,7 +1489,7 @@
         private System.Windows.Forms.TextBox txtInfo_Iot;
         private System.Windows.Forms.GroupBox groupBox2;
         private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
-        private System.Windows.Forms.Panel pnlDeviceState6;
+        private System.Windows.Forms.Panel pnlFileUp;
         private System.Windows.Forms.Panel pnlDeviceState8;
         private System.Windows.Forms.Panel pnlDeviceState7;
         private System.Windows.Forms.Panel pnlPassStationDetail;
@@ -1512,5 +1584,11 @@
         private System.Windows.Forms.ComboBox pnlPassStationDetail_status;
         private System.Windows.Forms.TextBox pnlPassStationDetail_resultVal;
         private System.Windows.Forms.Label label41;
+        private System.Windows.Forms.TextBox pnlFileUp_path;
+        private System.Windows.Forms.Label label45;
+        private System.Windows.Forms.TextBox pnlFileUp_sn;
+        private System.Windows.Forms.Label label43;
+        private System.Windows.Forms.Label label44;
+        private System.Windows.Forms.TextBox pnlFileUp_slot;
     }
 }

+ 101 - 14
MainForm/FaForm/Form_MESTest.cs

@@ -1,4 +1,5 @@
-using MainForm.ClassFile.XiaomiAPI;
+using EIP_Protocol;
+using MainForm.ClassFile.XiaomiAPI;
 using Sunny.UI.Win32;
 using System;
 using System.Collections.Generic;
@@ -295,7 +296,7 @@ namespace MainForm.FaForm
         {
             try
             {
-                await Task.Run(() =>
+                await Task.Run(async () =>
                 {
                     string stationStr = cmbStationName_Iot.Text.Trim();           // 工站名称
                     string mesStation = "";
@@ -373,6 +374,11 @@ namespace MainForm.FaForm
                             (int, string) resultPassStationDetail = SendIotPassStationDetailFun(mesStation);
                             ShowLog_Iot($"[{resultPassStationDetail.Item1}]" + resultPassStationDetail.Item2);
                             break;
+                        case "非结构化":
+                            Task<(int, string)> resultFileUp = SendIotFileUpFun(mesStation);
+                            var result = await resultFileUp;
+                            ShowLog_Iot($"[{result.Item1}]" + result.Item2);
+                            break;
                         default:
                             break;
                     }
@@ -725,7 +731,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = false;
                     pnlPassStation.Enabled = false;
                     pnlPassStationDetail.Enabled = false;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -735,7 +741,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Gray;
                     pnlPassStation.BackColor = Color.Gray;
                     pnlPassStationDetail.BackColor = Color.Gray;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -746,7 +752,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = false;
                     pnlPassStation.Enabled = false;
                     pnlPassStationDetail.Enabled = false;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -756,7 +762,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Gray;
                     pnlPassStation.BackColor = Color.Gray;
                     pnlPassStationDetail.BackColor = Color.Gray;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -767,7 +773,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = false;
                     pnlPassStation.Enabled = false;
                     pnlPassStationDetail.Enabled = false;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -777,7 +783,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Gray;
                     pnlPassStation.BackColor = Color.Gray;
                     pnlPassStationDetail.BackColor = Color.Gray;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -788,7 +794,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = true;
                     pnlPassStation.Enabled = false;
                     pnlPassStationDetail.Enabled = false;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -798,7 +804,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Yellow;
                     pnlPassStation.BackColor = Color.Gray;
                     pnlPassStationDetail.BackColor = Color.Gray;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -809,7 +815,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = false;
                     pnlPassStation.Enabled = true;
                     pnlPassStationDetail.Enabled = false;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -819,7 +825,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Gray;
                     pnlPassStation.BackColor = Color.Yellow;
                     pnlPassStationDetail.BackColor = Color.Gray;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -830,7 +836,7 @@ namespace MainForm.FaForm
                     pnlOperateLog.Enabled = false;
                     pnlPassStation.Enabled = false;
                     pnlPassStationDetail.Enabled = true;
-                    pnlDeviceState6.Enabled = false;
+                    pnlFileUp.Enabled = false;
                     pnlDeviceState7.Enabled = false;
                     pnlDeviceState8.Enabled = false;
 
@@ -840,7 +846,29 @@ namespace MainForm.FaForm
                     pnlOperateLog.BackColor = Color.Gray;
                     pnlPassStation.BackColor = Color.Gray;
                     pnlPassStationDetail.BackColor = Color.Yellow;
-                    pnlDeviceState6.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Gray;
+                    pnlDeviceState7.BackColor = Color.Gray;
+                    pnlDeviceState8.BackColor = Color.Gray;
+                    break;
+
+                case "非结构化":
+                    pnlDeviceState.Enabled = false;
+                    pnlFaultLog.Enabled = false;
+                    pnlStationInputBegin.Enabled = false;
+                    pnlOperateLog.Enabled = false;
+                    pnlPassStation.Enabled = false;
+                    pnlPassStationDetail.Enabled = false;
+                    pnlFileUp.Enabled = true;
+                    pnlDeviceState7.Enabled = false;
+                    pnlDeviceState8.Enabled = false;
+
+                    pnlDeviceState.BackColor = Color.Gray;
+                    pnlFaultLog.BackColor = Color.Gray;
+                    pnlStationInputBegin.BackColor = Color.Gray;
+                    pnlOperateLog.BackColor = Color.Gray;
+                    pnlPassStation.BackColor = Color.Gray;
+                    pnlPassStationDetail.BackColor = Color.Gray;
+                    pnlFileUp.BackColor = Color.Yellow;
                     pnlDeviceState7.BackColor = Color.Gray;
                     pnlDeviceState8.BackColor = Color.Gray;
                     break;
@@ -866,6 +894,42 @@ namespace MainForm.FaForm
                 txtFaultCode.Enabled = false;
             }
         }
+
+        /// <summary>
+        /// 上传过站数据_Iot
+        /// </summary>
+        /// <param name="mesStation">mes工站名称</param>
+        /// <returns></returns>
+        private async Task<(int, string)> SendIotFileUpFun(string mesStation)
+        {
+            (int, string) iotResult;
+            BarcodeSet_t BarcodeSet=new BarcodeSet_t();
+            BarcodeSet.strProductBarcode= pnlFileUp_sn.Text.Trim() ;
+            BarcodeSet.strCarrierBarcode = pnlFileUp_slot.Text.Trim();
+            string StationName = cmbStationName_Iot.Text.Trim();
+            string code = StationName.Substring(0, 6);
+            string name = StationName.Substring(6);
+            string path= pnlFileUp_path.Text.Trim();
+
+            Form_Home home= new Form_Home();
+            // 创建并显示加载提示框
+            using (var loadingForm = new LoadingForm())
+            {
+                loadingForm.Show();
+
+                iotResult = await home.SaveDBbyFileInfo(BarcodeSet, code, name, path);
+
+                // 关闭加载提示框
+                loadingForm.Close();
+            }
+
+            // 上传过站结果
+            //(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
+            //(int, string) iotResult = (0, "");
+            return iotResult;
+        }
+
+
         #endregion Iot手动上传 Tap
 
         #region 其他方法
@@ -890,7 +954,30 @@ namespace MainForm.FaForm
         {
             MessageEvent?.Invoke(logType, msg);
         }
+
         #endregion 其他方法
 
     }
+
+    public class LoadingForm : Form
+    {
+        private Label label;
+
+        public LoadingForm()
+        {
+            this.Text = "请稍等";
+            this.Width = 200;
+            this.Height = 100;
+            this.StartPosition = FormStartPosition.CenterScreen;
+
+            label = new Label
+            {
+                Text = "正在处理,请稍等...",
+                Dock = DockStyle.Fill,
+                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
+            };
+
+            this.Controls.Add(label);
+        }
+    }
 }

+ 1 - 0
MainForm/MainForm.csproj

@@ -288,6 +288,7 @@
     <Compile Include="ClassFile\XiaomiAPI_IOT\XiaomiMqttResponse_ErrCode.cs" />
     <Compile Include="ClassFile\XiaomiAPI_MES\XiaomiMESHttp_StationOutbound.cs" />
     <Compile Include="ClassFile\XiaomiAPI_MES\XiaomiMESHttp_StationInbound.cs" />
+    <Compile Include="ClassFile\XiaomiAPI_MES\XiaomiMESHttp_UpLoadFile.cs" />
     <Compile Include="ClassFile\XiaomiAPI_MES\XiaomiMESHttp_X5.cs" />
     <Compile Include="ClassFile\XiaomiAPI_MES\XiaomiMESResponse_ErrCode.cs" />
     <Compile Include="ClassFile\XiaomiAPI_RouteCom\XiaomiMES_RouteCommunication.cs" />