示例#1
0
        private void kPTZBtn_down_Click(object sender, EventArgs e)
        {
            HikvisionPTZControl hkPtzCtl = new HikvisionPTZControl();
            //根据选中的摄像头通道号跟IP地址进行预览
            string srtSql = "IP地址= '" + StaticData.g_CameraSelectNVRIP + "'";

            DataRow[] dr = StaticData.g_dtNVR.Select(srtSql);
            if (dr.Length > 0)
            {
                hkPtzCtl.PTZdown(Convert.ToInt32(dr[0]["userid"]), StaticData.g_CameraSelectChannel);
            }
        }
        /// <summary>
        /// 命令解析函数
        /// </summary>
        /// <param name="strJson"></param>
        /// <returns></returns>
        public string ReceiceJson(string strJson)
        {
            try
            {
                JsonObject joWebCmd      = (JsonObject)JsonValue.Parse(strJson);
                string     strResult     = "null";
                string     strResult2    = "null";
                string     strStatusCode = "0";
                string     strCmd        = "";
                #region 摄像头云台控制命令
                if (joWebCmd["requestType"] == "Camera")
                {
                    string strCameraNVRip   = joWebCmd["requestDetail"]["nvrip"];
                    string strCameraChannel = joWebCmd["requestDetail"]["channel"];
                    string strCameraCmd     = joWebCmd["requestDetail"]["command"];
                    //执行命令
                    HikvisionPTZControl hkPtzCtl = new HikvisionPTZControl();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    DataRow[] dr;
                    switch (strCameraCmd)
                    {
                    case "left":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "right":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "up":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZup(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "down":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdown(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZupleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_out":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomout(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_in":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomin(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  摄像头云台控制命令!\n" + "控制nvrip为:" + strCameraNVRip + "   通道号为:" + strCameraChannel + "   命令为:" + strCameraCmd + "\n");

                    //得到状态,下一步封装成json传回去
                    JsonObject returnJS        = SendJson("Camera", strStatusCode, m_lCameraIP, m_lChannel, strCmd, strResult, strResult2);
                    string     strReturnResult = returnJS.ToString();
                    strReturnResult = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(strReturnResult));
                    return(strReturnResult);
                }
                #endregion


                #region 广播控制命令
                if (joWebCmd["requestType"] == "Broadcast")
                {
                    string strBroadcastDeviceId    = joWebCmd["requestDetail"]["deviceid"];
                    string strBroadcastChannel     = joWebCmd["requestDetail"]["channel"];
                    string strBroadcastDeviceIp    = joWebCmd["requestDetail"]["deviceip"];
                    string strBroadcastVolumeValue = joWebCmd["requestDetail"]["volumeValue"];
                    string strBroadcastCmd         = joWebCmd["requestDetail"]["command"];

                    //执行命令
                    BroadcastUDP broadcastUDP = new BroadcastUDP();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    switch (strBroadcastCmd)
                    {
                    case "volume":
                        //此命令为修改设备音量,需要设备id,设备ip地址,音量值。
                        Byte volumeArray = (Byte)Convert.ToInt32(strBroadcastVolumeValue);     // 将获取到的string转化为 byte
                        broadcastUDP.setBroadcastDeviceVolume(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), volumeArray);
                        break;

                    case "stop":
                        //此命令为 强制关闭设备,需要设备id,设备ip地址,音量值。
                        Byte nMode = (Byte)Convert.ToInt32("1");     // 输入默认值 ;强制关闭类型: 1 表示强制关闭
                        broadcastUDP.closeBroadcastDevice(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nMode);
                        break;

                    case "channel":
                        //此命令为 切换设备频道,需要设备id,设备ip地址,频道。
                        Byte nChannel = (Byte)Convert.ToInt32(strBroadcastChannel);
                        broadcastUDP.changeBroadcastDeviceChannel(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nChannel);
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  广播云台控制命令!\n" + "控制广播设备编号为:" + strBroadcastDeviceId + "   命令为:" + strBroadcastCmd + "   广播设备IP为:" + strBroadcastDeviceIp + "\n");
                }
                #endregion

                return(strResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                StaticUtils.ShowEventMsg("MgJsonCtrl.class-ReceiceJson : 数据格式错误,请输入标准Json格式或产生异常\n");
                return("数据格式错误,请输入标准Json格式或产生异常");
            }
        }