public static StepperDevice Load(XmlNode xml, List <RS232Configuration> interfaces)
        {
            StepperDevice result = null;

            // odczytanie typu
            StepperDeviceType type = (StepperDeviceType)Enum.Parse(typeof(StepperDeviceType), xml.Attributes["type"].Value);

            switch (type)
            {
            case StepperDeviceType.Simple:
                result = new SimpleStepperDevice();
                break;

            default:
                return(null);
            }

            string             interfaceId = xml.Attributes["interface"].Value;
            RS232Configuration interf      = interfaces.Find(delegate(RS232Configuration o)
            {
                return(o.Id == interfaceId);
            });

            if (interf == null)
            {
                return(null);
            }

            result.Interface   = interf;
            result.Id          = xml.Attributes["id"].Value;
            result.Description = xml.Attributes["description"].Value;
            result.DeviceId    = byte.Parse(xml.Attributes["device"].Value);
            result.Load(xml);
            return(result);
        }
示例#2
0
        public static ServoDevice Load(XmlNode xml, List <RS232Configuration> interfaces)
        {
            ServoDevice result = new ServoDevice();

            string             interfaceId = xml.Attributes["interface"].Value;
            RS232Configuration interf      = interfaces.Find(delegate(RS232Configuration o)
            {
                return(o.Id == interfaceId);
            });

            if (interf == null)
            {
                return(null);
            }

            result.Interface   = interf;
            result.Id          = xml.Attributes["id"].Value;
            result.Description = xml.Attributes["description"].Value;
            result.DeviceId    = byte.Parse(xml.Attributes["device"].Value);

            List <Servo> servos = new List <Servo>();

            foreach (XmlNode node in xml.SelectNodes("servo"))
            {
                Servo s = Servo.Load(node);
                if (s != null)
                {
                    s.Device = result;
                    servos.Add(s);
                }
            }
            result.Servos = servos.ToArray();

            return(result);
        }
示例#3
0
        public AddEditServoDevice(XMLConfiguration configuration, int servoDeviceIndex, RS232Configuration interf)
        {
            InitializeComponent();

            _configuration    = configuration;
            _servoDeviceIndex = servoDeviceIndex;
            _interf           = interf;

            if (servoDeviceIndex < 0)
            {
                // dodanie nowego
                Text = "Dodaj nowe serwomechanizmy";
                NumericUpDown2ValueChanged(null, null);
            }
            else
            {
                // edycja istniejącego
                Text = "Edycja serwomechanizmów";
                ServoDevice servod = (ServoDevice)configuration.ServoDevices[servoDeviceIndex];
                textBox2.Text = servod.Description;
                for (int j = 0; j < servod.Servos.Length; j++)
                {
                    dataGridView1.Rows.Add((j + 1).ToString(), servod.Servos[j].Id, servod.Servos[j].Description);
                }
                if (dataGridView1.Rows.Count < numericUpDown2.Value)
                {
                    NumericUpDown2ValueChanged(null, null);
                }
                numericUpDown2.Value = dataGridView1.Rows.Count;
                _loading             = true;
                numericUpDown1.Value = servod.DeviceId;
                _loading             = false;
            }
        }
        public AddEditStepperDevice(XMLConfiguration configuration, StepperDevice stepperDevice, RS232Configuration interf)
        {
            _configuration = configuration;
            StepperDevice  = stepperDevice;
            _interf        = interf;

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            if (StepperDevice == null)
            {
                Text = "Dodaj silniki krokowe";
                NumericUpDown1ValueChanged(this, EventArgs.Empty);
            }
            else
            {
                Text = "Edytuj silniki krokowe";

                textBox2.Text        = StepperDevice.Description;
                numericUpDown1.Value = StepperDevice.DeviceId;

                textBox1.Text        = StepperDevice.Motor1.Id;
                textBox3.Text        = StepperDevice.Motor1.Description;
                numericUpDown2.Value = StepperDevice.Motor1.StepsFor360;
                numericUpDown3.Value = StepperDevice.Motor1.MinStepInterval;
                checkBox1.Checked    = StepperDevice.Motor1.HasZeroSensor;
                checkBox2.Checked    = StepperDevice.Motor1.InvertZeroSensor;
                checkBox3.Checked    = StepperDevice.Motor1.ReverseDirection;

                textBox5.Text        = StepperDevice.Motor2.Id;
                textBox4.Text        = StepperDevice.Motor2.Description;
                numericUpDown5.Value = StepperDevice.Motor2.StepsFor360;
                numericUpDown4.Value = StepperDevice.Motor2.MinStepInterval;
                checkBox6.Checked    = StepperDevice.Motor2.HasZeroSensor;
                checkBox5.Checked    = StepperDevice.Motor2.InvertZeroSensor;
                checkBox4.Checked    = StepperDevice.Motor2.ReverseDirection;
            }
        }