| | |
| | | if (device == null) { |
| | | continue; |
| | | } |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 17, (byte)device.CurtainProress }); |
| | | } else if (common.Type == DeviceType.CurtainTrietex) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | | continue; |
| | | } |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 17, (byte)device.CurtainProress }); |
| | | } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | |
| | | } |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] { |
| | | device.AreaID,device.AreaSceneID}); |
| | | } else if (common.Type == DeviceType.UniversalDevice) {//2020-09-02 增加通用开关 |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | | continue; |
| | | } |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, device.SubnetID, device.DeviceID, new byte [] { device.SendBytes [0], device.SendBytes [1] }); |
| | | } |
| | | |
| | | try { |
| | |
| | | }); |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 2020-06-05 加锁 |
| | | /// </summary> |
| | | private readonly object SendLocker = new object (); |
| | | |
| | | public void ControlScene (string sceneFilePath) |
| | | { |
| | |
| | | foreach (var deviceFilePath in tempScene.DeviceFilePathList) { |
| | | controlDeviceIndex++; |
| | | new System.Threading.Thread (() => { |
| | | mSendCount++; |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (common.Type == DeviceType.LightDimming) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | try { |
| | | lock (SendLocker) { |
| | | mSendCount++; |
| | | } |
| | | } else if (common.Type == DeviceType.LightEnergySocket) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.LightEnergySwitch) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.LightRGB) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | //mSendCount++; |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (common.Type == DeviceType.LightDimming) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.LightEnergySocket) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.LightEnergySwitch) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.LightRGB) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.DelayTimeHeigh,device.DelayTimeLow, |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.DelayTimeHeigh,device.DelayTimeLow, |
| | | 3,device.RStatus,device.GStatus,device.BStatus,0,0}); |
| | | } |
| | | } else if (common.Type == DeviceType.LightSwitch) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainModel) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainRoller) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainTrietex) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, device.SubnetID, device.DeviceID, new byte [] { |
| | | } |
| | | } else if (common.Type == DeviceType.LightSwitch) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainModel) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainRoller) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.CurtainTrietex) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status }); |
| | | } |
| | | } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, device.SubnetID, device.DeviceID, new byte [] { |
| | | device.LoopID, |
| | | device.TemperatureMode, |
| | | device.IndoorTemperature, |
| | |
| | | device.SetFanSpeed, |
| | | device.SetTemperature, |
| | | device.ShaoFanMode}); |
| | | } |
| | | } else if (common.Type == DeviceType.FoolHeat) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID, |
| | | new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature, |
| | | } |
| | | } else if (common.Type == DeviceType.FoolHeat) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID, |
| | | new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature, |
| | | device.NightTemperature, device.AwayTemperature , 0, 0 }); |
| | | } |
| | | } else if (common.Type == DeviceType.FanModule) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.WindSpeed }); |
| | | } |
| | | } else if (common.Type == DeviceType.LogicModule) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] { |
| | | } |
| | | } else if (common.Type == DeviceType.FanModule) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.WindSpeed }); |
| | | } |
| | | } else if (common.Type == DeviceType.LogicModule) { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | //if (device == null) { |
| | | // mSendCount--; |
| | | // continue; |
| | | //} |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] { |
| | | device.AreaID,device.AreaSceneID}); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | if (showTip) { |
| | | if (replyBytes == null) { |
| | | Application.RunOnMainThread (() => { |
| | | string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); |
| | | var btnTip = new Button () { |
| | | Height = Application.GetRealHeight (140), |
| | | Text = common.Name + tipString + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (), |
| | | BackgroundColor = SkinStyle.Current.TitileView, |
| | | }; |
| | | MainPage.MainFrameLayout.AddChidren (btnTip); |
| | | btnTip.MouseUpEventHandler += (sender, e) => { |
| | | btnTip.RemoveFromParent (); |
| | | showTip = false; |
| | | //MainPage.MainFrameLayout.Remove (btnTip); |
| | | }; |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | System.Threading.Thread.Sleep (3000); |
| | | Application.RunOnMainThread (() => { |
| | | btnTip.RemoveFromParent (); |
| | | //MainPage.MainFrameLayout.Remove (btnTip); |
| | | //showTip = false; |
| | | }); |
| | | }); |
| | | }); |
| | | } |
| | | } else if (common.Type == DeviceType.UniversalDevice) {//2020-09-02 增加通用开关 |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (device == null) { |
| | | replyBytes = new byte [] { 0x00 }; |
| | | } else { |
| | | replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, device.SubnetID, device.DeviceID, new byte [] { device.SendBytes [0], device.SendBytes [1] }); |
| | | } |
| | | } |
| | | } catch { |
| | | } |
| | | |
| | | mSendCount--; |
| | | }){ IsBackground = true}.Start(); |
| | | |
| | | |
| | | try { |
| | | if (showTip) { |
| | | if (replyBytes == null) { |
| | | Application.RunOnMainThread (() => { |
| | | string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); |
| | | var btnTip = new Button () { |
| | | Height = Application.GetRealHeight (140), |
| | | Text = common.Name + tipString + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (), |
| | | BackgroundColor = SkinStyle.Current.TitileView, |
| | | }; |
| | | MainPage.MainFrameLayout.AddChidren (btnTip); |
| | | btnTip.MouseUpEventHandler += (sender, e) => { |
| | | btnTip.RemoveFromParent (); |
| | | showTip = false; |
| | | //MainPage.MainFrameLayout.Remove (btnTip); |
| | | }; |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | System.Threading.Thread.Sleep (3000); |
| | | Application.RunOnMainThread (() => { |
| | | btnTip.RemoveFromParent (); |
| | | //MainPage.MainFrameLayout.Remove (btnTip); |
| | | //showTip = false; |
| | | }); |
| | | }); |
| | | }); |
| | | } |
| | | } |
| | | } catch { |
| | | } |
| | | |
| | | //mSendCount--; |
| | | } catch { } finally { |
| | | lock (SendLocker) { |
| | | mSendCount--; |
| | | } |
| | | } |
| | | }) { IsBackground = true }.Start (); |
| | | |
| | | //等待100ms再发送第二个设备数据 |
| | | System.Threading.Thread.Sleep (100); |