public static CmdModel CmdAnayer(string CmdString) { string[] data = CmdString.Trim().Split(Convert.ToChar("/")); CmdModel ObjItem = new CmdModel() { Cmd = data[0].Trim(), PortNum = data[1].Trim(), Value = data[2].Trim(), }; return(ObjItem); }
}//出栈 private void Socket_MessageReceived2(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)//与服务器进行通讯 8000端口 { string remoteaddr = args.RemoteAddress.DisplayName;//远端IP地址 //if (remoteaddr == LocIp) // return;//本机IP不做处理 DataReader reader = args.GetDataReader(); reader.UnicodeEncoding = UnicodeEncoding.Utf8; // 读长度 uint len = reader.ReadUInt32(); // 读内容 string msg = reader.ReadString(reader.UnconsumedBufferLength); if (oldStr == msg) { return;//重复过滤器 } else { oldStr = msg; } try { CmdModel Cmd = CmdAnay.CmdAnayer(msg); if (Cmd.PortNum == "8000")//本机指令 { switch (Cmd.Cmd) { case "DeviceList": SendDeviceList(8001, Obj); break; //请求设备列表命令 default: break; } } else { switch (Cmd.Cmd) { case "FanOnOrOff": SendCmd(Convert.ToInt16(Cmd.PortNum), "0000+A");; break; case "FanValueSet": SendCmd(Convert.ToInt16(Cmd.PortNum), "0000+B");; break; case "Led1OnOrOff": WriteCmdByte(new byte[] { 0x01 }); break; case "Led2OnOrOff": WriteCmdByte(new byte[] { 0x02 }); break; case "LedFlu": WriteCmdByte(new byte[] { 0x03 }); break; default: break; } } } catch (Exception) { } }