예제 #1
0
        public Dictionary <string, PD_LineObj> textline_dict = new Dictionary <string, PD_LineObj>(); //文本协议字典
        public void formJson(Dictionary <string, object> v)                                           //初始化
        {
            if (v.ContainsKey("para_dict"))
            {
                ArrayList list = v["para_dict"] as ArrayList;
                foreach (var item in list)
                {
                    var    tv = item as Dictionary <string, object>;
                    string s  = tv["name"] as string;
                    para_dict[s] = ParaValue.factory(tv);                     //构建参数
                }
            }
            if (v.ContainsKey("prot_root"))
            {
                prot_root = MC_Prot.factory(v["prot_root"] as Dictionary <string, object>, this);                //递归创建自己的子协议域
            }
            //文本行协议
            if (v.ContainsKey("textline_dict"))
            {
                ArrayList list = v["textline_dict"] as ArrayList;
                foreach (var item in list)
                {
                    var tv = item as Dictionary <string, object>;

                    string s = "";
                    if (tv.ContainsKey("name"))
                    {
                        s = tv["name"] as string;
                    }
                    int col_n = (int)tv["col_n"];                     //必须描述此协议的列数
                    s += "-" + col_n.ToString();
                    textline_dict[s] = new PD_LineObj(tv, DataType.str, this);
                }
            }
        }
예제 #2
0
        public override void pro(byte[] b, ref int off, int n)
        {
            int pre_off = off;           //上次偏移位置

            for (int i = 0; i < prot_list.Count; i++)
            {
                ProtDom pd = prot_dict[prot_list[i]]; //当前子协议域
                pd.pro(b, ref off, n);                //递归调用
                n      -= off - pre_off;              //增加了多少字节,总字节数相应减掉
                pre_off = off;
            }
        }
예제 #3
0
        public override void set_val(double d)
        {
            switch (type)             //根据输出的类型给输出
            {
            case DataType.f: data.f = (float)d; break;

            case DataType.df: data.df = d; break;

            default:
                data.ds64 = ProtDom.double_2_s64(d);                         //转换成整数,四舍五入
                break;
            }
            update_cb(this);             //需要调参数的回调函数
        }
예제 #4
0
 public void clear()
 {
     prot_root = null;
     textline_dict.Clear();
     para_dict.Clear();
 }