Beispiel #1
0
        public TestDialog(XMLConfiguration configuration, HomeSimCockpitSDK.ILog log, HomeSimCockpitSDK.IModule module)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            _configuration = configuration;

            // pokazanie urządzeń
            foreach (RS232Configuration d in _configuration.Interfaces)
            {
                ListViewItem item = new ListViewItem(d.PortName);
                item.SubItems.Add("");
                item.Tag = d;
                listView1.Items.Add(item);
            }

            // pokazanie wyświetlaczy
            for (int i = 0; i < _configuration.LCDs.Length; i++)
            {
                int r = dataGridView5.Rows.Add(_configuration.LCDs[i].ID, _configuration.LCDs[i].Description, "On", "Clear", "Off");
                dataGridView5.Rows[r].Tag = _configuration.LCDs[i];
            }

            // pokazanie obszarów tekstowych
            for (int i = 0; i < _configuration.Areas.Length; i++)
            {
                int r = dataGridView1.Rows.Add(_configuration.Areas[i].ID, _configuration.Areas[i].Description, "");
                dataGridView1.Rows[r].Tag = _configuration.Areas[i];
            }

            // pokazanie diod LED
            for (int i = 0; i < _configuration.LEDs.Length; i++)
            {
                int r = dataGridView2.Rows.Add(_configuration.LEDs[i].ID, _configuration.LEDs[i].Description, false);
                dataGridView2.Rows[r].Tag = _configuration.LEDs[i];
            }

            // pokazanie grup diod LED
            for (int i = 0; i < _configuration.LEDGroups.Length; i++)
            {
                int r = dataGridView2.Rows.Add(_configuration.LEDGroups[i].ID, _configuration.LEDGroups[i].Description, false);
                dataGridView2.Rows[r].Tag = _configuration.LEDGroups[i];
            }

            // pokazanie wyświetlaczy LED
            for (int i = 0; i < _configuration.LEDDisplays.Length; i++)
            {
                int r = dataGridView3.Rows.Add(_configuration.LEDDisplays[i].ID, _configuration.LEDDisplays[i].Description, "");
                dataGridView3.Rows[r].Tag = _configuration.LEDDisplays[i];
            }

            // pokazanie grup wyświetlaczy LED
            for (int i = 0; i < _configuration.LEDDisplayGroups.Length; i++)
            {
                int r = dataGridView3.Rows.Add(_configuration.LEDDisplayGroups[i].ID, _configuration.LEDDisplayGroups[i].Description, "");
                dataGridView3.Rows[r].Tag = _configuration.LEDDisplayGroups[i];
            }

            // pokazanie wejść cyfrowych
            for (int i = 0; i < _configuration.Keys.Length; i++)
            {
                int r = inputsGrid.Rows.Add(_configuration.Keys[i].ID, _configuration.Keys[i].Description, "False");
                inputsGrid.Rows[r].Tag = _configuration.Keys[i];
            }

            // pokazanie silników krokowych
            for (int i = 0; i < _configuration.StepperDevices.Length; i++)
            {
                if (_configuration.StepperDevices[i].Motor1 != null)
                {
                    int r = dataGridView4.Rows.Add(_configuration.StepperDevices[i].Motor1.Id, _configuration.StepperDevices[i].Motor1.Description, _configuration.StepperDevices[i].Motor1.CurrentPosition);
                    dataGridView4.Rows[r].Tag = _configuration.StepperDevices[i].Motor1;
                }

                if (_configuration.StepperDevices[i].Motor2 != null)
                {
                    int r = dataGridView4.Rows.Add(_configuration.StepperDevices[i].Motor2.Id, _configuration.StepperDevices[i].Motor2.Description, _configuration.StepperDevices[i].Motor2.CurrentPosition);
                    dataGridView4.Rows[r].Tag = _configuration.StepperDevices[i].Motor2;
                }
            }

            // pokazanie serwomechanizmów
            for (int i = 0; i < _configuration.ServoDevices.Length; i++)
            {
                for (int j = 0; j < _configuration.ServoDevices[i].Servos.Length; j++)
                {
                    int r = gridServos.Rows.Add(_configuration.ServoDevices[i].Servos[j].Id, _configuration.ServoDevices[i].Servos[j].Description, _configuration.ServoDevices[i].Servos[j].Min, _configuration.ServoDevices[i].Servos[j].InitialPosition, _configuration.ServoDevices[i].Servos[j].Max);
                    gridServos.Rows[r].Tag = _configuration.ServoDevices[i].Servos[j];
                }
            }

            timer1.Enabled = dataGridView4.Rows.Count > 0;

            // pokazanie dodatkowych zmiennych
            IOutputVariable [] addins = _configuration.GetAddinsVariable();
            if (addins != null && addins.Length > 0)
            {
                Array.Sort <IOutputVariable>(addins, delegate(IOutputVariable left, IOutputVariable right)
                {
                    int result = left.ID.CompareTo(right.ID);
                    if (result == 0)
                    {
                        result = left.Description.CompareTo(right.Description);
                    }
                    return(result);
                });
            }
            for (int i = 0; i < addins.Length; i++)
            {
                int r = addinsGrid.Rows.Add(addins[i].ID, addins[i].Description, "");
                addinsGrid.Rows[r].Tag = addins[i];
            }

            Working = false;
            _log    = log;
            _module = module;
        }
        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();
        }
Beispiel #3
0
        private void OpenDevices()
        {
            if (Working)
            {
                return;
            }

            button1.Enabled = false;

            // wyczyszczenie gridów
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                dataGridView1.Rows[i].Cells[2].Value = "";
            }

            Working = true;

            // 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);
            }

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

            // dodatkowe zmienne
            IOutputVariable [] addins = _configuration.GetAddinsVariable();
            if (addins != null && addins.Length > 0)
            {
                variables.AddRange(addins);
            }

            List <RS232Configuration> interfaces   = new List <RS232Configuration>();
            List <Device>             devices      = new List <Device>();
            List <simINDevices>       simInDevices = new List <simINDevices>();

            foreach (RS232Configuration inte in _configuration.Interfaces)
            {
                inte.Log    = _log;
                inte.Module = _module;
                //inte.Receiver = this;
                interfaces.Add(inte);

                List <simINDevice> simINs = new List <simINDevice>();
                for (int i = 0; i < _configuration.KeysDevices.Length; i++)
                {
                    if (_configuration.KeysDevices[i].Interface == inte)
                    {
                        simINs.Add(_configuration.KeysDevices[i]);
                    }
                }
                if (simINs.Count > 0)
                {
                    simInDevices.Add(new simINDevices(_configuration, inte, simINs.ToArray()));
                }
            }

            _simINDevices = simInDevices.ToArray();

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

            // dodanie wszystkich urządzeń
            foreach (LCDDevice lcdDevice in _configuration.LCDDevices)
            {
                devices.Add(lcdDevice);
            }

            foreach (LEDDevice ledDevice in _configuration.LEDDevices)
            {
                devices.Add(ledDevice);
            }

            foreach (LEDDisplayDevice ledDisplayDevice in _configuration.LEDDisplayDevices)
            {
                devices.Add(ledDisplayDevice);
            }

            foreach (Steppers.StepperDevice stepperDevice in _configuration.StepperDevices)
            {
                devices.Add(stepperDevice);
            }

            foreach (Servos.ServoDevice servoDevice in _configuration.ServoDevices)
            {
                devices.Add(servoDevice);
            }

            // zresetowanie stanu przycisków
            foreach (Key key in _configuration.Keys)
            {
                key.Reset();
            }

            _interfaces = interfaces.ToArray();
            _devices    = devices.ToArray();

            // otwarcie potrzebnych interfejsów
            for (int i = 0; i < _interfaces.Length; i++)
            {
                ListViewItem item = null;
                foreach (ListViewItem it in listView1.Items)
                {
                    if (it.Tag == _interfaces[i])
                    {
                        item = it;
                        break;
                    }
                }
                try
                {
                    item.SubItems[1].Text = "Łączenie...";
                    _interfaces[i].Open();
                    item.SubItems[1].Text = "Połączono...";
                    foreach (simINDevices sim in simInDevices)
                    {
                        if (sim.Interf == _interfaces[i])
                        {
                            sim.ReceivedReportEvent += new ReceivedReportDelegate(sim_ReceivedReportEvent);
                            sim.Start();
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    item.SubItems[1].Text = "Błąd połączenia: " + ex.Message;
                }
            }

            // inicjalizacja urządzeń
            for (int j = 0; j < _devices.Length; j++)
            {
                if (_devices[j] is LEDDisplayDevice)
                {
                    ((LEDDisplayDevice)_devices[j]).Dictionary = _configuration.LEDDisplaysDictionary;
                }
                _devices[j].Initialize();
            }

            // inicjalizacja wyświetlaczy LCD
            for (int i = 0; i < _configuration.LCDs.Length; i++)
            {
                _configuration.LCDs[i].Initialize();
            }

            // inicjalizacja zmiennych
            foreach (IOutputVariable kvp in variables)
            {
                if (kvp is LEDDisplay)
                {
                    ((LEDDisplay)kvp).Dictionary = _configuration.LEDDisplaysDictionary;
                }
                if (kvp is LEDDisplayGroup)
                {
                    ((LEDDisplayGroup)kvp).Dictionary = _configuration.LEDDisplaysDictionary;
                }
                kvp.Initialize();
            }

            button2.Enabled = true;
        }