yanjinhui
2025-02-26 f3c2bc390da81d90b444ed48061cdf8b285e0567
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RJCP.IO.Ports;
using WIDESEA_ISerialPortRepository;
using WIDESEA_ISerialPortService;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Model.Models.SerialPort;
 
namespace WIDESEA_SerialPortService
{
    public class SerialPortService : ServiceBase<Dt_TorqueOp, ISerialPortRepository>, ISerialPortService
    {
        private SerialPortTestService _serialPortTestService;  // 串口服务
        public SerialPortService(ISerialPortRepository BaseDal) : base(BaseDal)
        {
 
            _serialPortTestService = new SerialPortTestService("COM3");
        }
 
        public WebResponseContent AddSerialPort(Dt_TorqueOp TorqueOp)
        {
            WebResponseContent content = new WebResponseContent();
            BaseDal.Db.Insertable(TorqueOp).ExecuteCommand();
            return content;
        }
 
        //// 启动串口通信
        //public WebResponseContent StartSerialPortCom()
        //{
        //    WebResponseContent content = new WebResponseContent();
 
        //    // 打开串口并开始发送数据
        //    _serialPortTestService.OpenSerialPort();
 
        //    return content;
        //}
 
        // 启动串口通信
        public void StartSerialPortCom()
        {
            //WebResponseContent content = new WebResponseContent();
 
            // 打开串口并开始发送数据
            _serialPortTestService.OpenSerialPort();
 
            //return content;
        }
 
 
 
        // 停止串口通信
        public void StopSerialPortCom()
        {
            //WebResponseContent content = new WebResponseContent();
            _serialPortTestService.CloseSerialPort();  // 关闭串口
            //return content;
        }
 
 
        public List<string> GetSerialPortCom()
        {
           
          return  _serialPortTestService.GetReceivedData();
         
        }
 
     
    }
}