public MainWindow()
        {
            InitializeComponent();
#if !DEBUG
            System.Windows.Threading.DispatcherTimer tmr = new System.Windows.Threading.DispatcherTimer();
            tmr.Tick += async   (s, a) =>
                {
                    try
                    {
                        StreetLightInfo[] infos=null;
                        if (chkStopCycleQuery.IsChecked == false)
                        {
                            
                            infos = await dev.GetVisibleStreetLightListAsync();
                            
                            this.datagrid1.ItemsSource = infos.OrderBy(n=>n.DevID).ToArray();
                          
                            CeraDevices.Schedule sch = new CeraDevices.Schedule();
                            sch.Segnments = Schedules;
                            int repcnt = 0;
                            foreach (StreetLightInfo info in infos)
                            {
                                if (chkIsRepair.IsChecked == true && !sch.IsEqual(info.sch))
                                {
                                    dev.SetDeviceSchedule(info.DevID, sch.GetScheduleSegTimeString(), sch.GetScheduleSegLevelString());
                                    repcnt++;
                                }
                              //  grdSchedule.ItemsSource
                            }

                            this.Title = repcnt + "/" + infos.Length.ToString();
                            
                        }
                        if (cyclecnt++ * cycle % 600 == 0) //10 min
                            if (chkIsLog.IsChecked == true)
                                savelog(infos);
                       
                    }
                    catch { ;}
                };

            tmr.Interval = TimeSpan.FromSeconds(60);
            tmr.Start();
           

            
          //  dev.SetDeviceRTC("*", DateTime.Now);
#endif
            for (int i = 0; i < Schedules.Length; i++)
                Schedules[i] = new ScheduleSegnment();
            this.grdSchedule.ItemsSource = Schedules;
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            string sceneName=  Microsoft.VisualBasic.Interaction.InputBox("請輸入範本名稱", "StreetLight");
              if (sceneName == "")
              return;

            ScheduleSegnment[] segs=new ScheduleSegnment[10];
            for(int i=0;i<segs.Length;i++)
                segs[i]=new ScheduleSegnment(){ Time=0,Level=255};
            Scenariors.Add(new Scenarior() { SceneName = sceneName, Schedule = new Schedule() { Segnments = segs } });
            this.lstScenarioName.ItemsSource = null;
            this.lstScenarioName.ItemsSource = Scenariors;
        }