change - 添加云台相机预览

master
wenjy 3 months ago
parent 9400542d52
commit eedd24b5d5

@ -59,6 +59,9 @@ namespace SlnMesnac.Serilog
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc"))
.WriteTo.File(Path.Combine(logPath, "Plc.log")))
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Camera"))
.WriteTo.File(Path.Combine(logPath, "Camera.log")))
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error"))
.WriteTo.File(Path.Combine(logPath, "Error.log")))

@ -35,6 +35,7 @@ namespace SlnMesnac.Serilog
private readonly ILogger? Info_logger = Log.ForContext("Module", "Info");
private readonly ILogger? Plc_logger = Log.ForContext("Module", "Plc");
private readonly ILogger? Error_logger = Log.ForContext("Module", "Error");
private readonly ILogger? Camera_logger = Log.ForContext("Module", "Camera");
/// <summary>
/// Info日志
@ -60,6 +61,18 @@ namespace SlnMesnac.Serilog
}
}
/// <summary>
/// 相机日志
/// </summary>
/// <param name="msg"></param>
public void Camera(string msg)
{
if (Camera_logger != null)
{
this.Camera_logger.Information(msg);
}
}
/// <summary>
/// Error日志
/// </summary>

@ -14,7 +14,7 @@ namespace SlnMesnac.WPF
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : System.Windows.Application
{
private System.Threading.Mutex? mutex = null;
private LierdaCracker cracker = new LierdaCracker();

File diff suppressed because it is too large Load Diff

@ -3,6 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wfCtrl="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:wfHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page"
mc:Ignorable="d"
d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent">
@ -23,8 +25,16 @@
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="#FFFFFF" CornerRadius="5" Margin="0,0,10,0"></Border>
<Border Grid.Column="1" Background="#FFFFFF" CornerRadius="5" Margin="10,0,0,0"></Border>
<Border Grid.Column="0" Background="#FFFFFF" CornerRadius="5" Margin="0,0,10,0">
<wfHost:WindowsFormsHost x:Name="DisplayWindow" Grid.ColumnSpan="2" IsEnabled="True" Background="Black">
<wfCtrl:PictureBox x:Name="RealPlayWnd"/>
</wfHost:WindowsFormsHost>
</Border>
<Border Grid.Column="1" Background="#FFFFFF" CornerRadius="5" Margin="10,0,0,0">
<wfHost:WindowsFormsHost x:Name="DisplayWindow2" Grid.ColumnSpan="2" IsEnabled="True" Background="Black">
<wfCtrl:PictureBox x:Name="RealPlayWnd2"/>
</wfHost:WindowsFormsHost>
</Border>
</Grid>
</Border>

@ -1,5 +1,8 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Serilog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -20,9 +23,185 @@ namespace SlnMesnac.WPF.Page
/// </summary>
public partial class IndexControl : UserControl
{
private SerilogHelper serilogHelper = null;
private bool m_bInitSDK = false;
private Int32 m_lUserID = -1;
private Int32 m_lRealHandle_1 = -1;
private Int32 m_lRealHandle_2 = -1;
public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
private Int32 m_lTree = 0;
private string DVRIPAddress = "192.168.1.64"; //设备IP地址或者域名 Device IP
private Int16 DVRPortNumber = 8000; //设备服务端口号 Device Port
private string DVRUserName = "admin"; //设备登录用户名 User name to login
private string DVRPassword = "haiwei@2024"; //设备登录密码 Password to login
public IndexControl()
{
InitializeComponent();
serilogHelper = App.ServiceProvider.GetService<SerilogHelper>();
Task.Run(() =>
{
App.Current.Dispatcher.Invoke(() =>
{
m_bInitSDK = CHCNetSDK.NET_DVR_Init();
if (m_bInitSDK == false)
{
DebugInfo("热成像双光谱微型云台初始化失败 error!");
return;
}
else
{
//保存SDK日志 To save the SDK log
CHCNetSDK.NET_DVR_SetLogToFile(3, "C:\\SdkLog\\", true);
DebugInfo("热成像双光谱微型云台初始化成功 error!");
}
Open_Device();
});
});
}
private void Open_Device()
{
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();
}
}
private void RealHandle_1()
{
try
{
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-码流33-码流4以此类推
lpPreviewInfo.dwLinkMode = 0;//连接方式0- TCP方式1- UDP方式2- 多播方式3- RTP方式4-RTP/RTSP5-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);
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}");
}
}
private void RealHandle_2()
{
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-码流33-码流4以此类推
lpPreviewInfo.dwLinkMode = 0;//连接方式0- TCP方式1- UDP方式2- 多播方式3- RTP方式4-RTP/RTSP5-RSTP/HTTP
lpPreviewInfo.bBlocked = true; //0- 非阻塞取流1- 阻塞取流
lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数
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("热成像预览加载成功!");
}
}
catch (Exception ex)
{
serilogHelper.Camera($"热成像图像预览加载异常:{ex.Message}");
}
}
private void Start_Grab()
{
RealHandle_1();
RealHandle_2();
}
private void Stop_Grab()
{
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
}
}
private void Close_Device()
{
if (!CHCNetSDK.NET_DVR_Logout(m_lUserID))
{
var str = "NET_DVR_Logout failed, error code= " + CHCNetSDK.NET_DVR_GetLastError(); ;
DebugInfo(str);
return;
}
DebugInfo("NET_DVR_Logout succ!");
}
private void DebugInfo(string str)
{
serilogHelper.Camera(str);
}
}
}

@ -5,6 +5,7 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>

@ -67,16 +67,16 @@ namespace SlnMesnac.WPF
//启用Serilog中间件
app.UseSerilogExtensions();
app.UseTouchSocketExtensions();
//app.UseTouchSocketExtensions();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapControllers();
//});
}
}

Loading…
Cancel
Save