change - 添加相机避障报警并写入PLC

master
wenjy 2 months ago
parent 09d6e3b94b
commit 0f8dc104e9

@ -407,5 +407,15 @@ namespace SlnMesnac.Business
_log.Info($"工作模式:取消写入PLC成功VD1536写0");
}
public void SendCameraAlarmToPlc()
{
if (!_plc.writeInt32ByAddress("VD1550", 1))
{
throw new ArgumentException($"相机避障报警写入PLC失败VD1550写1");
}
_log.Info($"相机避障报警写入PLC成功VD1550写1");
}
}
}

@ -10,6 +10,7 @@ using SlnMesnac.Model.dto;
using SlnMesnac.Serilog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -54,6 +55,7 @@ namespace SlnMesnac.WPF.ViewModel
private AppConfig _appConfig;
private CHCNetSDK.RemoteConfigCallback _callback;
private CHCNetSDK.MSGCallBack_V31 m_falarmData_V31;
public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
private bool m_bInitSDK = false;
@ -72,6 +74,7 @@ namespace SlnMesnac.WPF.ViewModel
{
_log = App.ServiceProvider.GetService<SerilogHelper>();
_callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback);
m_falarmData_V31 = new CHCNetSDK.MSGCallBack_V31(MsgCallback_V31);
_appConfig = App.ServiceProvider.GetService<AppConfig>();
autoModeBusiness = App.ServiceProvider.GetService<AutoModeBusiness>();
inspModeBusiness = App.ServiceProvider.GetService<InspModeBusiness>();
@ -88,7 +91,8 @@ namespace SlnMesnac.WPF.ViewModel
inspModeBusiness.GimbaRotationControlEvent += GimbaRotationControl;
RefreshTrackMotorAddress();
}catch (Exception ex)
}
catch (Exception ex)
{
_log.Error("巡检控制系统初始化失败", ex);
MessageBox.Show($"巡检控制系统初始化失败:{ex.Message}");
@ -191,6 +195,38 @@ namespace SlnMesnac.WPF.ViewModel
return;
}
///
/// 报警布防
///
//设置透传报警信息类型
CHCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struLocalCfg = new CHCNetSDK.NET_DVR_LOCAL_GENERAL_CFG();
struLocalCfg.byAlarmJsonPictureSeparate = 1;//控制JSON透传报警数据和图片是否分离0-不分离(COMM_VCA_ALARM返回)1-分离分离后走COMM_ISAPI_ALARM回调返回
Int32 nSize = Marshal.SizeOf(struLocalCfg);
IntPtr ptrLocalCfg = Marshal.AllocHGlobal(nSize);
Marshal.StructureToPtr(struLocalCfg, ptrLocalCfg, false);
if (!CHCNetSDK.NET_DVR_SetSDKLocalCfg(17, ptrLocalCfg)) //NET_DVR_LOCAL_CFG_TYPE_GENERAL
{
MessageBox.Show("NET_DVR_SetSDKLocalCfg failed, error code= " + CHCNetSDK.NET_DVR_GetLastError());
}
Marshal.FreeHGlobal(ptrLocalCfg);
CHCNetSDK.NET_DVR_SETUPALARM_PARAM struAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
struAlarmParam.dwSize = (uint)Marshal.SizeOf(struAlarmParam);
struAlarmParam.byLevel = 1; //0- 一级布防,1- 二级布防
struAlarmParam.byAlarmInfoType = 1;//智能交通设备有效,新报警信息类型
struAlarmParam.byFaceAlarmDetection = 1;//1-人脸侦测
var m_lAlarmHandle = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(m_lUserID, ref struAlarmParam);
if (m_lAlarmHandle < 0)
{
_log.Info("布防失败,错误号::" + CHCNetSDK.NET_DVR_GetLastError());
}
var res = CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(m_falarmData_V31, IntPtr.Zero);
}
});
@ -565,7 +601,8 @@ namespace SlnMesnac.WPF.ViewModel
//Marshal.FreeHGlobal(ptrPtzCfg);
}
}catch(Exception ex)
}
catch (Exception ex)
{
_log.Info($"云台旋转控制异常:{ex.Message}");
}
@ -660,5 +697,51 @@ namespace SlnMesnac.WPF.ViewModel
});
}
public bool MsgCallback_V31(int lCommand, ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
{
AlarmMessageHandle(lCommand, ref pAlarmer, pAlarmInfo, dwBufLen, pUser);
return true;
}
public void AlarmMessageHandle(int lCommand, ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
{
switch (lCommand)
{
case CHCNetSDK.COMM_ISAPI_ALARM://ISAPI报警信息上传
ProcessCommAlarm_ISAPIAlarm(ref pAlarmer, pAlarmInfo, dwBufLen, pUser);
break;
default:
{
string strIP = System.Text.Encoding.UTF8.GetString(pAlarmer.sDeviceIP).TrimEnd('\0');
string stringAlarm = "报警上传信息类型0x" + Convert.ToString(lCommand, 16);
Console.WriteLine(stringAlarm);
}
break;
}
}
private void ProcessCommAlarm_ISAPIAlarm(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
{
try
{
CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO struISAPIAlarm = new CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO();
uint dwSize = (uint)Marshal.SizeOf(struISAPIAlarm);
struISAPIAlarm = (CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_DVR_ALARM_ISAPI_INFO));
string stringAlarm = $"ISAPI报警信息byDataType{struISAPIAlarm.byDataType}";
_log.Info($"云台避障报警:{stringAlarm}");
autoModeBusiness.SendCameraAlarmToPlc();
}catch(Exception e)
{
_log.Info($"云台避障报警逻辑处理异常:{e.Message}");
}
}
}
}

@ -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