57 lines
2.5 KiB
C#
Raw Normal View History

2024-08-21 16:50:14 +08:00
using Abp.Dependency;
using DotNettyHelper;
using System.Threading.Tasks.Dataflow;
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.TeleInfoSave;
using Yunda.ISAS.DataMonitoringServer.WebSocket.Model;
using Yunda.ISAS.MongoDB.Entities.DataMonitoring;
namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection
{
public class TelcommandDataModel
{
public TelecommandModel Telecommand { get; set; }
public ReceiveMessageEventArgs<DataMonitorMessageModel> ReceiveMessageEvent { get; set; }
}
public class TeleCommandDataSendTask : ISingletonDependency
{
public ActionBlock<TelcommandDataModel> TelecommandTActionBlock = default;
public TeleCommandDataSendTask(TelecommandResultSaveTask telecommandResultSaveTask
)
{
TelecommandTActionBlock = new ActionBlock<TelcommandDataModel>(data =>
{
var telecommand = data.Telecommand;
try
{
var info = $"编码地址:{ (int)telecommand.DispatcherAddress}, 遥控值:{(byte)telecommand.CommandValue},遥控类型:{telecommand.RemoteType}";
// int rst = DataCollectionTask.Iec104ClnYK((byte)telecommand.DeviceAddress, (byte)telecommand.CPUSector, (ushort)telecommand.DispatcherAddress, (byte)telecommand.CommandValue);
int rst = 0;
DataCollectionTask._client.SendValue((byte)telecommand.CommandValue, (int)telecommand.DispatcherAddress, telecommand.RemoteType == YunDa.ISAS.Entities.DataMonitoring.RemoteTypeEnum.DoublePoint);
telecommandResultSaveTask.SaveDataAsync(new TelecommandResult
{
TelecommandConfigurationId = telecommand.Id,
Source = telecommand.Source,
Sender = telecommand.Sender,
CommandValue = telecommand.CommandValue,
SendStatus = rst,
TelecommandTime = DateTime.Now
});
var soltstr = rst == 0 ? "成功" : "失败";
MonitoringEventBus.LogHandler(info, $"发送遥控数据{soltstr}");
Task.Delay(3000).Wait();
}
catch (Exception ex)
{
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
}
}, new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 1 });
}
}
}