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
using Autofac.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WIDESEA_ISerialPortService;
using WIDESEA_SerialPortService;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseController;
using WIDESEAWCS_Model.Models.SerialPort;
using WIDESEAWCS_QuartzJob.Service;
//using WIDESEA_ISerialPortService.ISerialPortService;
 
namespace WIDESEAWCS_Server.Controllers.SerialPort
{
    [Route("api/[controller]")]
    [ApiController]
    public class SerialPortController : ApiBaseController<ISerialPortService, Dt_TorqueOp>
    {
        private readonly ISerialPortService _serialPortService;
        // 构造函数注入服务
        public SerialPortController(ISerialPortService serialPortService):base(serialPortService)
        {
            _serialPortService = serialPortService;
        }
 
     
        [HttpPost, Route("AddStudent"), AllowAnonymous]
        public WebResponseContent AddStudent([FromBody] Dt_TorqueOp TorqueOp)
        {
            return Service.AddSerialPort(TorqueOp);
        }
 
        /// <summary>
        /// 开启
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("StartSerialPortCom"), AllowAnonymous]
        public IActionResult StartSerialPortCom()
        {
             Service.StartSerialPortCom();
            return Ok(new { messga = "开启成功" });
        }
 
        /// <summary>
        /// 关
        /// </summary>
        /// <returns></returns>
        [HttpPost,Route("StopSerialPortCom"),AllowAnonymous]
        public IActionResult StopSerialPortCom()
        {
             _serialPortService.StopSerialPortCom();
            return Ok(new { messga = "关闭成功" });
        }
 
        /// <summary>
        /// 查
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("GetSerialPortCom"), AllowAnonymous]
        public IActionResult GetSerialPortCom()
        {
            
            var receivedData = _serialPortService.GetSerialPortCom(); // 调用 SerialPortService 的 GetReceivedData 方法
            return Ok(receivedData); // 返回接收到的数据
            
        }
    }
}