private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var timingset in timingSets)
                {
                    ucTS uc = new ucTS();
                    uc.Set(timingset.ID);
                    stpTS.Children.Add(uc);
                }

                for (int i = 0; i < channelGroups.Count; i++)
                {
                    TabItem tabItem = new TabItem();
                    tabItem.Header = "Group" + (i + 1);
                    ucChannel uc = new ucChannel();
                    uc.Set(channelGroups[i]);
                    tabItem.Content = uc;
                    tabChannel.Items.Add(tabItem);
                }

#if REALHW
                Digital = new pe32h(true);
                LogMessage("Create pe32h instance successfully!");
                if (Digital.Initialize() != 0)
                {
                    LogMessage("Initialize pe32h failed!");
                }
                LogMessage("Initialize pe32h successfully!");
                pezMAX = Digital.lmload(1, 1, 0, filePEZ);
                if (pezMAX < 0)
                {
                    LogMessage("lmload failed!");
                }
                LogMessage("lmload successfully returns " + pezMAX + "!");
                Digital.rd_pesno(1);
                int data = 0;
                foreach (var channelgroup in channelGroups)
                {
                    int offset = channelgroup.Clock.ID - 1;
                    data = (data | (1 << offset));
                }
                Digital.set_rz(1, 1, data);
                LogMessage(string.Format("Digital.set_rz(1, 1, {0});", Convert.ToString(data, 2).PadLeft(32, '0')));
                Digital.set_ro(1, 1, 0);
                LogMessage(string.Format("Digital.set_ro(1, 1, {0});", Convert.ToString(0, 2).PadLeft(32, '0')));
#endif

                btnSet.IsEnabled   = true;
                btnDebug.IsEnabled = false;
            }
            catch (Exception ex)
            {
                btnSet.IsEnabled   = false;
                btnDebug.IsEnabled = false;
                MessageBox.Show(ex.Message);
                LogMessage(ex.Message);
            }
        }
 private void GetTimingSets()
 {
     foreach (var child in stpTS.Children)
     {
         if (child is ucTS)
         {
             ucTS      uc = child as ucTS;
             TimingSet ts = timingSets.First(x => x.ID == uc.ID);
             uc.SetObj(ts);
         }
     }
 }