From 2f0c81709876d76b6b120cf6ac43f05cda6dfe4c Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期六, 22 三月 2025 09:36:13 +0800
Subject: [PATCH] 修改websocket;

---
 项目代码/WIDESEAWCS_Server 正式/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs |  101 +++++++++++++++++++++++++-------------------------
 1 files changed, 51 insertions(+), 50 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs"
index f2eea2a..d4f798f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs"
@@ -3,24 +3,23 @@
 using System.Drawing.Imaging;
 using System.IO.Ports;
 using System.Linq;
+using System.Net.WebSockets;
 using System.Text;
 using System.Threading.Tasks;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
+using HslCommunication.WebSocket;
+using Newtonsoft.Json;
 using Quartz;
+using SqlSugar;
 using StackExchange.Profiling.Internal;
 using WIDESEA_ISerialPortRepository;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DTO;
-using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
-using WIDESEAWCS_Tasks.ConveyorLineJob;
-using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
 {
     [DisallowConcurrentExecution]
-    public class SerialPortJob : JobBase, IJob, IDisposable
+    public class SerialPortJob : JobBase, IJob,IDisposable
     {
         public void Dispose()
         {
@@ -30,24 +29,27 @@
         public enum CommandType
         {
             None = 0,
-            Get = 1,
-            Set = 2,
+            Get = 1,//鍙戜俊鍙�
+            Set = 2,//璁惧��
         }
 
         public enum CommandResult
         {
-            SetOK = 0,
-            GetOK = 1,
-            GetError = 2,
+            SetOK = 0,//parseok
+            GetOK = 1,//03
+            GetError = 2,//04
         }
         private readonly IPutakeRepository _putakeRepository;
         private readonly IProcessRepository _processRepository;
         private readonly ITorqueOpRepository _orqueOpRepository;
-        public SerialPortJob(IPutakeRepository putakeRepository, IProcessRepository processRepository, ITorqueOpRepository torqueOpRepository)
+        private WebSocketServer _webSocketContext;
+
+        public SerialPortJob(IPutakeRepository putakeRepository, IProcessRepository processRepository, ITorqueOpRepository torqueOpRepository, WebSocketServer webSocketContext)
         {
             _putakeRepository = putakeRepository;
             _processRepository = processRepository;
             _orqueOpRepository = torqueOpRepository;
+            _webSocketContext = webSocketContext;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -57,6 +59,7 @@
                 SerialPortDevice serialPortDevice = (SerialPortDevice)context.JobDetail.JobDataMap.Get("JobParams");
                 if (serialPortDevice != null)
                 {
+
                     List<DeviceProDTO> deviceProDTOs = serialPortDevice.DeviceProDTOs;
                     foreach (var item in deviceProDTOs)
                     {
@@ -65,30 +68,21 @@
                             DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandType) && x.ProtocolDetailType == nameof(CommandType.Set));
                             if (deviceProtocolDetail != null)
                             {
-                                //鎴戣鍓嶇杩斿洖缁欐垜涓�涓粍鍒紝鍜屼换鍔d
-                                string group = "";
-                                var putake = _putakeRepository.QueryFirst(x => x.Grouptype == group);
-                                //杩欓噷鍒ゆ柇缁勫埆涓変釜鐪嬫槸閭d釜锛屽氨鏌ラ偅涓伐鑹鸿〃鐨勫��
-                                if (group=="鐢垫皵")
+                                # region  Setvalue
+                                string group = item.DeviceProDataBlock;
+                                if (group == "鐢垫皵")
                                 {
-                                    //鍏堢湅宸ヨ壓琛ㄤ腑姝ラ涓�涓鎵殑鍊兼湁澶氬皯涓� 鍐嶆煡鐪婦t_TorqueOp琛ㄤ腑鏄惁鏈夎浠诲姟鍙穒d鍜屾楠ゆ�绘暟鏄惁婊¤冻宸ヨ壓琛�
-                                    var proces = _processRepository.QueryData(x => x.CraftType == group);
-
+                                    //鏌ョ湅姝ラ
+                                    var com = item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (5 * 1000).ToString().PadLeft(7, '0'))+"\r";
+                                    serialPortDevice.Communicator.Write(com+"\r");
+                                    //鎵撳紑涓插彛鏃跺厛璁惧��
+                                    
+                                     
                                 }
-                                if (group == "鏈烘")
-                                {
-
-                                }
-                                if (group == "鍦版矡")
-                                {
-
-                                }
-                                //g宸ヨ壓琛ㄧ殑鎵姏鍊�
-
-                                double num = 4.5;//0005000
-
-                                serialPortDevice.Communicator.Write(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (num* 1000).ToString().PadLeft(7,'0'))+"\r");//鎵撳紑涓插彛鏃跺厛璁惧��
+                                #endregion
                                 item.DeviceProParamName = CommandType.Set.ToString();
+
+
                             }
                         }
 
@@ -137,34 +131,38 @@
                                 {
                                     DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetOK));
                                     //03鎴愬姛
-
                                     if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue))
                                     {
-                                        //杩欓噷鎴愬姛涔嬪悗锛岃瀛樺偍鍒扮湅Dt_TorqueOp锛堝瓨浠诲姟鍙凤紝缁勶紝鍊硷級
+
+                                        string group = item.DeviceProDataBlock; // 璁惧鎵�灞炵粍鍒�
+                                        if (group == "鐢垫皵")
+                                        {
+
+                                            item.DeviceProParamName = CommandType.Set.ToString();
+                                        }
+                                        else if (item.DeviceProParamName == CommandType.Get.ToString())
+                                        {
+                                            //DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetError));
+                                            //if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue))
+                                            //{
+                                            //    item.DeviceProParamName = CommandType.Set.ToString();
 
 
 
-                                        item.DeviceProParamName = CommandType.Set.ToString();
-
-                                    }
-                                }
-                                else if (item.DeviceProParamName == CommandType.Get.ToString())
-                                {
-                                    DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetError));
-                                    if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue))
-                                    {
-                                        item.DeviceProParamName = CommandType.Set.ToString();
-
-
-
+                                            //}
+                                        }
                                     }
                                 }
                             }
+
+
+                            //寤轰竴涓璞″皢鍏朵紶缁欏墠绔�
+                            string data = JsonConvert.SerializeObject(serialPortDevice);//杩欓噷serialPortDevice鏄亣璁炬湁杩欎釜瀵硅薄
+                            _webSocketContext.PublishAllClientPayload(data);
                         }
+
                     }
-
                 }
-
             }
             catch (Exception ex)
             {
@@ -173,5 +171,8 @@
             WriteDebug("CommonConveyorLineJob", "test");
             return Task.CompletedTask;
         }
+       
+
+
     }
 }

--
Gitblit v1.9.3