From aeb32ca2cc420266734c782df01b27be617e6943 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期五, 07 三月 2025 13:48:37 +0800
Subject: [PATCH] 后端业务

---
 项目代码/WIDESEAWCS_Server 正式/WIDESEAWCS_Tasks/SerialPort/SerialPortJob.cs |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 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 40462f4..9e8c32a 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"
@@ -9,6 +9,7 @@
 
 namespace WIDESEAWCS_Tasks
 {
+    [DisallowConcurrentExecution]
     public class SerialPortJob : JobBase, IJob
     {
         public enum CommandType
@@ -17,20 +18,23 @@
             Get = 1,
             Set = 2,
         }
-        private SerialPort serialPort;
-        private CommandType commandType = CommandType.None;
-        private string commandGet = "";//璇诲��
-        private string commandSet = "";//璁惧��
-        private string setOK = "";
-        private string getOK = "";
+        private static SerialPort serialPort;
+        private static CommandType commandType = CommandType.None;
+        private string commandGet = "824070241JNT\r";//璇诲��
+        private string commandSet = "824070241JNT,0005000,+0001000[+TOL],-0001000[-TOL]\r";//璁惧��
+        private string setOK = "ParseOK";
+        private string getOK = "82407024103";
+        private string getError = "82407024104";
         public Task Execute(IJobExecutionContext context)
         {
             try
             {
-                if (serialPort == null) { serialPort = new SerialPort("COM1"); serialPort.DataReceived += SerialPort_DataReceived;}
+                if (serialPort == null) { serialPort = new SerialPort("COM3"); serialPort.DataReceived += SerialPort_DataReceived; }
                 if (!serialPort.IsOpen)
                 {
                     serialPort.Open();
+
+
 
                     serialPort.Write(commandSet);//鎵撳紑涓插彛鏃跺厛璁惧��
                     commandType = CommandType.Set;
@@ -45,7 +49,11 @@
                         break;
                 }
             }
-            catch (Exception ex) { }            return Task.CompletedTask;
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            return Task.CompletedTask;
         }
         private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
         {
@@ -61,6 +69,14 @@
                 else if (data.Contains(getOK) && commandType == CommandType.Get)
                 {
                     commandType = CommandType.Set;
+
+
+                }
+                else if (data.Contains(getError) && commandType == CommandType.Get)
+                {
+                    commandType = CommandType.Set;
+
+
                 }
             }
         }

--
Gitblit v1.9.3