Exemplo n.º 1
0
        private void LoadVariables()
        {
            // odczytanie zmiennych
            List <IOutputVariable> variables = new List <IOutputVariable>();

            // dodanie zmiennych do sterowania wyświetlaczami
            foreach (RS232LCD lcd in _configuration.LCDs)
            {
                variables.Add(new LCDOnOffCommandVariable(lcd));
                variables.Add(new LCDClearCommandVariable(lcd));
            }

            // dodanie zmiennych do obszarów na LCD
            foreach (LCDArea lcdArea in _configuration.Areas)
            {
                variables.Add(new RS232LCDArea(lcdArea));
            }

            // dodanie zmiennych do sterowania diodami
            foreach (LED led in _configuration.LEDs)
            {
                variables.Add(led);
            }

            // dodanie zmiennych do obszarów diód
            foreach (LEDGroup ledGroup in _configuration.LEDGroups)
            {
                variables.Add(ledGroup);
            }

            // dodanie zmiennych do sterowania wyświetlaczami 7-segmentowymi
            foreach (LEDDisplay ledDisplay in _configuration.LEDDisplays)
            {
                variables.Add(ledDisplay);
                LEDDisplay ledDisplayInt = new LEDDisplay()
                {
                    Description      = string.Format("{0} Zapis bitowy.", ledDisplay.Description),
                    Dictionary       = ledDisplay.Dictionary,
                    ID               = string.Format("{0}_int", ledDisplay.ID),
                    Index            = ledDisplay.Index,
                    LEDDisplayDevice = ledDisplay.LEDDisplayDevice,
                    Type             = HomeSimCockpitSDK.VariableType.Int
                };
                variables.Add(ledDisplayInt);
            }

            // dodanie zmiennych do obszarów wyświetlaczy 7-segmentowych
            foreach (LEDDisplayGroup ledDisplayGroup in _configuration.LEDDisplayGroups)
            {
                variables.Add(ledDisplayGroup);
            }

            // dodanie zmiennych do regulacji jasności diod i wyświetlaczy
            IOutputVariable [] addins = _configuration.GetAddinsVariable();
            if (addins != null && addins.Length > 0)
            {
                variables.AddRange(addins);
            }

            _outputVariables = variables.ToArray();
        }
Exemplo n.º 2
0
 public LEDDisplayInGroup(LEDDisplay ledDisplay, byte order)
 {
     LEDDisplay = ledDisplay;
     Order      = order;
 }
        private void button1_Click(object sender, EventArgs e)
        {
            // sprawdzenie poprawności danych
            byte deviceId = (byte)numericUpDown1.Value;
            //byte ledId = (byte)numericUpDown2.Value;
            string id          = _ledDisplayDeviceIndex < 0 ? Guid.NewGuid().ToString() : _configuration.LEDDisplayDevices[_ledDisplayDeviceIndex].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 (_ledDisplayDeviceIndex == -1 || _configuration.LEDDisplayDevices[_ledDisplayDeviceIndex].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 wyświetlacza '{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.LEDDisplays.Length; i++)
            {
                LEDDisplay led = (LEDDisplay)_configuration.LEDDisplays[i];
                if (led.LEDDisplayDevice.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 (_ledDisplayDeviceIndex > -1)
            {
                LEDDisplayDevice dev = _configuration.LEDDisplayDevices[_ledDisplayDeviceIndex];
                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
                    LEDDisplay lcd3 = Array.Find <LEDDisplay>(_configuration.LEDDisplays, delegate(LEDDisplay o)
                    {
                        return(o.LEDDisplayDevice == dev && o.Index == dindex);
                    });

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

                // usunięcie znaków z obszarów
                List <LEDDisplayGroup> areas = new List <LEDDisplayGroup>();
                for (int j = 0; j < _configuration.LEDDisplayGroups.Length; j++)
                {
                    List <LEDDisplay> ccc = new List <LEDDisplay>(_configuration.LEDDisplayGroups[j].LEDDisplays);
                    ccc.RemoveAll(delegate(LEDDisplay o)
                    {
                        return(o.LEDDisplayDevice == dev && o.Index >= dataGridView1.Rows.Count);
                    });
                    if (ccc.Count > 0)
                    {
                        _configuration.LEDDisplayGroups[j].LEDDisplays = ccc.ToArray();
                        areas.Add(_configuration.LEDDisplayGroups[j]);
                    }
                }
                _configuration.LEDDisplayGroups = areas.ToArray();

                // usunięcie diod
                List <LEDDisplay> diodyOld = new List <LEDDisplay>(_configuration.LEDDisplays);
                diodyOld.RemoveAll(delegate(LEDDisplay o)
                {
                    return(o.LEDDisplayDevice == dev && o.Index >= dataGridView1.Rows.Count);
                });
                _configuration.LEDDisplays = diodyOld.ToArray();
            }
            else
            {
                // dodanie nowego urządzenia i wyświetlaczy
                LEDDisplayDevice dev = new LEDDisplayDevice()
                {
                    Description = description,
                    DeviceId    = deviceId,
                    Id          = id,
                    Interface   = _interf
                };
                List <LEDDisplayDevice> devsAll = new List <LEDDisplayDevice>(_configuration.LEDDisplayDevices);
                devsAll.Add(dev);
                _configuration.LEDDisplayDevices = devsAll.ToArray();
                AddedLEDDisplayDevice            = 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;

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

            DialogResult = DialogResult.OK;
            Close();
        }
        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);
        }