예제 #1
0
        public static Encoder Load(XmlNode xml, List <KeysDevice> keysDevices)
        {
            Encoder    result       = new Encoder();
            string     keysDeviceId = xml.Attributes["keysDevice"].Value;
            KeysDevice keysDevice   = keysDevices.Find(delegate(KeysDevice o)
            {
                return(o.Id == keysDeviceId);
            });

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

            result.KeysDevice  = keysDevice;
            result.Description = xml.Attributes["description"].Value;
            result.Index       = byte.Parse(xml.Attributes["index"].Value);
            if (xml.Attributes["fast"] != null)
            {
                result.DetectFast = bool.Parse(xml.Attributes["fast"].Value);
            }
            if (xml.Attributes["fastTime"] != null)
            {
                result.FastTime = long.Parse(xml.Attributes["fastTime"].Value);
            }
            if (xml.Attributes["type"] != null)
            {
                result.Type = (EncoderType)Enum.Parse(typeof(EncoderType), xml.Attributes["type"].Value);
            }
            return(result);
        }
        public void RemoveDevice(KeysDevice device)
        {
            // usunięcie keys
            List <Key> keys = new List <Key>(Keys);

            keys.RemoveAll(delegate(Key o)
            {
                return(o.KeysDevice == device);
            });
            Keys = keys.ToArray();

            // usunięcie enkoderów
            List <Encoder> encoders = new List <Encoder>(Encoders);

            encoders.RemoveAll(delegate(Encoder o)
            {
                return(o.KeysDevice == device);
            });
            Encoders = encoders.ToArray();

            // usunięcie urządzenia
            List <KeysDevice> devs = new List <KeysDevice>(KeysDevices);

            devs.Remove(device);
            KeysDevices = devs.ToArray();
        }
예제 #3
0
        public AddEditKeyDevice(XMLConfiguration configuration, int keysDeviceIndex, RS232Configuration interf)
        {
            _configuration   = configuration;
            _keysDeviceIndex = keysDeviceIndex;
            _interf          = interf;

            InitializeComponent();

            if (keysDeviceIndex < 0)
            {
                // dodanie nowego
                Text = "Dodaj nowe wejścia cyfrowe";
                comboBox1.SelectedIndex = 0;
                ComboBox1SelectedIndexChanged(null, null);
            }
            else
            {
                // edycja istniejącego
                Text = "Edycja wejść cyfrowych";
                KeysDevice keysd = (KeysDevice)configuration.KeysDevices[keysDeviceIndex];
                textBox2.Text        = keysd.Description;
                checkBox1.Checked    = keysd.HardwareIndexes;
                numericUpDown2.Value = keysd.Delay;
                List <Key> keys = new List <Key>();
                for (int i = 0; i < configuration.Keys.Length; i++)
                {
                    Key key = configuration.Keys[i];
                    if (key.KeysDevice == keysd)
                    {
                        keys.Add(key);
                    }
                }
                keys.Sort(delegate(Key left, Key right)
                {
                    return(left.Index.CompareTo(right.Index));
                });
                for (int j = 0; j < keys.Count; j++)
                {
                    dataGridView1.Rows.Add((j).ToString(), keys[j].ID, keys[j].Description);
                }
                comboBox1.SelectedItem = dataGridView1.Rows.Count.ToString();
                ComboBox1SelectedIndexChanged(null, null);
                _loading             = true;
                numericUpDown1.Value = keysd.DeviceId;
                _loading             = false;
            }
        }
        void Button1Click(object sender, EventArgs e)
        {
            // sprawdzenie
            string description = textBox1.Text.Trim();

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

            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Nie wybrano urządzenia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox1.Focus();
                return;
            }
            KeysDevice device = ((KD)comboBox1.SelectedItem).Device;

            if (comboBox2.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Nie wybrano wejść enkodera.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox2.Focus();
                return;
            }
            int index = ((EI)comboBox2.SelectedItem).Index;

            if (_encoder == null)
            {
                // dodanie nowego enkodera
                _encoder = new Encoder();

                List <Encoder> encoders = new List <Encoder>(_configuration.Encoders);
                encoders.Add(_encoder);
                _configuration.Encoders = encoders.ToArray();
            }
            _encoder.Description = description;
            _encoder.Index       = (byte)index;
            _encoder.Type        = (EncoderType)comboBox3.SelectedIndex;
            _encoder.KeysDevice  = device;
            _encoder.DetectFast  = checkBox1.Checked;

            DialogResult = DialogResult.OK;
            Close();
        }
예제 #5
0
        public static Key Load(XmlNode xml, List <KeysDevice> keysDevices)
        {
            Key        result       = new Key();
            string     keysDeviceId = xml.Attributes["keysDevice"].Value;
            KeysDevice keysDevice   = keysDevices.Find(delegate(KeysDevice o)
            {
                return(o.Id == keysDeviceId);
            });

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

            result.KeysDevice  = keysDevice;
            result.ID          = xml.Attributes["id"].Value;
            result.Description = xml.Attributes["description"].Value;
            result.Index       = byte.Parse(xml.Attributes["index"].Value);
            return(result);
        }
예제 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            // sprawdzenie poprawności danych
            byte   deviceId    = (byte)numericUpDown1.Value;
            byte   keysCount   = (byte)int.Parse((string)comboBox1.SelectedItem);
            string id          = _keysDeviceIndex < 0 ? Guid.NewGuid().ToString() : _configuration.KeysDevices[_keysDeviceIndex].Id;
            string description = textBox2.Text.Trim();

            textBox2.Text = description;
            byte delay           = (byte)numericUpDown2.Value;
            bool hardwareIndexes = checkBox1.Checked;

            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 (_keysDeviceIndex == -1 || _configuration.KeysDevices[_keysDeviceIndex].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 keys
            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 wejścia '{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 keys
            for (int i = 0; i < _configuration.Keys.Length; i++)
            {
                Key key = (Key)_configuration.Keys[i];
                if (key.KeysDevice.Id == id)
                {
                    continue;
                }

                if (ids.FindIndex(delegate(string o)
                {
                    return(o == key.ID);
                }) > -1)
                {
                    MessageBox.Show(this, string.Format("Identyfikator '{0}' jest już wykorzystywany.", key.ID), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (_keysDeviceIndex > -1)
            {
                KeysDevice dev = _configuration.KeysDevices[_keysDeviceIndex];
                dev.Description     = description;
                dev.DeviceId        = deviceId;
                dev.KeysCount       = keysCount;
                dev.Delay           = delay;
                dev.HardwareIndexes = hardwareIndexes;

                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
                    Key lcd3 = Array.Find <Key>(_configuration.Keys, delegate(Key o)
                    {
                        return(o.KeysDevice == dev && o.Index == dindex);
                    });

                    if (lcd3 != null)
                    {
                        lcd3.ID          = did;
                        lcd3.Description = ddescription;
                    }
                    else
                    {
                        Key lcd4 = new Key()
                        {
                            Description = ddescription,
                            ID          = did,
                            Index       = dindex,
                            KeysDevice  = dev
                        };
                        List <Key> lcds2 = new List <Key>(_configuration.Keys);
                        lcds2.Add(lcd4);
                        _configuration.Keys = lcds2.ToArray();
                    }
                }

                // usunięcie encoderów
                List <Encoder> encoders = new List <Encoder>(_configuration.Encoders);
                encoders.RemoveAll(delegate(Encoder o)
                {
                    int index = o.Index * 2;
                    return(index >= keysCount);
                });
                _configuration.Encoders = encoders.ToArray();

                // usunięcie diod
                List <Key> diodyOld = new List <Key>(_configuration.Keys);
                diodyOld.RemoveAll(delegate(Key o)
                {
                    return(o.KeysDevice == dev && o.Index >= dataGridView1.Rows.Count);
                });
                _configuration.Keys = diodyOld.ToArray();
            }
            else
            {
                // dodanie nowego urządzenia i wyświetlaczy
                KeysDevice dev = new KeysDevice()
                {
                    Description     = description,
                    DeviceId        = deviceId,
                    Id              = id,
                    Interface       = _interf,
                    KeysCount       = keysCount,
                    Delay           = delay,
                    HardwareIndexes = hardwareIndexes
                };
                List <KeysDevice> devsAll = new List <KeysDevice>(_configuration.KeysDevices);
                devsAll.Add(dev);
                _configuration.KeysDevices = devsAll.ToArray();
                AddedKeysDevice            = 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;

                    Key lcd4 = new Key()
                    {
                        Description = ddescription,
                        ID          = did,
                        Index       = dindex,
                        KeysDevice  = dev
                    };
                    List <Key> lcds2 = new List <Key>(_configuration.Keys);
                    lcds2.Add(lcd4);
                    _configuration.Keys = lcds2.ToArray();
                }
            }

            DialogResult = DialogResult.OK;
            Close();
        }
예제 #7
0
        void Button4Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null || treeView1.SelectedNode == _root)
            {
                return;
            }

            if (treeView1.SelectedNode is InterfaceTreeNode)
            {
                RS232Configuration     rs = ((InterfaceTreeNode)treeView1.SelectedNode).Interface;
                AddEditInterfaceDialog d  = new AddEditInterfaceDialog(Configuration, rs);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    ((InterfaceTreeNode)treeView1.SelectedNode).RefreshText();
                    ShowInfo();
                }
            }

            if (treeView1.SelectedNode.Tag is LCDDevice)
            {
                LCDDevice        dev = (LCDDevice)treeView1.SelectedNode.Tag;
                AddEditLCDDevice d   = new AddEditLCDDevice(Configuration, Array.IndexOf(Configuration.LCDDevices, dev), dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    if (d.LCDReduction)
                    {
                        ShowLCDAreas();
                    }
                }
            }

            if (treeView1.SelectedNode.Tag is LEDDevice)
            {
                LEDDevice        dev = (LEDDevice)treeView1.SelectedNode.Tag;
                AddEditLEDDevice d   = new AddEditLEDDevice(Configuration, Array.IndexOf(Configuration.LEDDevices, dev), dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    ShowLEDs();
                }
            }

            if (treeView1.SelectedNode.Tag is LEDDisplayDevice)
            {
                LEDDisplayDevice dev            = (LEDDisplayDevice)treeView1.SelectedNode.Tag;
                AddEditLEDDisplayDeviceDialog d = new AddEditLEDDisplayDeviceDialog(Configuration, Array.IndexOf(Configuration.LEDDisplayDevices, dev), dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    ShowLEDDisplays();
                }
            }

            if (treeView1.SelectedNode.Tag is Steppers.StepperDevice)
            {
                Steppers.StepperDevice        dev = (Steppers.StepperDevice)treeView1.SelectedNode.Tag;
                Steppers.AddEditStepperDevice d   = new Steppers.AddEditStepperDevice(Configuration, dev, dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    ShowSteppers();
                }
            }

            if (treeView1.SelectedNode.Tag is Servos.ServoDevice)
            {
                Servos.ServoDevice        dev = (Servos.ServoDevice)treeView1.SelectedNode.Tag;
                Servos.AddEditServoDevice d   = new Servos.AddEditServoDevice(Configuration, Array.IndexOf(Configuration.ServoDevices, dev), dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    ShowServos();
                }
            }

            if (treeView1.SelectedNode.Tag is KeysDevice)
            {
                KeysDevice       dev = (KeysDevice)treeView1.SelectedNode.Tag;
                AddEditKeyDevice d   = new AddEditKeyDevice(Configuration, Array.IndexOf(Configuration.KeysDevices, dev), dev.Interface);
                if (d.ShowDialog(this) == DialogResult.OK)
                {
                    treeView1.SelectedNode.Text = dev.Name2;
                    ShowInfo();
                    ShowKeys();
                }
            }
        }
예제 #8
0
        void Button5Click(object sender, EventArgs e)
        {
            // sprawdzenie co wybrano
            if (treeView1.SelectedNode == null || treeView1.SelectedNode == _root)
            {
                return;
            }

            if (treeView1.SelectedNode is InterfaceTreeNode)
            {
                RS232Configuration rs = ((InterfaceTreeNode)treeView1.SelectedNode).Interface;
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć interfejs '{0}' i wszystkie urządzenia podpięte do tego interfejsu ?", rs.Id), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (treeView1.SelectedNode.Nodes.Count > 0)
                    {
                        // usunięcie urządzeń przypiętych do tego interfejsu
                        int index = treeView1.SelectedNode.Nodes.Count;
                        while (index-- > 0)
                        {
                            TreeNode node = treeView1.SelectedNode.Nodes[index];
                            // sprawdzenie czy to LEDDevice
                            if (node.Tag is LEDDevice)
                            {
                                if (((LEDDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((LEDDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }

                            // sprawdzenie czy to LCDDevice
                            if (node.Tag is LEDDisplayDevice)
                            {
                                if (((LEDDisplayDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((LEDDisplayDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }

                            // sprawdzenie czy to LEDDisplayDevice
                            if (node.Tag is LCDDevice)
                            {
                                if (((LCDDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((LCDDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }

                            // sprawdzenie czy to StepperDevice
                            if (node.Tag is Steppers.StepperDevice)
                            {
                                if (((Steppers.StepperDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((Steppers.StepperDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }

                            // sprawdzenie czy to ServoDevice
                            if (node.Tag is Servos.ServoDevice)
                            {
                                if (((Servos.ServoDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((Servos.ServoDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }

                            // sprawdzenie czy to KeysDevice
                            if (node.Tag is KeysDevice)
                            {
                                if (((KeysDevice)node.Tag).Interface == rs)
                                {
                                    Configuration.RemoveDevice((KeysDevice)node.Tag);
                                    treeView1.SelectedNode.Nodes.Remove(node);
                                    continue;
                                }
                            }
                        }
                        ShowVariables();
                    }

                    // usunięcie interfejsu
                    List <RS232Configuration> rss = new List <RS232Configuration>(Configuration.Interfaces);
                    rss.Remove(rs);
                    Configuration.Interfaces = rss.ToArray();

                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is LCDDevice)
            {
                LCDDevice dev = (LCDDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć wyświetlacze '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowLCDAreas();
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is LEDDevice)
            {
                LEDDevice dev = (LEDDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć diody '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowLEDs();
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is LEDDisplayDevice)
            {
                LEDDisplayDevice dev = (LEDDisplayDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć wyświetlacze 7-LED '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowLEDDisplays();
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is Steppers.StepperDevice)
            {
                Steppers.StepperDevice dev = (Steppers.StepperDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć silniki krokowe '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowSteppers();
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is Servos.ServoDevice)
            {
                Servos.ServoDevice dev = (Servos.ServoDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć serwomechanizmy '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowServos();
                }
                return;
            }

            if (treeView1.SelectedNode.Tag is KeysDevice)
            {
                KeysDevice dev = (KeysDevice)treeView1.SelectedNode.Tag;
                // pytanie
                if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć wejścia cyfrowe '{0}' ?", dev.Description), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Configuration.RemoveDevice(dev);

                    // usunięcie węzła
                    treeView1.SelectedNode.Parent.Nodes.Remove(treeView1.SelectedNode);
                    ShowInfo();
                    ShowKeys();
                }
                return;
            }
        }
예제 #9
0
        private void ShowInfo()
        {
            ClearInfo();
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            if (treeView1.SelectedNode == _root)
            {
                // możliwość dodania nowego interfejsu
                button6.Enabled = true;
                _addAction      = AddActions.Interface;
                return;
            }

            if (treeView1.SelectedNode is InterfaceTreeNode)
            {
                RS232Configuration rs = ((InterfaceTreeNode)treeView1.SelectedNode).Interface;
                textBox1.Text     = rs.Id;
                textBox2.Text     = "Interfejs RS232";
                textBox3.Text     = string.Format("Port COM: {0}", rs.PortName);
                textBox6.Text     = string.Format("Prędkość: {0}, Bity: {1}, Parzystość: {2}, Stop: {3}", rs.BaudRate, rs.DataBits, rs.Parity, rs.StopBits);
                groupBox3.Enabled = true;

                // możliwość dodania, edycji i usunięcia
                button6.Enabled = button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.Device;

                return;
            }

            if (treeView1.SelectedNode.Tag is LCDDevice)
            {
                LCDDevice lcdd = (LCDDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", lcdd.DeviceId);
                textBox2.Text     = "Wyświetlacze LCD";
                textBox3.Text     = lcdd.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }

            if (treeView1.SelectedNode.Tag is LEDDevice)
            {
                LEDDevice lcdd = (LEDDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", lcdd.DeviceId);
                textBox2.Text     = "Diody LED";
                textBox3.Text     = lcdd.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }

            if (treeView1.SelectedNode.Tag is LEDDisplayDevice)
            {
                LEDDisplayDevice lcdd = (LEDDisplayDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", lcdd.DeviceId);
                textBox2.Text     = "Wyświetlacze 7-LED";
                textBox3.Text     = lcdd.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }

            if (treeView1.SelectedNode.Tag is Steppers.StepperDevice)
            {
                Steppers.StepperDevice stepperD = (Steppers.StepperDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", stepperD.DeviceId);
                textBox2.Text     = "Silniki krokowe";
                textBox3.Text     = stepperD.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }

            if (treeView1.SelectedNode.Tag is Servos.ServoDevice)
            {
                Servos.ServoDevice servoD = (Servos.ServoDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", servoD.DeviceId);
                textBox2.Text     = "Serwomechanizmy";
                textBox3.Text     = servoD.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }

            if (treeView1.SelectedNode.Tag is KeysDevice)
            {
                KeysDevice keysd = (KeysDevice)treeView1.SelectedNode.Tag;
                textBox1.Text     = string.Format("{0}", keysd.DeviceId);
                textBox2.Text     = string.Format("Wejścia cyfrowe {0}", keysd.KeysCount);
                textBox3.Text     = keysd.Description;
                groupBox3.Enabled = true;

                // możliwość edycji i usunięcia
                button6.Enabled = false;
                button4.Enabled = button5.Enabled = true;

                _addAction = AddActions.None;
            }
        }
예제 #10
0
        public static XMLConfiguration Load()
        {
            if (__instance != null)
            {
                return(__instance);
            }

            if (!File.Exists(ConfigurationFilePath))
            {
                throw new FileNotFoundException(ConfigurationFilePath);
            }
            XMLConfiguration c   = new XMLConfiguration();
            XmlDocument      xml = new XmlDocument();

            xml.Load(ConfigurationFilePath);

            // wczytanie interfejsów
            List <RS232Configuration> interfaces = new List <RS232Configuration>();
            XmlNodeList nodes = xml.SelectNodes("/configuration/interfaces/interface");

            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    RS232Configuration interf = RS232Configuration.Load(node);
                    interfaces.Add(interf);
                }
            }
            c.Interfaces = interfaces.ToArray();

            // wczytanie urządzeń z LCD
            List <LCDDevice> lcdDevices = new List <LCDDevice>();

            nodes = xml.SelectNodes("/configuration/lcdDevices/lcdDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LCDDevice lcdDevice = LCDDevice.Load(node, interfaces);
                    if (lcdDevice != null)
                    {
                        lcdDevices.Add(lcdDevice);
                    }
                }
            }
            c.LCDDevices = lcdDevices.ToArray();

            // wczytanie LCD
            List <RS232LCD> lcds = new List <RS232LCD>();

            nodes = xml.SelectNodes("/configuration/lcds/lcd");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    RS232LCD lcd = RS232LCD.Load(lcdDevices, node);
                    if (lcd != null)
                    {
                        lcds.Add(lcd);
                    }
                }
            }
            c.LCDs = lcds.ToArray();

            // wczytanie obszarów LCD
            List <LCDArea> areas = new List <LCDArea>();

            nodes = xml.SelectNodes("/configuration/lcdAreas/area");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LCDArea area = new LCDArea(node, new LCDSet(lcds));
                    areas.Add(area);
                }
            }
            c.Areas = areas.ToArray();

            // wczytanie urządzeń z LED
            List <LEDDevice> ledDevices = new List <LEDDevice>();

            nodes = xml.SelectNodes("/configuration/ledDevices/ledDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LEDDevice ledDevice = LEDDevice.Load(node, interfaces);
                    if (ledDevice != null)
                    {
                        ledDevices.Add(ledDevice);
                    }
                }
            }
            c.LEDDevices = ledDevices.ToArray();

            // wczytanie LED
            List <LED> leds = new List <LED>();

            nodes = xml.SelectNodes("/configuration/leds/led");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LED led = LED.Load(node, ledDevices);
                    if (led != null)
                    {
                        leds.Add(led);
                    }
                }
            }
            c.LEDs = leds.ToArray();

            // wczytanie obszarów LED
            List <LEDGroup> ledGroups = new List <LEDGroup>();

            nodes = xml.SelectNodes("/configuration/leds/leds");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LEDGroup ledGroup = LEDGroup.Load(node, leds);
                    if (ledGroup != null)
                    {
                        ledGroups.Add(ledGroup);
                    }
                }
            }
            c.LEDGroups = ledGroups.ToArray();

            // wczytanie urządzeń z 7-LED
            List <LEDDisplayDevice> ledDisplayDevices = new List <LEDDisplayDevice>();

            nodes = xml.SelectNodes("/configuration/ledDisplayDevices/ledDisplayDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LEDDisplayDevice ledDisplayDevice = LEDDisplayDevice.Load(node, interfaces);
                    if (ledDisplayDevice != null)
                    {
                        ledDisplayDevices.Add(ledDisplayDevice);
                    }
                }
            }
            c.LEDDisplayDevices = ledDisplayDevices.ToArray();

            // wczytanie 7-LED
            List <LEDDisplay> ledDisplays = new List <LEDDisplay>();

            nodes = xml.SelectNodes("/configuration/ledDisplays/ledDisplay");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LEDDisplay ledDisplay = LEDDisplay.Load(node, ledDisplayDevices);
                    if (ledDisplay != null)
                    {
                        ledDisplays.Add(ledDisplay);
                    }
                }
            }
            c.LEDDisplays = ledDisplays.ToArray();

            // wczytanie obszarów 7-LED
            List <LEDDisplayGroup> ledDisplayGroups = new List <LEDDisplayGroup>();

            nodes = xml.SelectNodes("/configuration/ledDisplays/ledDisplays");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    LEDDisplayGroup ledDisplayGroup = LEDDisplayGroup.Load(node, ledDisplays);
                    if (ledDisplayGroup != null)
                    {
                        ledDisplayGroups.Add(ledDisplayGroup);
                    }
                }
            }
            c.LEDDisplayGroups = ledDisplayGroups.ToArray();

            // wczytanie słownika dla wyświetlaczy 7-segmentowych
            XmlNode dictionaryNode = xml.SelectSingleNode("/configuration/ledDisplaysDictionary");

            c.LEDDisplaysDictionary = LEDDisplaysDictionary.Load(dictionaryNode);

            // wczytanie urządzeń Keys
            List <KeysDevice> keysDevices = new List <KeysDevice>();

            nodes = xml.SelectNodes("/configuration/keysDevices/keysDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    KeysDevice keysDevice = KeysDevice.Load(node, interfaces);
                    if (keysDevice != null)
                    {
                        keysDevices.Add(keysDevice);
                    }
                }
            }
            c.KeysDevices = keysDevices.ToArray();

            // wczytanie keys
            List <Key> keys = new List <Key>();

            nodes = xml.SelectNodes("/configuration/keys/key");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    Key key = Key.Load(node, keysDevices);
                    if (key != null)
                    {
                        keys.Add(key);
                    }
                }
            }
            c.Keys = keys.ToArray();

            // wczytanie encoders
            List <Encoder> encoders = new List <Encoder>();

            nodes = xml.SelectNodes("/configuration/encoders/encoder");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    Encoder encoder = Encoder.Load(node, keysDevices);
                    if (encoder != null)
                    {
                        encoders.Add(encoder);

                        // przypisanie enkoderów do wejść (wykrywanie szybkiego kręcenia)
                        foreach (Key key in c.Keys)
                        {
                            if (key.KeysDevice == encoder.KeysDevice)
                            {
                                if (key.Index == encoder.LeftIndex || key.Index == encoder.RightIndex)
                                {
                                    key.Encoder = encoder;
                                }
                            }
                        }
                    }
                }
            }
            c.Encoders = encoders.ToArray();

            // wczytanie stepper motors
            List <StepperDevice> stepperDevices = new List <StepperDevice>();

            nodes = xml.SelectNodes("/configuration/stepperDevices/stepperDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    StepperDevice stepperDevice = StepperDevice.Load(node, interfaces);
                    if (stepperDevice != null)
                    {
                        stepperDevices.Add(stepperDevice);
                    }
                }
            }
            c.StepperDevices = stepperDevices.ToArray();

            // wczytanie servo devices
            List <ServoDevice> servoDevices = new List <ServoDevice>();

            nodes = xml.SelectNodes("/configuration/servoDevices/servoDevice");
            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    ServoDevice servoDevice = ServoDevice.Load(node, interfaces);
                    if (servoDevice != null)
                    {
                        servoDevices.Add(servoDevice);
                    }
                }
            }
            c.ServoDevices = servoDevices.ToArray();


            __instance = c;

            return(__instance);
        }