Example #1
0
        //
        public APIRst GetYdMonitorOfControl(string cmd, int module_id)
        {
            APIRst rst = new APIRst();

            if (string.IsNullOrEmpty(cmd))
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "请发送指令";
                return(rst);
            }
            try
            {
                //long log_id = bll.YdModuleOnAddCmd(module_id, 0, V0Fun.Ssr1.ToString(), cmd);
                long log_id = bll.YdModuleOnAddCmd(module_id, 0, V0Fun.Ssr.ToString(), cmd);

                CommandVModel command = bll.GetYdModuleOnSendCmd(log_id);
                ListenVModel  vm      = new ListenVModel();
                vm.cfun    = ListenCFun.cmd.ToString();
                vm.content = JsonHelper.Serialize(command);
                string msg = "";
                rst.rst     = CacheMgr.SendCollectVal(vm, out msg);
                rst.err.msg = msg;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("下发指令错误(GetYdMonitorOfControl):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Example #2
0
        public APIResult GetCollectValue(List <ApiVar> var)
        {
            APIResult rst = new APIResult();
            bool      cc  = CacheMgr.SendCollectVal(var);

            rst.Code = cc == true ? 0 : -1;
            rst.Msg  = cc == true ? "成功" : "失败";
            rst.Data = "";
            return(rst);
        }
Example #3
0
        /// <summary>
        /// 下发命令数据
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="dataValue"></param>
        /// <returns></returns>
        public APIRst SendVal(List <string> tags, string dataValue)
        {
            List <object> dd  = new List <object>();
            APIRst        rst = new APIRst()
            {
                rst = true
            };

            try
            {
                DataTable dtInfo = bll.GetTagInfo(string.Join(",", tags.ToArray()));
                foreach (var k in tags)
                {
                    DataRow[] arr = dtInfo.Select("LpszDbVarName='" + k + "'");
                    if (arr.Count() == 0)
                    {
                        dd.Add(new { tag = k, rst = false, msg = "没有此采集点" });
                        continue;
                    }
                    CommandVModel cmd = ModelHandler <CommandVModel> .FillModel(arr[0]);

                    cmd.Action        = 1;
                    cmd.LpszDbVarName = CommFunc.ConvertDBNullToString(arr[0]["TagName"]);
                    cmd.DataValue     = dataValue;
                    cmd.IsNDb         = true;
                    bll.UpdateMapDataVal(cmd.Module_id, cmd.Fun_id, cmd.DataValue);
                    //
                    ListenVModel vm = new ListenVModel()
                    {
                        cfun = ListenCFun.cmd.ToString(), content = JsonHelper.Serialize(cmd)
                    };
                    string msg = "";
                    bool   rr  = CacheMgr.SendCollectVal(vm, out msg);
                    dd.Add(new { tag = k, rst = rr, msg = msg });
                }
                rst.data = dd;
            }
            catch (Exception ex)
            {
                rst.rst  = false;
                rst.data = "";
                rst.err  = new APIErr()
                {
                    code = -1, msg = ex.Message
                };
            }
            return(rst);
        }
Example #4
0
        public APIRst CollectData(string dataValue)
        {
            APIRst rst = new APIRst()
            {
                rst = true
            };

            try
            {
                Pack pack = JsonHelper.Deserialize <Pack>(dataValue);
                if (pack == null || pack.Data == null || pack.Data.Count == 0)
                {
                    rst = new APIRst()
                    {
                        rst = false, data = "", err = new APIErr()
                        {
                            code = -2, msg = "没有值"
                        }
                    };
                    FileLog.WriteLog("接收到数据格式不正确:" + dataValue);
                    return(rst);
                }
                string key = pack.DevAddr + "." + pack.DisNo + "." + pack.EleNo + ".";
                SortedList <string, Data> e  = new SortedList <string, Data>();
                SortedList <string, Data> e4 = new SortedList <string, Data>();
                List <Data> ld = new List <Data>();
                foreach (Data dd in pack.Data)
                {
                    if (dd.FunType.Equals("E") || dd.FunType.Equals("E1") || dd.FunType.Equals("E2") || dd.FunType.Equals("E3") || dd.FunType.Equals("E4"))
                    {
                        string funType = dd.FunType;
                        if (dd.FunType.Equals("E"))
                        {
                            funType = "E0";
                        }
                        if (dd.Type == 0)
                        {
                            e.Add(funType, dd);
                        }
                        else
                        {
                            e4.Add(funType, dd);
                        }
                    }
                    else
                    {
                        ld.Add(dd);
                    }
                }
                if (this.AddType(ref e, ref ld, 0) == false)
                {
                    FileLog.WriteLog("接收到非冻结数据总电能不等于尖峰平谷:" + dataValue);
                }
                if (this.AddType(ref e4, ref ld, 1) == false)
                {
                    FileLog.WriteLog("接收到冻结数据总电能不等于尖峰平谷:" + dataValue);
                }
                //if (e.Count > 0)
                //{
                //    FileLog.WriteLog("接收到实时尖峰平谷数据:" + dataValue);
                //    FileLog.WriteLog("实时压栈数据:" + JsonHelper.Serialize(ld));
                //}
                //if (e4.Count > 0)
                //{
                //    FileLog.WriteLog("接收到冻结尖峰平谷数据:" + dataValue);
                //    FileLog.WriteLog("冻结压栈数据:" + JsonHelper.Serialize(ld));
                //}
                foreach (Data dd in ld)
                {
                    if (dd.FunType.Equals("E1") || dd.FunType.Equals("E2") || dd.FunType.Equals("E3") ||
                        dd.FunType.Equals("E5") || dd.FunType.Equals("E6") || dd.FunType.Equals("E6") || dd.FunType.Equals("E8") ||
                        dd.FunType.Equals("E9") || dd.FunType.Equals("E10") || dd.FunType.Equals("E11") || dd.FunType.Equals("E12"))
                    {
                        continue;
                    }
                    CommandVModel cmd = new CommandVModel();
                    cmd.Ledger       = WebConfig.Ledger;
                    cmd.TransferType = 4;
                    cmd.FunType      = dd.FunType;

                    cmd.LpszDbVarName = key + dd.FunType;
                    cmd.DataValue     = dd.DataValue;
                    cmd.CollectTime   = dd.Time;

                    ListenVModel vm = new ListenVModel()
                    {
                        cfun = ListenCFun.collect.ToString(), content = JsonHelper.Serialize(cmd)
                    };
                    string msg = "";
                    bool   rr  = CacheMgr.SendCollectVal(vm, out msg);
                    if ((dd.FunType.Equals("E") || dd.FunType.Equals("E4")) && rr == true)
                    {
                        FileLog.WriteLog("成功发送数据:" + vm.content);
                    }
                    //if (rr==true)
                    //    FileLog.WriteLog("成功发送数据:" + vm.content);
                }
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取采集信息错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }