Example #1
0
      private void AddDeviceButton_Click(object sender, EventArgs e)
      {
         int nextControlTop = 0;

         foreach (DeviceControl storedDeviceControl in this.deviceList)
         {
            nextControlTop += storedDeviceControl.Height;
         }

         nextControlTop -= this.DevicePanel.VerticalScroll.Value;

         DeviceControl deviceControl = null;
         string deviceType = (string)this.DeviceComboBox.SelectedItem;

         if ("ElmoMotor" == deviceType)
         {
            deviceControl = new ElmoMotorDeviceControl();
         }
         else if ("PeakDigitalIo" == deviceType)
         {
            deviceControl = new PeakDigitalIoDeviceControl();
         }
         else if ("PeakAnalogIo" == deviceType)
         {
            deviceControl = new PeakAnalogIoDeviceControl();
         }
         else if ("UlcRoboticsCamera" == deviceType)
         {
            deviceControl = new UlcRoboticsCamera();
         }
         else if ("UlcRoboticsGps" == deviceType)
         {
            deviceControl = new UlcRoboticsGps();
         }
         else if ("UlcRoboticsNicbotBody" == deviceType)
         {
            deviceControl = new UlcRoboticsNicbotBody();
         }
         else if ("UlcRoboticsNicbotWheel" == deviceType)
         {
            deviceControl = new UlcRoboticsNicbotWheel();
         }                        

         if (null != deviceControl)
         {
            string busId = (0 != this.BusComboBox.SelectedIndex) ? "B" : "A";
            deviceControl.SetBusId(busId);
            this.AddDevice(nextControlTop, deviceControl);
         }
      }
Example #2
0
      private void ReadConfiguration(string filePath)
      {
         try
         {
            foreach (DeviceControl deviceControl in this.deviceList)
            {
               this.DevicePanel.Controls.Remove(deviceControl);
            }

            this.deviceList.Clear();
            this.busADeviceList.Clear();
            this.busBDeviceList.Clear();

            using (XmlReader reader = XmlReader.Create(filePath))
            {
               bool result = true;
               int nextControlTop = 0;
               DeviceControl deviceControl = null;

               for (; result; )
               {
                  result = reader.Read();

                  if (reader.IsStartElement() != false)
                  {
                     if (null != deviceControl)
                     {
                        deviceControl.Read(reader);
                     }
                     else if ("Type" == reader.Name)
                     {
                        reader.Read();

                        if ("NICBOT.BusSim.ElmoMotorDeviceControl" == reader.Value)
                        {
                           deviceControl = new ElmoMotorDeviceControl();
                        }
                        else if ("NICBOT.BusSim.PeakDigitalIoDeviceControl" == reader.Value)
                        {
                           deviceControl = new PeakDigitalIoDeviceControl();
                        }
                        else if ("NICBOT.BusSim.PeakAnalogIoDeviceControl" == reader.Value)
                        {
                           deviceControl = new PeakAnalogIoDeviceControl();
                        }
                        else if ("NICBOT.BusSim.UlcRoboticsCamera" == reader.Value)
                        {
                           deviceControl = new UlcRoboticsCamera();
                        }
                        else if ("NICBOT.BusSim.UlcRoboticsGps" == reader.Value)
                        {
                           deviceControl = new UlcRoboticsGps();
                        }
                        else if ("NICBOT.BusSim.UlcRoboticsNicbotBody" == reader.Value)
                        {
                           deviceControl = new UlcRoboticsNicbotBody();
                        }
                        else if ("NICBOT.BusSim.UlcRoboticsNicbotWheel" == reader.Value)
                        {
                           deviceControl = new UlcRoboticsNicbotWheel();
                        }                        
                     }
                  }
                  else
                  {
                     if (reader.Name.Contains("Device") != false)
                     {
                        this.AddDevice(nextControlTop, deviceControl);
                        nextControlTop += deviceControl.Height;
                        deviceControl = null;
                     }
                  }
               }

               reader.Close();
            }
         }
         catch { }
      }
Example #3
0
      private void LoadRegistry()
      {
         RegistryKey appKey;
         object keyValue;
         int defaultValue;
         int parsedValue;

         appKey = this.GetAppKey();

         #region Window Location

         keyValue = appKey.GetValue("Height");
         defaultValue = this.MinimumSize.Height;
         this.Height = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : defaultValue) : defaultValue;

         keyValue = appKey.GetValue("Width");
         defaultValue = this.MinimumSize.Width;
         this.Width = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : defaultValue) : defaultValue;

         keyValue = appKey.GetValue("Top");
         int defaultValueTop = (SystemInformation.PrimaryMonitorSize.Height - this.Height) / 2;
         int top = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : defaultValue) : defaultValue;
                  
         keyValue = appKey.GetValue("Left");
         int defaultValueLeft = (SystemInformation.PrimaryMonitorSize.Width - this.Width) / 2;
         int left = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : defaultValue) : defaultValue;

         this.ValidateWindowLocation(ref top, ref left, defaultValueTop, defaultValueLeft);
         this.Top = top;
         this.Left = left;

         keyValue = appKey.GetValue("WindowState");
         this.WindowState = ((null != keyValue) && Enum.IsDefined(this.WindowState.GetType(), keyValue)) ? (FormWindowState)Enum.Parse(this.WindowState.GetType(), keyValue.ToString()) : FormWindowState.Normal;

         #endregion

         #region Session Information

         keyValue = appKey.GetValue("SelectedBusA");
         this.BusAInterfaceComboBox.SelectedIndex = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : 0) : 0;

         keyValue = appKey.GetValue("SelectedBusB");
         this.BusBInterfaceComboBox.SelectedIndex = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : 0) : 0;

         keyValue = appKey.GetValue("NumDevices");
         int numDevices = (null != keyValue) ? (int.TryParse(keyValue.ToString(), out parsedValue) ? parsedValue : 0) : 0;

         int nextControlTop = 0;

         for (int i = 0; i < numDevices; i++)
         {
            string deviceTag = "Device" + i.ToString();
            keyValue = appKey.GetValue(deviceTag);
            string deviceType = (null != keyValue) ? keyValue.ToString() : "";
            DeviceControl deviceControl = null;

            if ("NICBOT.BusSim.ElmoMotorDeviceControl" == deviceType)
            {
               deviceControl = new ElmoMotorDeviceControl();
            }
            else if ("NICBOT.BusSim.PeakDigitalIoDeviceControl" == deviceType)
            {
               deviceControl = new PeakDigitalIoDeviceControl();
            }
            else if ("NICBOT.BusSim.PeakAnalogIoDeviceControl" == deviceType)
            {
               deviceControl = new PeakAnalogIoDeviceControl();
            }
            else if ("NICBOT.BusSim.UlcRoboticsCamera" == deviceType)
            {
               deviceControl = new UlcRoboticsCamera();
            }
            else if ("NICBOT.BusSim.UlcRoboticsGps" == deviceType)
            {
               deviceControl = new UlcRoboticsGps();
            }
            else if ("NICBOT.BusSim.UlcRoboticsNicbotBody" == deviceType)
            {
               deviceControl = new UlcRoboticsNicbotBody();
            }
            else if ("NICBOT.BusSim.UlcRoboticsNicbotWheel" == deviceType)
            {
               deviceControl = new UlcRoboticsNicbotWheel();
            }                        

            if (null != deviceControl)
            {
               deviceControl.LoadRegistry(appKey, deviceTag);
               this.AddDevice(nextControlTop, deviceControl);
               nextControlTop += deviceControl.Height;
            }
         }

         #endregion
      }