From 880766ff5ccc98f1def11cd3c6e15e860f143ada Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期五, 28 二月 2025 14:51:41 +0800 Subject: [PATCH] 扭矩 --- 项目代码/WIDESEAWCS_Server 正式/WIDESEAWCS_Tasks/SerialPort/SerialPortTestJob.cs | 38 ++++++++++++++++++++++++++++---------- 1 files changed, 28 insertions(+), 10 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/SerialPortTestService.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/SerialPortTestJob.cs" similarity index 86% rename from "\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortTestService.cs" rename to "\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_Tasks/SerialPort/SerialPortTestJob.cs" index 0cbbb53..abc1750 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/SerialPortTestService.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/SerialPortTestJob.cs" @@ -1,38 +1,54 @@ 锘縰sing System.IO.Ports; using System.Text; +using Quartz; using WIDESEA_ISerialPortService; using WIDESEAWCS_Model.Models.SerialPort; -namespace WIDESEA_SerialPortTestService +namespace WIDESEAWCS_Tasks { - public class SerialPortTestService + public class SerialPortTestJob:IJob { // 鍦� SerialPortTestService 绫讳腑娣诲姞瀵� ISerialPortService 鐨勫紩鐢� private readonly ISerialPortService _serialPortService; + public readonly string _port; + public SerialPort SerialPort { get; set; } =null!; //琛ㄧず瑕佹墦寮�鐨勪覆鍙�,鍙负绌� // 鏋勯�犲嚱鏁� - public SerialPortTestService(string port, ISerialPortService _serialPortService) + public SerialPortTestJob(ISerialPortService serialPortService) { - SerialPort = new SerialPort(port); + _serialPortService = serialPortService; + _port = "COM3"; + + SerialPort = new SerialPort(_port); + + //涓插彛鎺ユ敹鍒版暟鎹椂锛孲erialPort 浼氳嚜鍔ㄨЕ鍙� DataReceived 浜嬩欢 - SerialPort.DataReceived += OnDataReceived; //鎺ユ敹涓插彛鍙戝嚭鐨勬暟鎹� + //SerialPort.DataReceived += OnDataReceived; //鎺ユ敹涓插彛鍙戝嚭鐨勬暟鎹� } private CancellationTokenSource _cancellationTokenSource; private Task _sendTask; private int commandType = 2; - public SerialPort SerialPort { get; set; } = null!; //琛ㄧず瑕佹墦寮�鐨勪覆鍙�,鍙负绌� - //// 浜嬩欢 - 鐢ㄤ簬閫氱煡鏁版嵁鎺ユ敹鍒� - //public event Action<string> DataReceivedEvent; + // 鍛戒护瀛楃涓� private string command0 = ""; // 涓嶅彂閫佸懡浠� private string command1 = "824070241JNT\r"; //鍙戦�佷俊鍙� - private string command2 = "824070241JNT,0004000,+0001000[+TOL],-0001000[-TOL]\r"; //璁惧�� + private string command2 = "824070241JNT,0005000,+0001000[+TOL],-0001000[-TOL]\r"; //璁惧�� + + public Task Execute(IJobExecutionContext context) + { + + OpenSerialPort(); + SerialPort.DataReceived += OnDataReceived; + + return Task.CompletedTask; + } + // 鐢ㄤ簬瀛樺偍鎺ユ敹鍒扮殑鏁版嵁 private List<string> receivedDataList = new List<string>(); @@ -112,7 +128,7 @@ receivedDataList.Add(receivedData); - + @@ -160,5 +176,7 @@ } }); } + + } } \ No newline at end of file -- Gitblit v1.9.3