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) { DeviceCommandManager.setCommandCallback(enumDeviceCommand.²éѯ»ÆµÆ״̬, (data) => { Debug.WriteLine("»ÆµÆ״̬ => " + data); IDeviceCommand idc = DeviceCommandManager.getDeivceCommand(enumDeviceCommand.²éѯ»ÆµÆ״̬); if (null != idc) { LightState ls = idc.parseResponse(data); if (null != ls && last_command != null) { bool temp = (last_command.Name == "open") ? true : false; if (ls.State == temp) //µÆÏÖÔÚµÄ״̬ºÍ²Ù×÷Ä¿±ê״̬Ïàͬ£¬Í¬Îª¹Ø»òÕß¿ª { switch (last_command.Name) { case "open": Debug.WriteLine(string.Format("{0} ´ò¿ª»ÆµÆ", last_command.Commander)); command ncOpen = new command("open", string.Format("{0}´ò¿ªÁ˵Æ", last_command.Commander)); last_effective_command = ncOpen; recently_broadcast = JsonConvert.SerializeObject(ncOpen); this.Broadcast(recently_broadcast); break; case "close": Debug.WriteLine(string.Format("{0} ¹Ø±Õ»ÆµÆ", last_command.Commander)); command ncClose = new command("close", string.Format("{0}¹Ø±ÕÁ˵Æ", last_command.Commander)); last_effective_command = ncClose; recently_broadcast = JsonConvert.SerializeObject(ncClose); this.Broadcast(recently_broadcast); break; } } else //˵Ã÷É豸ûÓÐÏìÓ¦£¬Í¨Öª¿Í»§¶Ë { switch (ls.State) { case true: command ncOpen = new command("open", "²Ù×÷ʧ°Ü"); recently_broadcast = JsonConvert.SerializeObject(ncOpen); this.Send(recently_broadcast); //ֻ֪ͨ±¾ÈË Debug.WriteLine("¹Ø±Õ»ÆµÆ²Ù×÷ʧ°Ü"); break; case false: command ncClose = new command("close", "²Ù×÷ʧ°Ü"); recently_broadcast = JsonConvert.SerializeObject(ncClose); this.Send(recently_broadcast); Debug.WriteLine("´ò¿ª»ÆµÆ²Ù×÷ʧ°Ü"); 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 && last_command != null) { bool temp = (last_command.Name == "open") ? true : false; if (ls.State == temp) //灯现在的状态和操作目标状态相同,同为关或者开 { switch (last_command.Name) { case "open": Debug.WriteLine(string.Format("{0} 打开电机", last_command.Commander)); command ncOpen = new command("open", string.Format("{0}打开了电机", last_command.Commander)); last_effective_command = ncOpen; recently_broadcast = JsonConvert.SerializeObject(ncOpen); this.Broadcast(recently_broadcast); break; case "close": Debug.WriteLine(string.Format("{0} 关闭电机", last_command.Commander)); command ncClose = new command("close", string.Format("{0}关闭了电机", last_command.Commander)); last_effective_command = ncClose; recently_broadcast = JsonConvert.SerializeObject(ncClose); this.Broadcast(recently_broadcast); break; } } else //说明设备没有响应,通知客户端 { switch (ls.State) { case true: command ncOpen = new command("open", "操作失败"); recently_broadcast = JsonConvert.SerializeObject(ncOpen); this.Send(recently_broadcast); //只通知本人 Debug.WriteLine("关闭电机操作失败"); break; case false: command ncClose = new command("close", "操作失败"); recently_broadcast = JsonConvert.SerializeObject(ncClose); this.Send(recently_broadcast); Debug.WriteLine("打开电机操作失败"); break; } } } } }); DeviceCommandManager.executeCommand(enumDeviceCommand.查询电机状态, ipEndPoint, 1000); }