using Application.Models; using IoTNode.DeviceServices.SerialPortManager; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System; namespace IoTNode.Controllers { [SwaggerTag("串口控制器")] public class SerialPortController : BaseDeviceController { private readonly SerialPortService _deviceService; public SerialPortController(IServiceProvider applicationServices, SerialPortService deviceService) : base(applicationServices) { this._deviceService = deviceService; } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("发送指令")] public ApiResponse Send([SwaggerParameter("设备编号")]string number, [SwaggerParameter("命令")]string name) { return this.AsyncAction(() => { this._deviceService.Exec(number, name); }); } [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("自定义指令")] public ApiResponse Buttons([SwaggerParameter("设备编号")]string number, [SwaggerParameter("指令")]string buttons) { return this.AsyncAction(() => { this._deviceService.UpdateButtons(number, buttons); }); } public ApiResponse Test([SwaggerParameter("设备编号")]string number, [SwaggerParameter("串口")]string port, [SwaggerParameter("波特率")]int baud, [SwaggerParameter("数据位")]int dataBits, [SwaggerParameter("校验位")]int partity, [SwaggerParameter("停止位")]int stopBits, [SwaggerParameter("消息")]string message) { return this.AsyncAction(() => { this._deviceService.Test(port, baud, dataBits, partity, stopBits, message); }); } } }