Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 void ´ò¿ªµÆ(IPEndPoint ipEndPoint)
 {
     DeviceCommandManager.executeCommand(enumDeviceCommand.´ò¿ª»ÆµÆ, ipEndPoint);
 }
Beispiel #4
0
 void ¹Ø±ÕµÆ(IPEndPoint ipEndPoint)
 {
     DeviceCommandManager.executeCommand(enumDeviceCommand.¹Ø±Õ»ÆµÆ, ipEndPoint);
 }
Beispiel #5
0
 void 打开电机(IPEndPoint ipEndPoint)
 {
     DeviceCommandManager.executeCommand(enumDeviceCommand.打开电机, ipEndPoint);
 }
Beispiel #6
0
 void 关闭风扇(IPEndPoint ipEndPoint)
 {
     DeviceCommandManager.executeCommand(enumDeviceCommand.关闭风扇, ipEndPoint);
 }