diff --git a/SlnMesnac.Business/AutoTaskBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs
similarity index 58%
rename from SlnMesnac.Business/AutoTaskBusiness.cs
rename to SlnMesnac.Business/AutoModeBusiness.cs
index 23b9588..98fd4b2 100644
--- a/SlnMesnac.Business/AutoTaskBusiness.cs
+++ b/SlnMesnac.Business/AutoModeBusiness.cs
@@ -1,4 +1,6 @@
-using SlnMesnac.Business.@base;
+using Microsoft.IdentityModel.Logging;
+using SlnMesnac.Business.@base;
+using SlnMesnac.Config;
using SlnMesnac.Model.dto;
using SlnMesnac.Plc;
using SlnMesnac.Repository;
@@ -34,18 +36,70 @@ using System.Threading.Tasks;
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Business
{
- public class AutoTaskBusiness : BaseBusiness
+ ///
+ /// 自动模式
+ ///
+ public class AutoModeBusiness : BaseBusiness
{
public readonly RealTemperatureInfo _realTemperatureInfo = new RealTemperatureInfo();
- public AutoTaskBusiness(SerilogHelper log,PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices) : base(log,plc, base_Cabinet_InfoServices, base_Busbar_InfoServices)
+ private readonly Irecord_busbar_tempServices _record_busbar_TempServices;
+
+ private readonly AppConfig _appConfig;
+
+ private System.Timers.Timer timer = null;
+
+ public delegate void CaptureAlarmPicture(string sJpegPicFileName);
+ public event CaptureAlarmPicture CaptureAlarmPictureEvent;
+
+ public AutoModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_busbar_tempServices record_busbar_TempServices, AppConfig appConfig) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices)
{
+ _record_busbar_TempServices = record_busbar_TempServices;
+ _appConfig = appConfig;
+
+
+ }
+
+ public void Start()
+ {
+ try
+ {
+ timer = new System.Timers.Timer(1000 * 60 * _appConfig.checkCycle);
+ timer.Elapsed += new System.Timers.ElapsedEventHandler(AutoModelEvent);
+ timer.AutoReset = true;
+ timer.Enabled = false;
+ timer.Start();
+ _log.Info($"自动模式初始化成功");
+ this.AutoModelEvent(null, null);
+ }
+ catch (Exception ex)
+ {
+ _log.Info($"自动模式初始化异常:{ex.Message}");
+ }
+ }
+
+ public void Stop()
+ {
+ try
+ {
+ if (timer.Enabled)
+ {
+ timer.Stop();
+ timer.Close();
+ timer.Dispose();
+ _log.Info($"自动模式关闭成功");
+ }
+ }
+ catch (Exception ex)
+ {
+ _log.Info($"自动模式停止异常:{ex.Message}");
+ }
}
///
/// 自动巡检
///
- public void AutoCheckHandle()
+ private void AutoModelEvent(object source, System.Timers.ElapsedEventArgs e)
{
lock(string.Empty)
{
@@ -84,9 +138,9 @@ namespace SlnMesnac.Business
_log.Info($"巡检结束");
});
- }catch (Exception e)
+ }catch (Exception ex)
{
- throw new InvalidOperationException($"自动巡检逻辑处理异常:{e.Message}");
+ throw new InvalidOperationException($"自动巡检逻辑处理异常:{ex.Message}");
}
}
@@ -134,9 +188,9 @@ namespace SlnMesnac.Business
//这里采集数据
_log.Info($"5S后开始测温");
Task.Delay(5000).Wait();
- _log.Info($"最高温度:{_realTemperatureInfo.fMaxTemperature};最低温度:{_realTemperatureInfo.fMinTemperature};平均温度:{_realTemperatureInfo.fAverageTemperature};温差:{_realTemperatureInfo.fTemperatureDiff}");
+ _log.Info($"温度测量完成,最高温度:{_realTemperatureInfo.fMaxTemperature};最低温度:{_realTemperatureInfo.fMinTemperature};平均温度:{_realTemperatureInfo.fAverageTemperature};温差:{_realTemperatureInfo.fTemperatureDiff}");
+ this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo);
Task.Delay(1000).Wait();
- _log.Info($"温度测量完成");
}
}
@@ -177,5 +231,50 @@ namespace SlnMesnac.Business
}
}
+ ///
+ /// 保存母排测温数据
+ ///
+ ///
+ ///
+ ///
+ private void SaveBusbarTemp(int? busbarCode, int? cabinetCode,RealTemperatureInfo realTemperatureInfo)
+ {
+ try
+ {
+
+ var record = new record_busbar_temp()
+ {
+ busbarCode = busbarCode,
+ cabinetCode = cabinetCode,
+ tempMax = (decimal)realTemperatureInfo.fMaxTemperature,
+ tempMin = (decimal)realTemperatureInfo.fMinTemperature,
+ tempAvg = (decimal)realTemperatureInfo.fAverageTemperature,
+ tempDiff = (decimal)realTemperatureInfo.fTemperatureDiff,
+ recordTime = DateTime.Now,
+ };
+
+ if (realTemperatureInfo.fMaxTemperature > 65)
+ {
+ record.isAlarm = 1;
+ string sJpegPicFileName = $"{cabinetCode}_{busbarCode}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg";
+ record.filePath = sJpegPicFileName ;
+ CaptureAlarmPictureEvent?.Invoke(sJpegPicFileName);
+ }
+ var res = _record_busbar_TempServices.Insert(record);
+
+ if (res)
+ {
+ _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存成功");
+ }
+ else
+ {
+ _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存失败");
+ }
+ }catch(Exception e)
+ {
+ _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存异常:{e.Message}");
+ }
+ }
+
}
}
diff --git a/SlnMesnac.Business/InspModeBusiness.cs b/SlnMesnac.Business/InspModeBusiness.cs
new file mode 100644
index 0000000..afe8aca
--- /dev/null
+++ b/SlnMesnac.Business/InspModeBusiness.cs
@@ -0,0 +1,59 @@
+using SlnMesnac.Business.@base;
+using SlnMesnac.Plc;
+using SlnMesnac.Repository;
+using SlnMesnac.Repository.service;
+using SlnMesnac.Serilog;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:T14-GEN3-7895
+* 命名空间:SlnMesnac.Business
+* 唯一标识:73cd3d99-8387-4ff6-9276-8eeb424e2aa2
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2024-11-07 9:51:55
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Business
+{
+ ///
+ /// Inspection mode 巡检模式
+ ///
+ public class InspModeBusiness : BaseBusiness
+ {
+ private readonly Irecord_inspection_cabinetServices _service;
+ public InspModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_inspection_cabinetServices service) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices)
+ {
+ _service = service;
+ }
+
+ public void Start(string taskCode,string filePath)
+ {
+ record_inspection_cabinet record_Inspection = new record_inspection_cabinet();
+ record_Inspection.taskCode = taskCode;
+ record_Inspection.filePath = filePath;
+ record_Inspection.beginTime = DateTime.Now;
+ _service.Insert(record_Inspection);
+ }
+
+ public void Stop(string taskCode, string filePath)
+ {
+
+ }
+ }
+}
diff --git a/SlnMesnac.Business/ManualModeBusiness.cs b/SlnMesnac.Business/ManualModeBusiness.cs
new file mode 100644
index 0000000..167bd8a
--- /dev/null
+++ b/SlnMesnac.Business/ManualModeBusiness.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:T14-GEN3-7895
+* 命名空间:SlnMesnac.Business
+* 唯一标识:04146a2b-c51d-4164-8c51-158a99301078
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2024-11-07 9:52:46
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Business
+{
+ ///
+ /// 手动模式
+ ///
+ internal class ManualModeBusiness
+ {
+ }
+}
diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs
index 684c1c9..17ebc56 100644
--- a/SlnMesnac.Business/base/BaseBusiness.cs
+++ b/SlnMesnac.Business/base/BaseBusiness.cs
@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
+using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@@ -55,7 +56,7 @@ namespace SlnMesnac.Business.@base
///
/// 工作模式:1-自动;2-巡检;3-手动
///
- public void InitEquip(int model)
+ public async void InitEquip(int model)
{
try
{
@@ -66,6 +67,7 @@ namespace SlnMesnac.Business.@base
if (plcFlag != 1)
{
_log.Info($"PLC状态不具备启动条件:VD1509值为{plcFlag}");
+ Task.Delay(1000).Wait();
continue;
}
diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs
index 4edd9eb..23d4665 100644
--- a/SlnMesnac.Config/AppConfig.cs
+++ b/SlnMesnac.Config/AppConfig.cs
@@ -52,6 +52,11 @@ namespace SlnMesnac.Config
///
public string videoFilePath { get; set; }
+ ///
+ /// 巡检周期
+ ///
+ public int checkCycle { get; set; }
+
///
/// Sql连接配置
///
diff --git a/SlnMesnac.Generate/Templates/Service/Impl/Services.vm b/SlnMesnac.Generate/Templates/Service/Impl/Services.vm
index bcf9a49..e6c2367 100644
--- a/SlnMesnac.Generate/Templates/Service/Impl/Services.vm
+++ b/SlnMesnac.Generate/Templates/Service/Impl/Services.vm
@@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace ${NameSpace}.service.Impl
{
- public class ${tableName}ServiceImpl : BaseServiceImpl<${tableName}>, I${tableName}Service
+ public class ${tableName}ServiceImpl : BaseServiceImpl<${tableName}>, I${tableName}Services
{
public ${tableName}ServiceImpl(Repository<${tableName}> repository):base(repository)
{
diff --git a/SlnMesnac.Model/domain/record_busbar_temp.cs b/SlnMesnac.Model/domain/record_busbar_temp.cs
new file mode 100644
index 0000000..8925612
--- /dev/null
+++ b/SlnMesnac.Model/domain/record_busbar_temp.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace SlnMesnac.Repository
+{
+ ///
+ ///母排测温信息
+ ///
+ [SugarTable("record_busbar_temp"), TenantAttribute("iot")]
+ public partial class record_busbar_temp
+ {
+ public record_busbar_temp(){
+
+
+ }
+ ///
+ /// Desc:标识
+ /// Default:
+ /// Nullable:False
+ ///
+ [SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="objId")]
+ public int objid {get;set;}
+
+ ///
+ /// Desc:母排编号
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="busbar_code")]
+ public int? busbarCode {get;set;}
+
+ ///
+ /// Desc:电柜编号
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="cabinet_code")]
+ public int? cabinetCode {get;set;}
+
+ ///
+ /// Desc:最高温度
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="temp_max")]
+ public decimal? tempMax {get;set;}
+
+ ///
+ /// Desc:最低温度
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="temp_min")]
+ public decimal? tempMin {get;set;}
+
+ ///
+ /// Desc:平均温度
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="temp_avg")]
+ public decimal? tempAvg {get;set;}
+
+ ///
+ /// Desc:温差
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="temp_diff")]
+ public decimal? tempDiff {get;set;}
+
+ ///
+ /// Desc:是否告警:1-是;0-否
+ /// Default:0
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="is_alarm")]
+ public int? isAlarm {get;set;}
+
+ ///
+ /// Desc:图像路径
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="file_path")]
+ public string filePath {get;set;}
+
+ ///
+ /// Desc:是否启用:1-是;0-否
+ /// Default:0
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="is_flag")]
+ public int? isFlag {get;set;}
+
+ ///
+ /// Desc:备注
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="remark")]
+ public string remark {get;set; }
+
+ ///
+ /// 记录时间
+ ///
+ [SugarColumn(ColumnName = "record_time")]
+ public DateTime? recordTime { get; set; }
+
+ ///
+ /// Desc:创建人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_by")]
+ public string createdBy {get;set;}
+
+ ///
+ /// Desc:创建时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_time")]
+ public DateTime? createdTime {get;set;}
+
+ ///
+ /// Desc:更新人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_by")]
+ public string updatedBy {get;set;}
+
+ ///
+ /// Desc:更新时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_time")]
+ public DateTime? updatedTime {get;set;}
+
+ }
+}
diff --git a/SlnMesnac.Model/domain/record_inspection_cabinet.cs b/SlnMesnac.Model/domain/record_inspection_cabinet.cs
new file mode 100644
index 0000000..a2de4d9
--- /dev/null
+++ b/SlnMesnac.Model/domain/record_inspection_cabinet.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace SlnMesnac.Repository
+{
+ ///
+ ///电柜巡检记录
+ ///
+ [SugarTable("record_inspection_cabinet"), TenantAttribute("iot")]
+ public partial class record_inspection_cabinet
+ {
+ public record_inspection_cabinet(){
+
+
+ }
+ ///
+ /// Desc:标识
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "obj_id")]
+ public int? objId {get;set;}
+
+ ///
+ /// Desc:任务编号
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="task_code")]
+ public string taskCode {get;set;}
+
+ ///
+ /// Desc:开始时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="begin_time")]
+ public DateTime? beginTime {get;set;}
+
+ ///
+ /// Desc:结束时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="end_time")]
+ public DateTime? endTime {get;set;}
+
+ ///
+ /// Desc:文件路径
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="file_path")]
+ public string filePath {get;set;}
+
+ ///
+ /// Desc:创建人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_by")]
+ public string createdBy {get;set;}
+
+ ///
+ /// Desc:创建时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_time")]
+ public DateTime? createdTime {get;set;}
+
+ ///
+ /// Desc:更新人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_by")]
+ public string updatedBy {get;set;}
+
+ ///
+ /// Desc:更新时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_time")]
+ public DateTime? updatedTime {get;set;}
+
+ }
+}
diff --git a/SlnMesnac.Repository/service/IRecord_busbar_tempService.cs b/SlnMesnac.Repository/service/IRecord_busbar_tempService.cs
new file mode 100644
index 0000000..b393ff0
--- /dev/null
+++ b/SlnMesnac.Repository/service/IRecord_busbar_tempService.cs
@@ -0,0 +1,13 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SlnMesnac.Repository.service
+{
+ public interface Irecord_busbar_tempServices: IBaseService
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/IRecord_inspection_cabinetService.cs b/SlnMesnac.Repository/service/IRecord_inspection_cabinetService.cs
new file mode 100644
index 0000000..3e741ce
--- /dev/null
+++ b/SlnMesnac.Repository/service/IRecord_inspection_cabinetService.cs
@@ -0,0 +1,13 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SlnMesnac.Repository.service
+{
+ public interface Irecord_inspection_cabinetServices: IBaseService
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/Impl/Record_busbar_tempServiceImpl.cs b/SlnMesnac.Repository/service/Impl/Record_busbar_tempServiceImpl.cs
new file mode 100644
index 0000000..918f4b8
--- /dev/null
+++ b/SlnMesnac.Repository/service/Impl/Record_busbar_tempServiceImpl.cs
@@ -0,0 +1,14 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System;
+using System.Collections.Generic;
+
+namespace SlnMesnac.Repository.service.Impl
+{
+ public class record_busbar_tempServiceImpl : BaseServiceImpl, Irecord_busbar_tempServices
+ {
+ public record_busbar_tempServiceImpl(Repository repository):base(repository)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.Repository/service/Impl/Record_inspection_cabinetServiceImpl.cs b/SlnMesnac.Repository/service/Impl/Record_inspection_cabinetServiceImpl.cs
new file mode 100644
index 0000000..de8e83e
--- /dev/null
+++ b/SlnMesnac.Repository/service/Impl/Record_inspection_cabinetServiceImpl.cs
@@ -0,0 +1,14 @@
+using SlnMesnac.Model.domain;
+using SlnMesnac.Repository.service.@base;
+using System;
+using System.Collections.Generic;
+
+namespace SlnMesnac.Repository.service.Impl
+{
+ public class record_inspection_cabinetServiceImpl : BaseServiceImpl, Irecord_inspection_cabinetServices
+ {
+ public record_inspection_cabinetServiceImpl(Repository repository):base(repository)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml b/SlnMesnac.WPF/Page/IndexControl.xaml
index d7567fe..0ccba6d 100644
--- a/SlnMesnac.WPF/Page/IndexControl.xaml
+++ b/SlnMesnac.WPF/Page/IndexControl.xaml
@@ -38,7 +38,7 @@
-
+
@@ -47,7 +47,7 @@
-
+
@@ -115,8 +115,12 @@
-
-
+
+
+
+
+
+
@@ -412,7 +416,7 @@ Canvas.Left="175" Canvas.Top="155" Stroke="Transparent" StrokeThickness="1">
-
+
@@ -427,7 +431,7 @@ Canvas.Left="175" Canvas.Top="155" Stroke="Transparent" StrokeThickness="1">
-
+
@@ -562,11 +566,11 @@ Canvas.Left="175" Canvas.Top="155" Stroke="Transparent" StrokeThickness="1">
-
+
-
+
diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml.cs b/SlnMesnac.WPF/Page/IndexControl.xaml.cs
index 79fecbf..c565d48 100644
--- a/SlnMesnac.WPF/Page/IndexControl.xaml.cs
+++ b/SlnMesnac.WPF/Page/IndexControl.xaml.cs
@@ -18,6 +18,7 @@ using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
+using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
@@ -34,7 +35,8 @@ namespace SlnMesnac.WPF.Page
private IndexControlViewModel indexControlViewModel = new IndexControlViewModel();
private SerilogHelper serilogHelper = null;
private AppConfig _appConfig = null;
- private AutoTaskBusiness taskBusiness = null;
+ private AutoModeBusiness taskBusiness = null;
+ private InspModeBusiness inspModeBusiness = null;
private bool m_bInitSDK = false;
private Int32 m_lUserID = -1;
@@ -58,11 +60,22 @@ namespace SlnMesnac.WPF.Page
this.DataContext = indexControlViewModel;
serilogHelper = App.ServiceProvider.GetService();
_appConfig = App.ServiceProvider.GetService();
- taskBusiness = App.ServiceProvider.GetService();
+ taskBusiness = App.ServiceProvider.GetService();
+ inspModeBusiness = App.ServiceProvider.GetService();
_callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback);
- Task.Run(() =>
+
+
+ Open_Device();
+
+ taskBusiness.CaptureAlarmPictureEvent += CapturePicture;
+ }
+
+
+ private void Open_Device()
+ {
+ try
{
- App.Current.Dispatcher.Invoke(() =>
+ Task.Run(() =>
{
m_bInitSDK = CHCNetSDK.NET_DVR_Init();
if (m_bInitSDK == false)
@@ -77,48 +90,42 @@ namespace SlnMesnac.WPF.Page
DebugInfo("热成像双光谱微型云台初始化成功!");
}
- Open_Device();
- });
- });
- }
-
- private void Open_Device()
- {
- try
- {
- m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
+ m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
- if (m_lUserID < 0)
- {
- string str = "热成像双光谱微型云台打开失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ; //登录失败,输出错误号 Failed to login and output the error code
- DebugInfo(str);
- }
- else
- {
- //登录成功
- DebugInfo("热成像双光谱微型云台打开成功!");
-
- Start_Grab(); //打开实时预览
-
- ///
- /// 加载实时温度数据
- ///
- var size = Marshal.SizeOf(typeof(CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND));
- CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = new CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
- struThermCond.dwSize = (uint)size;
- struThermCond.byRuleID = 0; //规则ID,0代表获取全部规则,具体规则ID从1开始
- struThermCond.dwChan = 2;// dwChannel; //从1开始,0xffffffff代表获取全部通道
-
- IntPtr pCond = Marshal.AllocCoTaskMem(size);
- Marshal.StructureToPtr(struThermCond, pCond, false);
- var ret = NET_DVR_StartRemoteConfig(m_lUserID, NET_DVR_GET_REALTIME_THERMOMETRY, pCond, size, _callback, IntPtr.Zero);
- if (ret < 0)
+ if (m_lUserID < 0)
{
- DebugInfo("配置测温失败, 错误代码:" + NET_DVR_GetLastError()); //登录失败,输出错误号
- return;
+ string str = "热成像双光谱微型云台打开失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ; //登录失败,输出错误号 Failed to login and output the error code
+ DebugInfo(str);
}
- }
+ else
+ {
+ //登录成功
+ DebugInfo("热成像双光谱微型云台打开成功!");
+
+ //SceneryPreview();
+ //ThermalPreview();
+
+ ///
+ /// 加载实时温度数据
+ ///
+ var size = Marshal.SizeOf(typeof(CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND));
+ CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = new CHCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
+ struThermCond.dwSize = (uint)size;
+ struThermCond.byRuleID = 0; //规则ID,0代表获取全部规则,具体规则ID从1开始
+ struThermCond.dwChan = 2;// dwChannel; //从1开始,0xffffffff代表获取全部通道
+
+ IntPtr pCond = Marshal.AllocCoTaskMem(size);
+ Marshal.StructureToPtr(struThermCond, pCond, false);
+ var ret = NET_DVR_StartRemoteConfig(m_lUserID, NET_DVR_GET_REALTIME_THERMOMETRY, pCond, size, _callback, IntPtr.Zero);
+ if (ret < 0)
+ {
+ DebugInfo("配置测温失败, 错误代码:" + NET_DVR_GetLastError()); //登录失败,输出错误号
+ return;
+ }
+ }
+ });
+
}
catch (Exception ex)
{
@@ -126,155 +133,152 @@ namespace SlnMesnac.WPF.Page
}
}
+ ///
+ /// 测温回调函数
+ ///
+ ///
+ ///
+ ///
+ ///
public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
{
var ret = Marshal.PtrToStructure(lpBuffer);
- //DebugInfo($"最高温度:{ret.struLinePolygonThermCfg.fMaxTemperature};最低温度:{ret.struLinePolygonThermCfg.fMinTemperature};平均温度:{ret.struLinePolygonThermCfg.fAverageTemperature};温差:{ret.struLinePolygonThermCfg.fTemperatureDiff}");
-
taskBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1);
- taskBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature, 1);
+ taskBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature);
taskBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1);
taskBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1);
- indexControlViewModel.RefreshRealTemperature(taskBusiness._realTemperatureInfo);
-
-
- if (taskBusiness._realTemperatureInfo.fMaxTemperature > 65)
+ var real = new RealTemperatureInfo()
{
- string sJpegPicFileName = $"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg";
- for (int i = 1; 1 < 3; i++){
- CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
- lpJpegPara.wPicQuality = 0;
- lpJpegPara.wPicSize = 0xff;
- var path = string.Empty;
- if (i == 1)
- {
- path = $"{_appConfig.visibleRangePath}\\{sJpegPicFileName}";
- }
- else
- {
- path = $"{_appConfig.infraredImagePath}\\{sJpegPicFileName}";
- }
+ fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1),
+ fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature, 1),
+ fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1),
+ fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1),
+ };
- //JPEG抓图 Capture a JPEG picture
- if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, i, ref lpJpegPara, path))
- {
- var str = "高温报警,图像信息保存失败, error code= " + NET_DVR_GetLastError();
- DebugInfo(str);
- return;
- }
- else
- {
- var str = "高温报警,图像信息保存成功: " + path;
- DebugInfo(str);
- }
- }
- }
+ indexControlViewModel.RefreshRealTemperature(real);
}
-
- private void RealHandle_1()
+ ///
+ /// 抓拍图像
+ ///
+ ///
+ public void CapturePicture(string sJpegPicFileName)
{
- try
+ for (int i = 1; i < 3; i++)
{
- CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
- lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle;//预览窗口 live view window
- lpPreviewInfo.lChannel = 1;//预览的设备通道 the device channel number
- lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
- lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
- lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流
- lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数
-
- IntPtr pUser = IntPtr.Zero;//用户数据 user data
-
- m_lRealHandle_1 = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
+ CHCNetSDK.NET_DVR_JPEGPARA lpJpegPara = new CHCNetSDK.NET_DVR_JPEGPARA();
+ lpJpegPara.wPicQuality = 0;
+ lpJpegPara.wPicSize = 0xff;
+ var path = string.Empty;
+ if (i == 1)
+ {
+ path = $"{_appConfig.visibleRangePath}\\{sJpegPicFileName}";
+ }
+ else
+ {
+ path = $"{_appConfig.infraredImagePath}\\{sJpegPicFileName}";
+ }
- if (m_lRealHandle_1 < 0)
+ if (!CHCNetSDK.NET_DVR_CaptureJPEGPicture(m_lUserID, i, ref lpJpegPara, path))
{
- var str = "光景图像预览加载失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); //预览失败,输出错误号 failed to start live view, and output the error code.
+ var str = "高温报警,图像信息保存失败, error code= " + NET_DVR_GetLastError();
DebugInfo(str);
+ return;
}
else
{
- //预览成功
- DebugInfo("光景图像预览加载成功!");
+ var str = "高温报警,图像信息保存成功: " + path;
+ DebugInfo(str);
}
}
- catch (Exception ex)
- {
-
- serilogHelper.Camera($"光景图像预览加载异常:{ex.Message}");
- }
}
- private void RealHandle_2()
+ ///
+ /// 可见光预览
+ ///
+ private void SceneryPreview()
{
try
{
- CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
- lpPreviewInfo.hPlayWnd = RealPlayWnd2.Handle;//预览窗口 live view window
- lpPreviewInfo.lChannel = 2;//预览的设备通道 the device channel number
- lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
- lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
- lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流
- lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数
+ App.Current.Dispatcher.Invoke(() =>
+ {
+ CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
+ lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle;//预览窗口 live view window
+ lpPreviewInfo.lChannel = 1;//预览的设备通道 the device channel number
+ lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
+ lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
+ lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流
+ lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数
- IntPtr pUser = IntPtr.Zero;//用户数据 user data
+ IntPtr pUser = IntPtr.Zero;//用户数据 user data
- m_lRealHandle_2 = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
+ m_lRealHandle_1 = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
- if (m_lRealHandle_2 < 0)
- {
- var str = "热成像预览加载失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); //预览失败,输出错误号 failed to start live view, and output the error code.
- DebugInfo(str);
- }
- else
- {
- //预览成功
- DebugInfo("热成像预览加载成功!");
- }
+ if (m_lRealHandle_1 < 0)
+ {
+ var str = "光景图像预览加载失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); //预览失败,输出错误号 failed to start live view, and output the error code.
+ DebugInfo(str);
+ }
+ else
+ {
+ //预览成功
+ DebugInfo("光景图像预览加载成功!");
+ }
+ });
+
}
catch (Exception ex)
{
- serilogHelper.Camera($"热成像图像预览加载异常:{ex.Message}");
+ serilogHelper.Camera($"光景图像预览加载异常:{ex.Message}");
}
}
-
- private void Start_Grab()
- {
- RealHandle_1();
- RealHandle_2();
- }
-
- private void Stop_Grab()
+ ///
+ /// 热成像预览
+ ///
+ private void ThermalPreview()
{
- if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle_1))
- {
- var str = "NET_DVR_StopRealPlay failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ;
- DebugInfo(str);
- return;
- }
- else
+ try
{
- DebugInfo("NET_DVR_StopRealPlay succ!");
- RealPlayWnd.Invalidate();//刷新窗口 refresh the window
- }
+ App.Current.Dispatcher.Invoke(() =>
+ {
+ CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
+ lpPreviewInfo.hPlayWnd = RealPlayWnd2.Handle;//预览窗口 live view window
+ lpPreviewInfo.lChannel = 2;//预览的设备通道 the device channel number
+ lpPreviewInfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
+ lpPreviewInfo.dwLinkMode = 0;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
+ lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流
+ lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数
- if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle_2))
- {
- var str = "NET_DVR_StopRealPlay failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ;
- DebugInfo(str);
- return;
+ IntPtr pUser = IntPtr.Zero;//用户数据 user data
+
+ m_lRealHandle_2 = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
+
+ if (m_lRealHandle_2 < 0)
+ {
+ var str = "热成像预览加载失败, error code= " + CHCNetSDK.NET_DVR_GetLastError(); //预览失败,输出错误号 failed to start live view, and output the error code.
+ DebugInfo(str);
+ }
+ else
+ {
+ //预览成功
+ DebugInfo("热成像预览加载成功!");
+ }
+ });
+
}
- else
+ catch (Exception ex)
{
- DebugInfo("NET_DVR_StopRealPlay succ!");
- RealPlayWnd2.Invalidate();//刷新窗口 refresh the window
+
+ serilogHelper.Camera($"热成像图像预览加载异常:{ex.Message}");
}
}
+ ///
+ /// 关闭设备
+ ///
private void Close_Device()
{
if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
@@ -286,11 +290,16 @@ namespace SlnMesnac.WPF.Page
DebugInfo("NET_DVR_Logout succ!");
}
+ ///
+ /// 日志记录
+ ///
+ ///
private void DebugInfo(string str)
{
serilogHelper.Camera(str);
}
+ #region 云台控制
private void btnUp_MouseDown(object sender, MouseButtonEventArgs e)
{
CHCNetSDK.NET_DVR_PTZControlWithSpeed(m_lRealHandle_1, CHCNetSDK.TILT_UP, 0, 4);
@@ -329,8 +338,14 @@ namespace SlnMesnac.WPF.Page
private void btnRight_MouseUp(object sender, MouseButtonEventArgs e)
{
CHCNetSDK.NET_DVR_PTZControlWithSpeed(m_lRealHandle_1, CHCNetSDK.PAN_RIGHT, 1, 4);
- }
+ }
+ #endregion
+ ///
+ /// 云台回零点
+ ///
+ ///
+ ///
private void btn_ptz_set_Click(object sender, RoutedEventArgs e)
{
@@ -390,22 +405,29 @@ namespace SlnMesnac.WPF.Page
}
}
- private bool is_automatic = false;
+ private bool is_insp_model = false;
///
- ///
+ /// 巡检模式
///
///
///
- private void btn_automatic_MouseDown(object sender, MouseButtonEventArgs e)
+ private void btn_inspmode_MouseDown(object sender, MouseButtonEventArgs e)
{
- if (!is_automatic)
+ if (!is_insp_model)
{
- MessageBox.Show("巡检模式开启");
+
+ if (is_auto_model)
+ {
+ MessageBox.Show("当前处于自动模式中,请先关闭自动模式,再开启巡检模式");
+ return;
+ }
+
btn_automatic.Background = new SolidColorBrush(Colors.LightBlue);
- is_automatic = true;
- string fileName = $"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.mp4";
+ is_insp_model = true;
+ string taskCode = DateTime.Now.ToString("yyyyMMddHHmmssffff");
+ string fileName = $"{taskCode}.mp4";
Task.Run(() =>
{
var url = $"{_appConfig.videoFilePath}\\可见光\\{fileName}";
@@ -437,12 +459,14 @@ namespace SlnMesnac.WPF.Page
DebugInfo($"热成像通道开启巡检录像成功");
}
});
+
+ inspModeBusiness.Start(taskCode, fileName);
}
else
{
//MessageBox.Show("巡检模式关闭");
btn_automatic.Background = new SolidColorBrush(Colors.Transparent);
- is_automatic = false;
+ is_insp_model = false;
Task.Run(() =>
@@ -475,20 +499,74 @@ namespace SlnMesnac.WPF.Page
}
}
- private bool is_autotask = false;
- private void btn_autotask_MouseDown(object sender, MouseButtonEventArgs e)
+ private bool is_auto_model = false;
+ private void btn_automode_MouseDown(object sender, MouseButtonEventArgs e)
{
- if (!is_autotask)
+ if (!is_auto_model)
{
+ if (is_insp_model)
+ {
+ MessageBox.Show("当前处于巡检模式中,请先关闭巡检模式,再开启自动模式");
+ }
btn_autotask.Background = new SolidColorBrush(Colors.LightBlue);
- is_autotask = true;
- taskBusiness.AutoCheckHandle();
+ is_auto_model = true;
+ taskBusiness.Start();
}
else
{
btn_autotask.Background = new SolidColorBrush(Colors.Transparent);
- is_autotask = false;
+ is_auto_model = false;
+ taskBusiness.Stop();
+
+ }
+ }
+ ///
+ /// 开启预览
+ ///
+ ///
+ ///
+ private void btn_start_preview_Click(object sender, RoutedEventArgs e)
+ {
+ if (m_lRealHandle_1 > 0 || m_lRealHandle_2 > 0)
+ {
+ MessageBox.Show("实时预览已开启,请勿重复开启");
+ return;
+ }
+ SceneryPreview();
+ ThermalPreview();
+ }
+
+ ///
+ /// 停止预览
+ ///
+ ///
+ ///
+ private void btn_stop_preview_Click(object sender, RoutedEventArgs e)
+ {
+ if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle_1))
+ {
+ var str = "NET_DVR_StopRealPlay failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ;
+ DebugInfo(str);
+ return;
+ }
+ else
+ {
+ DebugInfo("NET_DVR_StopRealPlay succ!");
+ RealPlayWnd.Invalidate();//刷新窗口 refresh the window
+ }
+
+ if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle_2))
+ {
+ var str = "NET_DVR_StopRealPlay failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ;
+ DebugInfo(str);
+ return;
+ }
+ else
+ {
+ DebugInfo("NET_DVR_StopRealPlay succ!");
+ RealPlayWnd2.Invalidate();//刷新窗口 refresh the window
+ m_lRealHandle_2 = 0;
}
}
}
diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json
index eef84a1..7d543f0 100644
--- a/SlnMesnac.WPF/appsettings.json
+++ b/SlnMesnac.WPF/appsettings.json
@@ -12,6 +12,7 @@
"visibleRangePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\可见光图像",
"infraredImagePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\红外热成像",
"videoFilePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\巡检录像",
+ "checkCycle": 5,
"SqlConfig": [
{
"configId": "iot",