海康相机的报警输出是无源开关量信号
官方资料:https://hkrobot.hikvision.com/servlet/WBShow?action=sac&wbId=-100&sysNum=145716889796196&FromUserName=null&sId=325191&subId=136617
一、报警输入
二、报警输出
三、测试代码
public class CountPassengers
{
public static void ProcessCommAlarm(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
{
CHCNetSDK.NET_DVR_ALARMINFO struAlarmInfo = new CHCNetSDK.NET_DVR_ALARMINFO();
struAlarmInfo = (CHCNetSDK.NET_DVR_ALARMINFO)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_DVR_ALARMINFO));
if (struAlarmInfo.dwAlarmType == 0)
{
Console.WriteLine("状态:开盖儿");
}
else
{
Console.WriteLine(0);
}
}
public static void cbMessageCallback(int lCommand, ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
{
switch (lCommand)
{
case 16384: //(DS-8000老设备)移动侦测、视频丢失、遮挡、IO信号量等报警信息
ProcessCommAlarm(ref pAlarmer, pAlarmInfo, dwBufLen, pUser);
break;
}
}
public static void Main(string[] args)
{
Camera camera = new Camera();
camera.CameraIp = "192.168.99.1";
camera.CameraPort = 8000;
camera.Username = "admin";
camera.Password = "admin";
HKService service = new HKService();
HkCamera hkcamera = service.LoginCamera(camera);
/*bool enable = true;
ModelEnum modelEnum = ModelEnum.HK_MOVE_DETECTION;
List<HKRegionParam> hKRegionParams = new List<HKRegionParam>();
HkCameraManager.OrdinaryDetection(hkcamera,modelEnum,enable, hKRegionParams);*/
CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V50(1, (CHCNetSDK.MSGCallBack)cbMessageCallback, IntPtr.Zero);
// Set up alarm parameters
CHCNetSDK.NET_DVR_SETUPALARM_PARAM setupParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
setupParam.dwSize = (uint)Marshal.SizeOf(setupParam);
// Start receiving alarm messages
int alarmHandle = CHCNetSDK.NET_DVR_SetupAlarmChan_V41(hkcamera.UserId, ref setupParam);
if (alarmHandle < 0)
{
Console.WriteLine("NET_DVR_SetupAlarmChan_V41 error!");
CHCNetSDK.NET_DVR_Logout(hkcamera.UserId);
CHCNetSDK.NET_DVR_Cleanup();
return;
}
Console.WriteLine("Press any key to stop...");
int flag = 1;
while (true)
{
flag = (flag == 1) ? 0 : 1;
// 设置报警输出
CHCNetSDK.NET_DVR_SetAlarmOut(hkcamera.UserId, 0x00ff, flag);
Thread.Sleep(5000);
}
}
}