Files
serein-flow/Net462DllTest/Web/CommandController.cs

57 lines
1.3 KiB
C#
Raw Normal View History

2024-10-07 15:15:18 +08:00

using Net462DllTest.Enums;
using Net462DllTest.Signal;
using Net462DllTest.Trigger;
2024-09-27 10:30:19 +08:00
using Serein.Library.Attributes;
2024-10-07 15:15:18 +08:00
using Serein.Library.Utils;
2024-09-27 10:30:19 +08:00
using Serein.Library.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-10-07 15:15:18 +08:00
namespace Net462DllTest.Web
2024-09-27 10:30:19 +08:00
{
[AutoHosting]
2024-09-30 16:36:55 +08:00
public class CommandController : ControllerBase
2024-09-27 10:30:19 +08:00
{
2024-10-07 15:15:18 +08:00
private readonly SiemensPlcDevice plcDevice;
2024-09-27 10:30:19 +08:00
2024-10-07 15:15:18 +08:00
public CommandController(SiemensPlcDevice plcDevice)
2024-09-30 16:36:55 +08:00
{
2024-10-07 15:15:18 +08:00
this.plcDevice = plcDevice;
2024-09-30 16:36:55 +08:00
}
/*
* POST
* url : http://127.0.0.1:8089/command/trigger?command=
* body [JSON]
*
* {
* "value":0,
* }
*/
2024-09-27 10:30:19 +08:00
[WebApi(API.POST)]
2024-10-07 15:15:18 +08:00
public dynamic Trigger([Url] string var, int value)
2024-09-27 10:30:19 +08:00
{
2024-10-07 15:15:18 +08:00
if (EnumHelper.TryConvertEnum<PlcVarName>(var,out var signal))
2024-09-27 10:30:19 +08:00
{
Console.WriteLine($"外部触发 {signal} 信号,信号内容 {value} ");
2024-10-07 15:15:18 +08:00
plcDevice.TriggerSignal(signal, value);// 通过 Web Api 模拟外部输入信号
2024-09-27 10:30:19 +08:00
return new { state = "succeed" };
}
2024-10-07 15:15:18 +08:00
else
{
return new { state = "fail" };
}
2024-09-27 10:30:19 +08:00
}
}
2024-10-07 15:15:18 +08:00
2024-09-27 10:30:19 +08:00
}