Esempio n. 1
0
        private void ShowServo()
        {
            if (_lastServo != null)
            {
                _lastServo.SetEnable(false);
            }
            _lastServo = SelectedServo;

            textBox4.Text = "";
            if (_lastServo == null)
            {
                groupBox4.Enabled = false;
                return;
            }
            groupBox4.Enabled = true;

            textBox4.Text = string.Format("{0} - {1}", _lastServo.Id, _lastServo.Description);
            int pos = _lastServo.Position;

            if (pos < trackBar1.Minimum)
            {
                pos = trackBar1.Minimum;
            }
            if (pos > trackBar1.Maximum)
            {
                pos = trackBar1.Maximum;
            }
            _lastServo.SetEnable(true);
            trackBar1.Value = pos;
        }
Esempio n. 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);
        }
Esempio n. 3
0
 void Button14Click(object sender, EventArgs e)
 {
     Servos.Servo servo = SelectedServo;
     if (servo != null)
     {
         servo.Max = trackBar1.Value;
         gridServos.Rows[gridServos.CurrentCell.RowIndex].Cells[4].Value = servo.Max;
     }
 }
Esempio n. 4
0
 void Button13Click(object sender, EventArgs e)
 {
     Servos.Servo servo = SelectedServo;
     if (servo != null)
     {
         servo.InitialPosition = trackBar1.Value;
         gridServos.Rows[gridServos.CurrentCell.RowIndex].Cells[3].Value = servo.InitialPosition;
     }
 }
Esempio n. 5
0
 void Timer2Tick(object sender, EventArgs e)
 {
     if (Working)
     {
         Servos.Servo servo = SelectedServo;
         if (servo != null)
         {
             servo.Position = trackBar1.Value;
         }
     }
 }
Esempio n. 6
0
        public static Servo Load(XmlNode xml)
        {
            if (xml == null)
            {
                return(null);
            }

            Servo result = new Servo();

            result.Id              = xml.Attributes["id"].Value;
            result.Description     = xml.Attributes["description"].Value;
            result.Index           = byte.Parse(xml.Attributes["index"].Value);
            result.Min             = int.Parse(xml.Attributes["min"].Value);
            result.Max             = int.Parse(xml.Attributes["max"].Value);
            result.InitialPosition = int.Parse(xml.Attributes["initialPosition"].Value);
            return(result);
        }
Esempio n. 7
0
 public ServoDevice()
 {
     Servos = new Servo[0];
 }
Esempio n. 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            // sprawdzenie poprawności danych
            byte   deviceId    = (byte)numericUpDown1.Value;
            byte   ledsCount   = (byte)numericUpDown2.Value;
            string id          = _servoDeviceIndex < 0 ? Guid.NewGuid().ToString() : _configuration.ServoDevices[_servoDeviceIndex].Id;
            string description = textBox2.Text.Trim();

            textBox2.Text = description;

            if (description.Length == 0)
            {
                MessageBox.Show(this, string.Format("Nie podano opisu."), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox2.Focus();
                return;
            }

            // sprawdzenie czy na tym interfejsie jest już urządzenie o takim ID
            if (_servoDeviceIndex == -1 || _configuration.ServoDevices[_servoDeviceIndex].DeviceId != deviceId)
            {
                if (_configuration.ExistsDevice(_interf, deviceId))
                {
                    MessageBox.Show(this, string.Format("Podany identyfikator urządzenia jest już używany na tym interfejsie."), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    numericUpDown1.Focus();
                    return;
                }
            }

            // sprawdzenie poprawności identyfikatorów diod
            List <string> ids = new List <string>();

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                string id2 = (string)dataGridView1.Rows[i].Cells[1].Value;
                id2 = id2.Trim();
                if (id2.Length == 0)
                {
                    MessageBox.Show(this, string.Format("Nie podano identyfikatora dla serwomechanizmu '{0}'.", (i + 1)), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (ids.Contains(id2))
                {
                    MessageBox.Show(this, string.Format("Identyfikator '{0}' został użyty więcj niż jeden raz.", id2), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                ids.Add(id2);
            }

//            // sprawdzenie czy identyfikatory diod
//            for (int i = 0; i < _configuration.ServoDevices.Length; i++)
//            {
//                ServoDevice servoD = _configuration.ServoDevices[i];
//                if (servoD.Id == id)
//                {
//                    continue;
//                }
//
//                if (ids.FindIndex(delegate(string o)
//                                  {
//                                      return o == led.ID;
//                                  }) > -1)
//                {
//                    MessageBox.Show(this, string.Format("Identyfikator '{0}' jest już wykorzystywany.", led.ID), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//                    return;
//                }
//            }

            if (_servoDeviceIndex > -1)
            {
                ServoDevice dev = _configuration.ServoDevices[_servoDeviceIndex];
                dev.Description = description;
                dev.DeviceId    = deviceId;

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    byte   dindex       = (byte)i;// byte.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) - 1;
                    string did          = (string)dataGridView1.Rows[i].Cells[1].Value;
                    string ddescription = (string)dataGridView1.Rows[i].Cells[2].Value;

                    // aktualizacja ustawień wyświetlacza lub dodanie nowego
                    Servo servo = Array.Find <Servo>(dev.Servos, delegate(Servo o)
                    {
                        return(o.Index == dindex);
                    });

                    if (servo != null)
                    {
                        servo.Id          = did;
                        servo.Description = ddescription;
                    }
                    else
                    {
                        servo = new Servo()
                        {
                            Description = ddescription,
                            Id          = did,
                            Index       = dindex,
                            Device      = dev
                        };
                        List <Servo> lcds2 = new List <Servo>(dev.Servos);
                        lcds2.Add(servo);
                        dev.Servos = lcds2.ToArray();
                    }
                }

//                // usunięcie diod
//                List<LED> diodyOld = new List<LED>(_configuration.LEDs);
//                diodyOld.RemoveAll(delegate(LED o)
//                                   {
//                                       return o.LEDDevice == dev && o.Index >= dataGridView1.Rows.Count;
//                                   });
//                _configuration.LEDs = diodyOld.ToArray();
            }
            else
            {
                // dodanie nowego urządzenia i wyświetlaczy
                ServoDevice dev = new ServoDevice()
                {
                    Description = description,
                    DeviceId    = deviceId,
                    Id          = id,
                    Interface   = _interf
                };
                List <ServoDevice> devsAll = new List <ServoDevice>(_configuration.ServoDevices);
                devsAll.Add(dev);
                _configuration.ServoDevices = devsAll.ToArray();
                AddedServoDevice            = dev;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    byte   dindex       = (byte)i;// byte.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
                    string did          = (string)dataGridView1.Rows[i].Cells[1].Value;
                    string ddescription = (string)dataGridView1.Rows[i].Cells[2].Value;

                    Servo lcd4 = new Servo()
                    {
                        Description = ddescription,
                        Id          = did,
                        Index       = dindex,
                        Device      = dev
                    };
                    List <Servo> lcds2 = new List <Servo>(dev.Servos);
                    lcds2.Add(lcd4);
                    dev.Servos = lcds2.ToArray();
                }
            }

            DialogResult = DialogResult.OK;
            Close();
        }