void 查询风扇状态(IPEndPoint ipEndPoint) { DeviceCommandManager.setCommandCallback(enumDeviceCommand.查询风扇状态, (data) => { Debug.WriteLine("风扇状态 => " + data); IDeviceCommand idc = DeviceCommandManager.getDeivceCommand(enumDeviceCommand.查询风扇状态); if (null != idc) { LightState ls = idc.parseResponse(data); if (null != ls) { if (ls.State) { string log = "风扇已经打开"; this.add_log(log); Debug.WriteLine(log); //FanService.last_effective_command = new command("open", ""); command cmd = new command(stateName.打开, ""); cmd.TargetDevice = TargetDeiveName.电风扇; cmd.Initializing = "true"; this.sendInitialInfo(ws, cmd); } else { string log = "风扇已经关闭"; this.add_log(log); Debug.WriteLine(log); FanService.last_effective_command = new command("close", ""); } } } }); DeviceCommandManager.executeCommand(enumDeviceCommand.查询风扇状态, ipEndPoint); }
void 检查风扇状态(IPEndPoint ipEndPoint) { DeviceCommandManager.setCommandCallback(enumDeviceCommand.查询风扇状态, (data) => { Debug.WriteLine("风扇状态 => " + data); IDeviceCommand idc = DeviceCommandManager.getDeivceCommand(enumDeviceCommand.查询风扇状态); if (null != idc) { LightState ls = idc.parseResponse(data); if (null != ls) { switch (ls.State) { case true: if (myCommand != null) { myCommand.Name = stateName.打开; } this.invokeCallback(myCommand); break; case false: if (myCommand != null) { myCommand.Name = stateName.关闭; } this.invokeCallback(myCommand); break; } } } }); DeviceCommandManager.executeCommand(enumDeviceCommand.查询风扇状态, ipEndPoint, 1000); }
void 查询电机状态(IPEndPoint ipEndPoint) { DeviceCommandManager.setCommandCallback(enumDeviceCommand.查询电机状态, (data) => { Debug.WriteLine("电机状态 => " + data); IDeviceCommand idc = DeviceCommandManager.getDeivceCommand(enumDeviceCommand.查询电机状态); if (null != idc) { LightState ls = idc.parseResponse(data); if (null != ls) { if (ls.State) { string log = "电机已经打开"; this.add_log(log); Debug.WriteLine(log); EngineService.last_effective_command = new command("open", ""); } else { string log = "电机已经关闭"; this.add_log(log); Debug.WriteLine(log); EngineService.last_effective_command = new command("close", ""); } } } }); DeviceCommandManager.executeCommand(enumDeviceCommand.查询电机状态, ipEndPoint); }
void 关闭风扇(IPEndPoint ipEndPoint) { //if (myCommand != null) //{ // myCommand.Name = stateName.关闭; // //myCommand.Name = stateName.打开; //} //this.invokeCallback(myCommand); //return; DeviceCommandManager.executeCommand(enumDeviceCommand.关闭风扇, ipEndPoint); 检查风扇状态(ipEndPoint); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DeviceCommandManager.initialCommandList(); List <CommandMatch> cmdList = CommandMatchHelper.importCommand(); DeviceCommandManager.matchCommand(cmdList); serverForm form = new serverForm(); services.showStateForm = form; //frmProtocolTest form = new frmProtocolTest(); Application.Run(form); }
void parseCommand(string strReceived) { if (strReceived.Length <= 0 || (strReceived.Length % 2) != 0) { return; } for (int i = 0; i < strReceived.Length; i += 2) { string temp = strReceived.Substring(0, i + 2); IDeviceCommand cmd = DeviceCommandManager.getDeivceCommandWithResponseOf(temp); if (cmd != null) { Debug.WriteLine("parseCommand ok => " + temp); cmd.callBack(temp); builder.Remove(0, i + 2); parseCommand(strReceived.Substring(i + 1)); } else { Debug.WriteLine("parseCommand null => " + temp); } } }
public static bool updateCommand(List <CommandMatch> list, CommandMatch cmd) { //首先要保证协议内同一个命令不能两次出现 bool b = list.Exists((_cmd) => { return(cmd.cmd == _cmd.cmd); }); if (!b) { CommandMatch temp = list.Find((_cmd) => { return(cmd.name == _cmd.name); }); if (temp != null) { temp.cmd = cmd.cmd; DeviceCommandManager.matchCommand(cmd); return(true); } } return(false); }
private void btnGroup_Click(object sender, EventArgs e) { DeviceCommandManager.executeCommand(enumDeviceCommand.组网, Program.getRemoteIPEndPoint()); }
public void sendCommand(IPEndPoint ipEndPoint) { DeviceCommandManager.sendCommand(this, ipEndPoint); }