Пример #1
0
        public static KeysDevice Load(XmlNode xml, List <RS232Configuration> interfaces)
        {
            KeysDevice         result      = new KeysDevice();
            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.KeysCount   = int.Parse(xml.Attributes["keysCount"].Value);
            if (xml.Attributes["realIndexes"] != null)
            {
                result.HardwareIndexes = bool.Parse(xml.Attributes["realIndexes"].Value);
            }
            return(result);
        }
Пример #2
0
 public simINDevices(XMLConfiguration configuration, RS232Configuration interf, simINDevice [] devices)
 {
     _configuration  = configuration;
     _interface      = interf;
     _devices        = devices;
     interf.Receiver = this;
 }
 public void ReceivedByte(RS232Configuration rs, byte data)
 {
     if (!Stop)
     {
         if (!_initiated)
         {
             if (data == 2)
             {
                 _initiated   = true;
                 _waitForType = true;
             }
         }
         else
         {
             if (_waitForType)
             {
                 _waitForType = false;
                 _type        = (byte)(data & 0x0f);
             }
             else
             {
                 _initiated = false;
                 if (!_devices.ContainsKey(data))
                 {
                     _devices.Add(data, _type);
                 }
             }
         }
     }
 }
Пример #4
0
        public static LEDDevice Load(XmlNode xml, List <RS232Configuration> interfaces)
        {
            LEDDevice          result      = new LEDDevice();
            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.LEDsCount   = byte.Parse(xml.Attributes["ledsCount"].Value);
            if (xml.Attributes["indexReverse"] != null)
            {
                result.IndexReversed = bool.Parse(xml.Attributes["indexReverse"].Value);
            }
            return(result);
        }
Пример #5
0
        public AddEditLEDDevice(XMLConfiguration configuration, int ledDeviceIndex, RS232Configuration interf)
        {
            InitializeComponent();

            _configuration  = configuration;
            _ledDeviceIndex = ledDeviceIndex;
            _interf         = interf;

            if (ledDeviceIndex < 0)
            {
                // dodanie nowego
                Text = "Dodaj nowe diody LED";
                NumericUpDown2ValueChanged(null, null);
            }
            else
            {
                // edycja istniejącego
                Text = "Edycja diod LED";
                LEDDevice ledd = (LEDDevice)configuration.LEDDevices[ledDeviceIndex];
                textBox2.Text = ledd.Description;
                List <LED> leds = new List <LED>();
                for (int i = 0; i < configuration.LEDs.Length; i++)
                {
                    LED led = configuration.LEDs[i];
                    if (led.LEDDevice == configuration.LEDDevices[ledDeviceIndex])
                    {
                        leds.Add(led);
                    }
                }
                leds.Sort(delegate(LED left, LED right)
                {
                    return(left.Index.CompareTo(right.Index));
                });
                for (int j = 0; j < leds.Count; j++)
                {
                    dataGridView1.Rows.Add((j + 1).ToString(), leds[j].ID, leds[j].Description);
                }
                if (dataGridView1.Rows.Count < numericUpDown2.Value)
                {
                    NumericUpDown2ValueChanged(null, null);
                }
                numericUpDown2.Value = dataGridView1.Rows.Count;
                _loading             = true;
                numericUpDown1.Value = ledd.DeviceId;
                _loading             = false;
            }
        }
Пример #6
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;
            }
        }
        public AddEditLCDDevice(XMLConfiguration configuration, int lcdDeviceIndex, RS232Configuration interf)
        {
            InitializeComponent();

            _configuration  = configuration;
            _lcdDeviceIndex = lcdDeviceIndex;
            _interf         = interf;

            dataGridView1.Columns[3].CellTemplate = new NumericCell1_4();
            dataGridView1.Columns[4].CellTemplate = new NumericCell1_40();

            if (lcdDeviceIndex < 0)
            {
                // dodanie nowego
                Text = "Dodaj nowe wyświetlacze";
                NumericUpDown2ValueChanged(null, null);
            }
            else
            {
                // edycja istniejącego
                Text = "Edycja wyświetlaczy";
                LCDDevice lcdd = (LCDDevice)configuration.LCDDevices[lcdDeviceIndex];
                textBox2.Text = lcdd.Description;
                List <RS232LCD> lcds = new List <RS232LCD>();
                for (int i = 0; i < configuration.LCDs.Length; i++)
                {
                    RS232LCD lcd = (RS232LCD)configuration.LCDs[i];
                    if (lcd.LCDDevice == configuration.LCDDevices[lcdDeviceIndex])
                    {
                        lcds.Add(lcd);
                    }
                }
                lcds.Sort(delegate(RS232LCD left, RS232LCD right)
                {
                    return(left.Index.CompareTo(right.Index));
                });
                for (int j = 0; j < lcds.Count; j++)
                {
                    dataGridView1.Rows.Add((j + 1).ToString(), lcds[j].ID, lcds[j].Description, lcds[j].Rows, lcds[j].Columns);
                }
                numericUpDown2.Value = dataGridView1.Rows.Count;
                _loading             = true;
                numericUpDown1.Value = lcdd.DeviceId;
                _loading             = false;
            }
        }
Пример #8
0
        public AddEditInterfaceDialog(XMLConfiguration configuration, RS232Configuration interf)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            comboBox1.Items.AddRange(SerialPort.GetPortNames());

            comboBox2.Items.AddRange(new object[] { 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 256000 });
            comboBox2.SelectedItem = 57600;

            comboBox3.Items.AddRange(new object[] { 5, 6, 7, 8 });
            comboBox3.SelectedItem = 8;

            comboBox4.Items.AddRange(Enum.GetNames(typeof(Handshake)));
            comboBox4.SelectedItem = Handshake.None.ToString();

            comboBox5.Items.AddRange(Enum.GetNames(typeof(Parity)));
            comboBox5.SelectedItem = Parity.None.ToString();

            comboBox6.Items.AddRange(Enum.GetNames(typeof(StopBits)));
            comboBox6.SelectedItem = StopBits.Two.ToString();

            Interface     = interf;
            Configuration = configuration;

            if (Interface == null)
            {
                Text         = "Dodaj nowy interfejs";
                button1.Text = "Dodaj";
            }
            else
            {
                comboBox1.Text         = Interface.PortName;
                comboBox2.SelectedItem = Interface.BaudRate;
                comboBox3.SelectedItem = Interface.DataBits;
                comboBox4.SelectedItem = Interface.HandShake.ToString();
                comboBox5.SelectedItem = Interface.Parity.ToString();
                comboBox6.SelectedItem = Interface.StopBits.ToString();
                Text         = "Edytuj interfejs";
                button1.Text = "Zapisz";
            }
        }
Пример #9
0
        void Button1Click(object sender, EventArgs e)
        {
            string portName = comboBox1.Text.Trim();

            if (portName.Length == 0)
            {
                MessageBox.Show(this, "Nie wybrano/wpisano nazwy portu RS232.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox1.Focus();
                return;
            }

            // sprawdzenie czy port jest unikalny
            foreach (RS232Configuration rs in Configuration.Interfaces)
            {
                if (rs == Interface)
                {
                    continue;
                }
                if (rs.PortName == portName)
                {
                    MessageBox.Show(this, "Wybrany port jest zajęty.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    comboBox1.Focus();
                    return;
                }
            }

            if (Interface == null)
            {
                Interface = new RS232Configuration();
            }

            Interface.Id = Interface.PortName = portName;

            Interface.BaudRate  = (int)comboBox2.SelectedItem;
            Interface.DataBits  = (int)comboBox3.SelectedItem;
            Interface.HandShake = (Handshake)Enum.Parse(typeof(Handshake), comboBox4.SelectedItem.ToString());
            Interface.Parity    = (Parity)Enum.Parse(typeof(Parity), comboBox5.SelectedItem.ToString());
            Interface.StopBits  = (StopBits)Enum.Parse(typeof(StopBits), comboBox6.SelectedItem.ToString());

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #10
0
        public void ReceivedByte(RS232Configuration rs, byte data)
        {
            if (_running && !_ignore)
            {
                // analiza danych
                switch (_state)
                {
                case State.Header:
                    _data0      = data;
                    _id         = (data >> 4) & 0x0f;
                    _dataLength = data & 0x0f;
                    _state      = State.Data;
                    _dataIndex  = 0;
                    break;

                case State.Data:
                    _data[_dataIndex++] = data;
                    _dataLength--;
                    if (_dataLength == 0)
                    {
                            #if DEBUG
                        if (_dataIndex == 2)
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("Odebrano: 0x{0} 0x{1} 0x{2}", _data0.ToString("X2"), _data[0].ToString("X2"), _data[1].ToString("X2")));
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("Odebrano: 0x{0} 0x{1} 0x{2}, 0x{3}", _data0.ToString("X2"), _data[0].ToString("X2"), _data[1].ToString("X2"), _data[2].ToString("X2")));
                        }
                            #endif

                        // analiza danych
                        byte type = (byte)((_data[0] >> 4) & 0x0f);
                        _data[0] &= 0x0f;
                        _state    = State.Header;
                        OnReceivedReport(_devices[_id], type, _dataIndex, _data);
                    }
                    break;
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Metoda sprawdza czy na wskazanym intefejsie jest urządzenie o wskazanym id
        /// </summary>
        /// <param name="interf"></param>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public bool ExistsDevice(RS232Configuration interf, byte deviceId)
        {
            List <Device> devices = new List <Device>();

            devices.AddRange(LEDDevices);
            devices.AddRange(LEDDisplayDevices);
            devices.AddRange(LCDDevices);
            devices.AddRange(KeysDevices);
            devices.AddRange(StepperDevices);
            devices.AddRange(ServoDevices);

            if (devices.Find(delegate(Device o)
            {
                return(o.Interface == interf && o.DeviceId == deviceId);
            }) != null)
            {
                return(true);
            }

            return(false);
        }
Пример #12
0
        public static Configuration Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }
            Configuration c   = new Configuration();
            XmlDocument   xml = new XmlDocument();

            xml.Load(fileName);
            c._rs232Configuration = RS232Configuration.Load(xml.SelectSingleNode("/configuration/rs232"));
            XmlNodeList nodes = xml.SelectNodes("/configuration/lcds/lcd");

            if (nodes != null && nodes.Count > 0)
            {
                List <LCD> lcds = new List <LCD>();
                foreach (XmlNode node in nodes)
                {
                    lcds.Add(LCD.Load(node));
                }
                c._lcds = lcds.ToArray();
            }
            return(c);
        }
Пример #13
0
        public void Start(HomeSimCockpitSDK.StartStopType startStopType)
        {
            if (_working)
            {
                return;
            }

            Stop(startStopType);

            // pobranie listy interfejsów RS do nasłuchu
            _deviceKeys.Clear();
            Dictionary <RS232Configuration, List <simINDevice> > interf = new Dictionary <RS232Configuration, List <simINDevice> >();

            foreach (Key key in LoadConfiguration().Keys)
            {
                if (!key.IsSubscribed)
                {
                    continue;
                }
                RS232Configuration interfac = key.KeysDevice.Interface;
                if (!interf.ContainsKey(interfac))
                {
                    interf.Add(interfac, new List <simINDevice>());
                }
                if (!interf[interfac].Contains(key.KeysDevice))
                {
                    interf[interfac].Add(key.KeysDevice);
                }

                key.Module = this;
                key.Reset();

                if (!_deviceKeys.ContainsKey(key.KeysDevice))
                {
                    _deviceKeys.Add(key.KeysDevice, new List <Key>());
                }
                _deviceKeys[key.KeysDevice].Add(key);
            }

            if (_deviceKeys.Count == 0)
            {
                return;
            }

            _devices.Clear();

            foreach (KeyValuePair <RS232Configuration, List <simINDevice> > kvp in interf)
            {
                if (kvp.Value.Count > 0)
                {
                    _devices.Add(new simINDevices(LoadConfiguration(), kvp.Key, kvp.Value.ToArray()));
                }
            }

            foreach (KeysDevice keysDevice in LoadConfiguration().KeysDevices)
            {
                List <Encoder> encoders = new List <Encoder>();
                if (LoadConfiguration().Encoders != null)
                {
                    foreach (Encoder enc in LoadConfiguration().Encoders)
                    {
                        if (enc.KeysDevice == keysDevice)
                        {
                            encoders.Add(enc);
                        }
                    }
                }
                keysDevice.Encoders = encoders.ToArray();
            }

            _working = true;

            foreach (simINDevices simin in _devices)
            {
                simin.ReceivedReportEvent += new ReceivedReportDelegate(simin_ReceivedReportEvent);
                simin.Start();
            }
        }
Пример #14
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();
                }
            }
        }
Пример #15
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;
            }
        }
Пример #16
0
 public InterfaceTreeNode(RS232Configuration interf)
 {
     Interface = interf;
     RefreshText();
 }
Пример #17
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;
            }
        }
Пример #18
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);
        }