private void ptzCtrl_Click(object sender, EventArgs e)
        {
            if (!isPlaying)
            {
                return;
            }
            Label       obj         = (Label)sender;
            string      strType     = obj.Name.Replace("ptzCtrl", "");
            PTZCtrlType ptzCtrlType = (PTZCtrlType)int.Parse(strType);
            string      errorMsg    = "";

            if (!LCSDK.LCOpenSDK_PTZCtrl(nowDeviceInfo.token, nowDeviceInfo.deviceID, (int)nowDeviceInfo.channelIndex, ptzCtrlType, ref errorMsg))
            {
            }
            else
            {
                //labelPrompt.Text = "提示信息:" + errorMsg;
            }
        }
        public bool PTZCtrl(string token, string deviceId, int channelId, PTZCtrlType ctrlType, ref string errorMsg)
        {
            try
            {
                int iH, iV, iZ;
                int duration = 100;
                iH       = iV = 0;
                iZ       = 1;
                errorMsg = "";
                switch (ctrlType)
                {
                case PTZCtrlType.PTZ_CONTROL_LEFT:
                    iH = -5;
                    iV = 0;
                    break;

                case PTZCtrlType.PTZ_CONTROL_RIGHT:
                    iH = 5;
                    iV = 0;
                    break;

                case PTZCtrlType.PTZ_CONTROL_UP:
                    iH = 0;
                    iV = 5;
                    break;

                case PTZCtrlType.PTZ_CONTROL_DOWN:
                    iH = 0;
                    iV = -5;
                    break;

                case PTZCtrlType.PTZ_CONTROL_LEFTUP:
                    iH = -5;
                    iV = 5;
                    break;

                case PTZCtrlType.PTZ_CONTROL_LEFTDOWN:
                    iH = -5;
                    iV = -5;
                    break;

                case PTZCtrlType.PTZ_CONTROL_RIGHTUP:
                    iH = 5;
                    iV = 5;
                    break;

                case PTZCtrlType.PTZ_CONTROL_RIGHTDOWN:
                    iH = 5;
                    iV = -5;
                    break;
                }

                string url = "https://openapi.lechange.cn/openapi/controlPTZ";

                JObject jsonObj    = new JObject();
                JObject paramsList = new JObject(
                    new JProperty("deviceId", deviceId),
                    new JProperty("duration", duration.ToString()),
                    new JProperty("channelId", channelId.ToString()),
                    new JProperty("h", iH),
                    new JProperty("operation", "move"),
                    new JProperty("token", token),
                    new JProperty("v", iV),
                    new JProperty("z", iZ)
                    );
                JToken jtoken  = JToken.Parse(paramsList.ToString());
                string strJson = SortJson(jtoken, null);
                paramsList = (JObject)JsonConvert.DeserializeObject(strJson);
                JObject systemList = GetSystemJsonArray(paramsList);
                jsonObj.Add("system", systemList);
                jsonObj.Add("params", paramsList);
                jsonObj.Add("id", "88");
                string stringTemp = jsonObj.ToString();
                stringTemp = stringTemp.Replace("\r\n", "");

                string resultContent = GetPostRequest(url, stringTemp);
                jsonObj = (JObject)JsonConvert.DeserializeObject(resultContent);
                string errcode = jsonObj["result"]["code"].ToString();
                string errmsg  = jsonObj["result"]["msg"].ToString();
                if (errcode == "0")
                {
                    return(true);
                }
                else
                {
                    errorMsg = errmsg;
                }
            }
            catch (Exception ex)
            {
                int ii = 0;
            }
            return(false);
        }
Beispiel #3
0
 //【云台控制】
 //参数-token	    授权Token
 //参数-deviceId	    设备序列号
 //参数-channelId    通道号
 //参数-ctrlType     方向
 //参数-errorMsg	    错误信息
 //返回值:		    =false获取失败
 public static bool LCOpenSDK_PTZCtrl(string token, string deviceId, int channelId, PTZCtrlType ctrlType, ref string errorMsg)
 {
     return(https.PTZCtrl(token, deviceId, channelId, ctrlType, ref errorMsg));
 }