change - 看板数据推送

master
wenjy 2 months ago
parent 82e9c90f9d
commit 09d6e3b94b

@ -41,8 +41,6 @@ namespace SlnMesnac.Business
/// </summary>
public class AutoModeBusiness : BaseBusiness
{
public readonly RealTemperatureInfo _realTemperatureInfo = new RealTemperatureInfo();
private readonly Irecord_busbar_tempServices _record_busbar_TempServices;
private readonly AppConfig _appConfig;
@ -55,7 +53,7 @@ namespace SlnMesnac.Business
public delegate void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos);
public event GimbaRotationControl GimbaRotationControlEvent;
public AutoModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_busbar_tempServices record_busbar_TempServices, Ibase_alarm_infoServices base_Alarm_InfoServices, AppConfig appConfig, Irecord_busbar_alarmServices record_Busbar_AlarmServices) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices, base_Alarm_InfoServices, record_Busbar_AlarmServices)
public AutoModeBusiness( Irecord_busbar_tempServices record_busbar_TempServices, AppConfig appConfig, IServiceProvider serviceProvider) : base(serviceProvider)
{
_record_busbar_TempServices = record_busbar_TempServices;
_appConfig = appConfig;

@ -35,11 +35,9 @@ namespace SlnMesnac.Business
{
public class FixedPointBusiness : BaseBusiness
{
private readonly Irecord_busbar_tempServices _record_busbar_TempServices;
public FixedPointBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_busbar_tempServices record_busbar_TempServices, Ibase_alarm_infoServices base_Alarm_InfoServices, Irecord_busbar_alarmServices record_Busbar_AlarmServices) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices, base_Alarm_InfoServices, record_Busbar_AlarmServices)
public FixedPointBusiness(Irecord_busbar_tempServices record_busbar_TempServices, IServiceProvider serviceProvider) : base(serviceProvider)
{
_record_busbar_TempServices = record_busbar_TempServices;
}

@ -41,15 +41,14 @@ namespace SlnMesnac.Business
private readonly Irecord_busbar_tempServices _record_busbar_TempServices;
private readonly Irecord_inspection_cabinetServices _service;
public readonly RealTemperatureInfo _realTemperatureInfo = new RealTemperatureInfo();
public delegate void CaptureAlarmPicture(string sJpegPicFileName);
public event CaptureAlarmPicture CaptureAlarmPictureEvent;
public delegate void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos);
public event GimbaRotationControl GimbaRotationControlEvent;
public InspModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_inspection_cabinetServices service, Irecord_busbar_tempServices irecord_Busbar_TempServices,Ibase_alarm_infoServices base_Alarm_InfoServices, Irecord_busbar_alarmServices record_Busbar_AlarmServices) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices, base_Alarm_InfoServices, record_Busbar_AlarmServices)
public InspModeBusiness( Irecord_inspection_cabinetServices service,
Irecord_busbar_tempServices irecord_Busbar_TempServices,IServiceProvider serviceProvider) : base(serviceProvider)
{
_record_busbar_TempServices = irecord_Busbar_TempServices;
_service = service;

@ -5,6 +5,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fleck" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />

@ -0,0 +1,134 @@
using Fleck;
using Newtonsoft.Json.Linq;
using SlnMesnac.Model.dto;
using SlnMesnac.Plc;
using SlnMesnac.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* T14-GEN3-7895
* SlnMesnac.Business
* 2a743b18-b6e9-499e-87b5-15ad4a2041b6
*
* WenJY
*
* 2024-12-04 9:10:44
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Business
{
public class WebSocketBusiness
{
private List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>();
private readonly RealTemperatureInfo _realTemperatureInfo;
public readonly PlcAbsractFactory _plc;
public WebSocketBusiness(RealTemperatureInfo realTemperatureInfo, PlcAbsractFactory plc)
{
_plc = plc;
_realTemperatureInfo = realTemperatureInfo;
this.Init();
}
public void Encapsulation(bool isAlarm ,base_alarm_info alarmInfo,record_busbar_alarm busbarAlarm,int source = 1)
{
if(_realTemperatureInfo != null)
{
JObject jsonObject = new JObject
{
["Uuid"] = System.Guid.NewGuid().ToString(),
["DeviceInfo"] = new JObject
{
["deviceStatus"] = _plc.readInt32ByAddress("VD1508"),
["runSpeed"] = _plc.readFloatByAddress("VD2022"),
["liftStatus"] = 1,
["cabinetCode"] = _plc.readInt32ByAddress("VD1100"),
["realAddr"] = string.Empty,
},
["TemParam"] = new JObject
{
["tempMax"] = _realTemperatureInfo.fMaxTemperature,
["tempMin"] = _realTemperatureInfo.fMinTemperature,
["tempAvg"] = _realTemperatureInfo.fAverageTemperature,
["tempDiff"] = _realTemperatureInfo.fTemperatureDiff
},
["AlarmInfo"] = new JObject
{
["isAlarm"] = isAlarm ? 1 : 0,
["alarmAddr"] = busbarAlarm != null ? busbarAlarm.cabinetCode : null,
["alarmType"] = alarmInfo != null ? alarmInfo.alarmType : null,
["alarmAlias"] = alarmInfo != null ? alarmInfo.alarmAlias : null,
["alarmContent"] = alarmInfo != null ? alarmInfo.alarmContent : null,
["alarmSource"] = source,
["isFlag"] = 0,
["alarmTime"] = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
}
};
// 将 JObject 转换为 JSON 字符串
string jsonString = jsonObject.ToString();
this.sendMessage(jsonString);
}
}
public void Init()
{
var server = new Fleck.WebSocketServer($"ws://0.0.0.0:7181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
var data = socket.ConnectionInfo;
Console.WriteLine("WebSocket Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("WebSocket Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
//ReceivedMessageRequestInfoEvent?.Invoke(socket, message);
};
});
}
public void sendMessage(string message)
{
try
{
foreach (var socket in allSockets.ToList())
{
socket.Send(message);
Console.WriteLine("WebSocket接口上传数据:" + message);
}
}
catch (Exception ex)
{
Console.WriteLine("WebSocket上传数据异常", ex);
}
}
}
}

@ -1,4 +1,5 @@
using Serilog;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using SlnMesnac.Model.dto;
using SlnMesnac.Plc;
using SlnMesnac.Repository;
@ -8,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
@ -40,23 +42,35 @@ namespace SlnMesnac.Business.@base
public readonly PlcAbsractFactory _plc;
public readonly RealTemperatureInfo _realTemperatureInfo;
private readonly WebSocketBusiness _webSocketBusiness;
private IServiceProvider _serviceProvider;
public readonly Ibase_cabinet_infoServices _ibase_Cabinet_InfoServices;
public readonly Ibase_busbar_infoServices _ibase_Busbar_InfoServices;
private readonly Ibase_alarm_infoServices _ibase_Alarm_InfoServices;
private readonly Irecord_busbar_alarmServices _iRecord_Busbar_AlarmServices;
public bool isFlag = false;
public BaseBusiness(SerilogHelper log,PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices,
Ibase_busbar_infoServices base_Busbar_InfoServices, Ibase_alarm_infoServices base_Alarm_InfoServices,
Irecord_busbar_alarmServices record_Busbar_AlarmServices)
public BaseBusiness(IServiceProvider serviceProvider)
{
_log = log;
_plc = plc;
_ibase_Cabinet_InfoServices = base_Cabinet_InfoServices;
_ibase_Busbar_InfoServices = base_Busbar_InfoServices;
_ibase_Alarm_InfoServices = base_Alarm_InfoServices;
_iRecord_Busbar_AlarmServices = record_Busbar_AlarmServices;
_serviceProvider = serviceProvider;
using (var scope = _serviceProvider.CreateScope())
{
_log = scope.ServiceProvider.GetRequiredService<SerilogHelper>();
_plc = scope.ServiceProvider.GetRequiredService<PlcAbsractFactory>();
_realTemperatureInfo = scope.ServiceProvider.GetRequiredService<RealTemperatureInfo>();
_ibase_Cabinet_InfoServices = scope.ServiceProvider.GetRequiredService<Ibase_cabinet_infoServices>();
_ibase_Busbar_InfoServices = scope.ServiceProvider.GetRequiredService<Ibase_busbar_infoServices>();
_ibase_Alarm_InfoServices = scope.ServiceProvider.GetRequiredService<Ibase_alarm_infoServices>();
_iRecord_Busbar_AlarmServices = scope.ServiceProvider.GetRequiredService<Irecord_busbar_alarmServices>();
_webSocketBusiness = scope.ServiceProvider.GetRequiredService<WebSocketBusiness>();
}
}
/// <summary>
@ -172,6 +186,10 @@ namespace SlnMesnac.Business.@base
_iRecord_Busbar_AlarmServices.Insert(busbarAlarm);
busbarTemp.isAlarm = 1;
_webSocketBusiness.Encapsulation(true,alarm,busbarAlarm);
}
}
}

@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using SlnMesnac.Model.dto;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -64,6 +65,8 @@ namespace SlnMesnac.Extensions
return Db;
});
services.AddSingleton<RealTemperatureInfo>();
}
}
}

@ -1,6 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;
using NVelocity.Util.Introspection;
using SlnMesnac.Business;
using SlnMesnac.Business.@base;
using SlnMesnac.Config;
@ -46,6 +48,9 @@ namespace SlnMesnac.WPF.ViewModel
private AutoModeBusiness autoModeBusiness;
private InspModeBusiness inspModeBusiness;
private FixedPointBusiness fixedPointBusiness;
private WebSocketBusiness webSocketBusiness;
private AppConfig _appConfig;
private CHCNetSDK.RemoteConfigCallback _callback;
@ -71,6 +76,7 @@ namespace SlnMesnac.WPF.ViewModel
autoModeBusiness = App.ServiceProvider.GetService<AutoModeBusiness>();
inspModeBusiness = App.ServiceProvider.GetService<InspModeBusiness>();
fixedPointBusiness = App.ServiceProvider.GetService<FixedPointBusiness>();
webSocketBusiness = App.ServiceProvider.GetService<WebSocketBusiness>();
autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture;
autoModeBusiness.GimbaRotationControlEvent += GimbaRotationControl;
@ -205,24 +211,6 @@ namespace SlnMesnac.WPF.ViewModel
public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
{
var ret = Marshal.PtrToStructure<CHCNetSDK.NET_DVR_THERMOMETRY_UPLOAD>(lpBuffer);
if (autoModeBusiness != null)
{
autoModeBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1);
autoModeBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature);
autoModeBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1);
autoModeBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1);
fixedPointBusiness._realTemperatureInfo.fMaxTemperature = autoModeBusiness._realTemperatureInfo.fMaxTemperature;
fixedPointBusiness._realTemperatureInfo.fMinTemperature = autoModeBusiness._realTemperatureInfo.fMinTemperature;
fixedPointBusiness._realTemperatureInfo.fAverageTemperature = autoModeBusiness._realTemperatureInfo.fAverageTemperature;
fixedPointBusiness._realTemperatureInfo.fTemperatureDiff = autoModeBusiness._realTemperatureInfo.fTemperatureDiff;
inspModeBusiness._realTemperatureInfo.fMaxTemperature = autoModeBusiness._realTemperatureInfo.fMaxTemperature;
inspModeBusiness._realTemperatureInfo.fMinTemperature = autoModeBusiness._realTemperatureInfo.fMinTemperature;
inspModeBusiness._realTemperatureInfo.fAverageTemperature = autoModeBusiness._realTemperatureInfo.fAverageTemperature;
inspModeBusiness._realTemperatureInfo.fTemperatureDiff = autoModeBusiness._realTemperatureInfo.fTemperatureDiff;
}
this.RealTemperature = new RealTemperatureInfo()
{
@ -231,6 +219,17 @@ namespace SlnMesnac.WPF.ViewModel
fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1),
fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1),
};
using (var scope = App.ServiceProvider.CreateScope())
{
var info = scope.ServiceProvider.GetRequiredService<RealTemperatureInfo>();
info.fMaxTemperature = _realTemperature.fMaxTemperature;
info.fMinTemperature = _realTemperature.fMinTemperature;
info.fAverageTemperature = _realTemperature.fAverageTemperature;
info.fTemperatureDiff = _realTemperature.fTemperatureDiff;
}
webSocketBusiness.Encapsulation(false, null, null);
}
/// <summary>
@ -660,5 +659,6 @@ namespace SlnMesnac.WPF.ViewModel
}
});
}
}
}

@ -29,8 +29,8 @@
{
"configId": 1,
"plcType": "SiemensPlc",
//"plcIp": "127.0.0.1",
"plcIp": "192.168.2.1",
"plcIp": "127.0.0.1",
//"plcIp": "192.168.2.1",
"plcPort": 102,
"plcKey": "iot",
"isFlage": "true"

Loading…
Cancel
Save