public bool SendRoot <T>(byte command, String Request, T Root, int Querycount) { WeaveSession b = new WeaveSession(); b.Request = Request; b.Token = this.Tokan; b.SetRoot <T>(Root); b.Querycount = Querycount; return(send(command, b.Getjson())); }
public bool SendRoot <T>(byte command, string Request, T Root, int Querycount) { WeaveSession b = new WeaveSession { Request = Request, Token = Tokan }; b.SetRoot(Root); b.Querycount = Querycount; return(Send(command, b.Getjson())); }
/// <summary> /// 将传输的BYTE字节内容转为基础类 /// </summary> /// <param name="data"></param> /// <returns></returns> public WeaveSession GetBaseModel(byte[] data) { //data 的内容为,协议中的内容段,不明白的查看 客户端协议的说明,内容段是自己定义的内容 WeaveSession bm = new WeaveSession(); byte[] bs = new byte[2]; Array.Copy(data, 0, bs, 0, bs.Length); int req = ConvertToInt(bs); if (req == 1) { bm.Request = "getdata"; } //bm.Request 注意这个属性必须要赋值,赋值的内容和你后端的执行处理的方法一致,代表你需要那个方法处理他。 byte[] b = new byte[data.Length - 2]; Array.Copy(data, 2, b, 0, b.Length); bm.SetRoot <byte[]>(b); //可以用SetRoot 方法把整段内容发送给后端方法处理 bm.Token = "这里不能是空的,如果没有,就自己随便加一个内容"; return(bm); }
private static void Wudpweb_waveReceiveEvent(byte command, string data, System.Net.Sockets.Socket soc) { WeaveSession wsion = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(data); try { if (command == 0x03) { foreach (chuganqi cq in LISTchuganqi) { if (cq.id == wsion.Root) { if (wsion.Request == "QXZ") { wsion.SetRoot <chuganqi>(cq); String strt = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x03, strt); return; } } } } foreach (nqdtu nqd in LISTDTU) { if (wsion.Root == nqd.ID) { if (nqd.state) { if (wsion.Request == "zheng") { Console.WriteLine("设备连接:" + nqd.ID + ":正向打开"); openzheng(nqd); return; } else if (wsion.Request == "fan") { openfan(nqd); return; } else if (wsion.Request == "closejuan") { closejuanlian(nqd); return; } if (wsion.Request == "open") { nqd.soc.Send(dtccommand.OPEN(Convert.ToByte(wsion.Parameter))); return; } if (wsion.Request == "close") { nqd.soc.Send(dtccommand.CLOSE(Convert.ToByte(wsion.Parameter))); return; } } else { wsion.Root = nqd.state? "设备正常" : "设备不在线"; wsion.Request = "cha"; String strs = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x01, strs); return; } if (wsion.Request == "cha") { wsion.Root = nqd.state ? "设备正常" : "设备不在线"; String strt = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x01, strt); return; } if (wsion.Request == "chazhuangtai") { wsion.SetRoot <bool[]>(nqd.kg); String strt = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x01, strt); return; } if (wsion.Request == "tiaojian") { wsion.SetRoot <tiaojian>(nqd.tiaojiancc); String strt = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x02, strt); return; } return; } } wsion.Root = "设备不在线"; wsion.Request = "chas"; String str = Newtonsoft.Json.JsonConvert.SerializeObject(wsion); wudpweb.Send(soc, 0x01, str); } catch { } }