You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs

55 lines
2.1 KiB

using IoTNode.DeviceServices.SerialPortManager;
using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.ComponentModel.DataAnnotations;
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("设备编号"), Required] string number, [SwaggerParameter("命令"), Required] string name)
{
return this.AsyncAction(() =>
{
this._deviceService.SendMessage(number, name);
});
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse Buttons([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("指令"), Required] string buttons)
{
return this.AsyncAction(() =>
{
this._deviceService.UpdateButtons(number, buttons);
});
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
public ApiResponse Test([SwaggerParameter("设备编号"), Required] string number,
[SwaggerParameter("串口"), Required] string port,
[SwaggerParameter("波特率"), Required] int baud,
[SwaggerParameter("数据位"), Required] int dataBits,
[SwaggerParameter("校验位"), Required] int partity,
[SwaggerParameter("停止位"), Required] int stopBits,
[SwaggerParameter("消息"), Required] string message)
{
return this.AsyncAction(() =>
{
this._deviceService.ExecCommand(port, baud, dataBits, partity, stopBits, message);
});
}
}
}