public override int pro_pack(byte[] b, int len) { switch (check_type) //按校验类型进行校验 { case CHECK_TYPE.sum: byte sum = Tool.check_sum(b, len - 1); if (sum != b[len - 1]) { return(1); } break; case CHECK_TYPE.crc16: UInt16 crc = Tool.crc_ccitt(b, len - 2); DATA_UNION d = new DATA_UNION(); d.du8 = b[len - 2]; d.du8_1 = b[len - 1]; if (crc != d.du16) { return(1); } break; case CHECK_TYPE.modbuscrc: break; } rx_bin_cb(b, 0, len); return(0); }
} = 0; //是否是有符号数 public PD_Node(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd) { if (v.ContainsKey("pro_k")) { pro_k = (double)(decimal)v["pro_k"]; } if (v.ContainsKey("pro_b")) { pro_b = (double)(decimal)v["pro_b"]; } if (v.ContainsKey("bit_st")) { bit_st = (int)v["bit_st"]; //默认从0bit开始 } if (v.ContainsKey("bit_len")) { bit_len = (int)v["bit_len"]; } if (v.ContainsKey("bit_singed")) { bit_st = (int)v["bit_singed"]; //默认从0bit开始 } if (v.ContainsKey("skip_n")) { skip_n = (int)v["skip_n"]; } len = DATA_UNION.get_type_len(type); }
} = new List <string>(); //显示字符串表。可用于bool型指令,0为失败字符,1为成果字符 public ParaValue(Dictionary <string, object> v, DataType t) //从json构造对象 { //这里遇到错误就throw出去,不想throw的才判断 if (v.ContainsKey("id")) { id = (int)v["id"]; } name = (string)v["name"]; type = t; if (v.ContainsKey("len")) { len = (int)v["len"]; } else { len = DATA_UNION.get_type_len(type); } if (v.ContainsKey("str_tab")) { var ar = v["str_tab"] as ArrayList; for (int i = 0; i < ar.Count; i++) { str_tab.Add(ar[i] as string); } //str_tab = v["str_tab"] as string[]; } }