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; } }
void DataGridView5CellContentClick(object sender, DataGridViewCellEventArgs e) { if (Working && e.RowIndex > -1) { RS232LCD lcd = (RS232LCD)dataGridView5.Rows[e.RowIndex].Tag; if (e.ColumnIndex == 2) { lcd.On(); return; } if (e.ColumnIndex == 3) { lcd.Clear(); return; } if (e.ColumnIndex == 4) { lcd.Off(); return; } } }
public LCDOnOffCommandVariable(RS232LCD lcd) { _lcd = lcd; }
public LCDClearCommandVariable(RS232LCD lcd) { _lcd = lcd; }
private void button1_Click(object sender, EventArgs e) { // sprawdzenie poprawności danych byte deviceId = (byte)numericUpDown1.Value; string id = _lcdDeviceIndex < 0 ? Guid.NewGuid().ToString() : _configuration.LCDDevices[_lcdDeviceIndex].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 (_lcdDeviceIndex == -1 || _configuration.LCDDevices[_lcdDeviceIndex].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 wyświetlaczy 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 wyświetlaczy są unikalne for (int i = 0; i < _configuration.LCDs.Length; i++) { RS232LCD lcd = (RS232LCD)_configuration.LCDs[i]; if (lcd.LCDDevice.Id == id) { continue; } if (ids.FindIndex(delegate(string o) { return(o == lcd.ID); }) > -1) { MessageBox.Show(this, string.Format("Identyfikator '{0}' jest już wykorzystywany.", lcd.ID), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (_lcdDeviceIndex > -1) { LCDDevice dev = _configuration.LCDDevices[_lcdDeviceIndex]; dev.Description = description; dev.DeviceId = deviceId; for (int i = 0; i < dataGridView1.Rows.Count; i++) { byte dindex = 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; byte drow = byte.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString()); byte dcolumn = byte.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString()); // aktualizacja ustawień wyświetlacza lub dodanie nowego RS232LCD lcd3 = Array.Find <RS232LCD>(_configuration.LCDs, delegate(RS232LCD o) { return(o.LCDDevice == dev && o.Index == dindex); }); if (lcd3 != null) { lcd3.ID = did; lcd3.Description = ddescription; lcd3.Rows = drow; lcd3.Columns = dcolumn; } else { RS232LCD lcd4 = new RS232LCD() { Columns = dcolumn, Description = ddescription, ID = did, Index = dindex, LCDDevice = dev, Rows = drow }; List <RS232LCD> lcds2 = new List <RS232LCD>(_configuration.LCDs); lcds2.Add(lcd4); _configuration.LCDs = lcds2.ToArray(); } } // usunięcie wyświetlaczy List <RS232LCD> diodyOld = new List <RS232LCD>(_configuration.LCDs); diodyOld.RemoveAll(delegate(RS232LCD o) { return(o.LCDDevice == dev && o.Index > dataGridView1.Rows.Count); }); _configuration.LCDs = diodyOld.ToArray(); // usunięcie znaków z obszarów List <LCDArea> areas = new List <LCDArea>(); for (int j = 0; j < _configuration.Areas.Length; j++) { List <LCDCharacter> ccc = new List <LCDCharacter>(_configuration.Areas[j].Characters); int rem = ccc.RemoveAll(delegate(LCDCharacter o) { RS232LCD lcd = Array.Find <RS232LCD>(_configuration.LCDs, delegate(RS232LCD oo) { return(oo == o.LCD); }); if (lcd != null) { return(o.Row >= lcd.Rows || o.Column >= lcd.Columns); } return(true); }); if (rem > 0) { LCDReduction = true; } if (ccc.Count > 0) { _configuration.Areas[j].Characters = ccc.ToArray(); areas.Add(_configuration.Areas[j]); } } _configuration.Areas = areas.ToArray(); } else { // dodanie nowego urządzenia i wyświetlaczy LCDDevice dev = new LCDDevice() { Description = description, DeviceId = deviceId, Id = id, Interface = _interf }; List <LCDDevice> devsAll = new List <LCDDevice>(_configuration.LCDDevices); devsAll.Add(dev); _configuration.LCDDevices = devsAll.ToArray(); AddedLCDDevice = dev; for (int i = 0; i < dataGridView1.Rows.Count; i++) { byte dindex = 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; byte drow = (byte)(int)dataGridView1.Rows[i].Cells[3].Value; byte dcolumn = (byte)(int)dataGridView1.Rows[i].Cells[4].Value; RS232LCD lcd4 = new RS232LCD() { Columns = dcolumn, Description = ddescription, ID = did, Index = dindex, LCDDevice = dev, Rows = drow }; List <RS232LCD> lcds2 = new List <RS232LCD>(_configuration.LCDs); lcds2.Add(lcd4); _configuration.LCDs = 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); }