public AddEditStepperDevice(XMLConfiguration configuration, StepperDevice stepperDevice, RS232Configuration interf) { _configuration = configuration; StepperDevice = stepperDevice; _interf = interf; // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); if (StepperDevice == null) { Text = "Dodaj silniki krokowe"; NumericUpDown1ValueChanged(this, EventArgs.Empty); } else { Text = "Edytuj silniki krokowe"; textBox2.Text = StepperDevice.Description; numericUpDown1.Value = StepperDevice.DeviceId; textBox1.Text = StepperDevice.Motor1.Id; textBox3.Text = StepperDevice.Motor1.Description; numericUpDown2.Value = StepperDevice.Motor1.StepsFor360; numericUpDown3.Value = StepperDevice.Motor1.MinStepInterval; checkBox1.Checked = StepperDevice.Motor1.HasZeroSensor; checkBox2.Checked = StepperDevice.Motor1.InvertZeroSensor; checkBox3.Checked = StepperDevice.Motor1.ReverseDirection; textBox5.Text = StepperDevice.Motor2.Id; textBox4.Text = StepperDevice.Motor2.Description; numericUpDown5.Value = StepperDevice.Motor2.StepsFor360; numericUpDown4.Value = StepperDevice.Motor2.MinStepInterval; checkBox6.Checked = StepperDevice.Motor2.HasZeroSensor; checkBox5.Checked = StepperDevice.Motor2.InvertZeroSensor; checkBox4.Checked = StepperDevice.Motor2.ReverseDirection; } }
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(); } } }
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; } }
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; } }
void button1_Click(object sender, EventArgs e) { // sprawdzenie ID urządzenia byte deviceId = (byte)numericUpDown1.Value; if (StepperDevice == null || StepperDevice.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; } } string id = StepperDevice == null?Guid.NewGuid().ToString() : StepperDevice.Id; string description = textBox2.Text.Trim(); // sprawdzenie ID string motor1Id = textBox1.Text.Trim(); if (motor1Id.Length == 0) { MessageBox.Show(this, "Nie podano identyfikatora silnika 1.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } string motor2Id = textBox5.Text.Trim(); if (motor2Id.Length == 0) { MessageBox.Show(this, "Nie podano identyfikatora silnika 2.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox5.Focus(); return; } // sprawdzenie unikalności identyfikatorów if (StepperDevice == null || StepperDevice.Motor1.Id != motor1Id) { bool jest = false; foreach (StepperDevice sd in _configuration.StepperDevices) { if (sd.Motor1.Id == motor1Id) { jest = true; break; } if (sd.Motor2.Id == motor2Id) { jest = true; break; } } if (jest) { MessageBox.Show(this, "Identyfikator silnika 1 nie jest unikalny.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox1.Focus(); return; } } if (StepperDevice == null || StepperDevice.Motor2.Id != motor2Id) { bool jest = false; foreach (StepperDevice sd in _configuration.StepperDevices) { if (sd.Motor1.Id == motor2Id) { jest = true; break; } if (sd.Motor2.Id == motor2Id) { jest = true; break; } } if (jest) { MessageBox.Show(this, "Identyfikator silnika 2 nie jest unikalny.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox5.Focus(); return; } } // opisy string motor1Description = textBox3.Text; string motor2Description = textBox4.Text; if (StepperDevice == null) { StepperDevice = new SimpleStepperDevice(); StepperDevice.Motor1 = new StepperMotor(); StepperDevice.Motor2 = new StepperMotor(); List <StepperDevice> sds = new List <StepperDevice>(_configuration.StepperDevices); sds.Add(StepperDevice); _configuration.StepperDevices = sds.ToArray(); } StepperDevice.Description = description; StepperDevice.DeviceId = deviceId; StepperDevice.Id = id; StepperDevice.Interface = _interf; StepperDevice.Motor1.Description = motor1Description; StepperDevice.Motor1.Device = StepperDevice; StepperDevice.Motor1.HasZeroSensor = checkBox1.Checked; StepperDevice.Motor1.Id = motor1Id; StepperDevice.Motor1.InvertZeroSensor = checkBox2.Checked; StepperDevice.Motor1.KeepTourque = false; StepperDevice.Motor1.MinStepInterval = (byte)numericUpDown3.Value; StepperDevice.Motor1.MotorIndex = 0; StepperDevice.Motor1.ReverseDirection = checkBox3.Checked; StepperDevice.Motor1.StepsFor360 = (int)numericUpDown2.Value; StepperDevice.Motor2.Description = motor2Description; StepperDevice.Motor2.Device = StepperDevice; StepperDevice.Motor2.HasZeroSensor = checkBox6.Checked; StepperDevice.Motor2.Id = motor2Id; StepperDevice.Motor2.InvertZeroSensor = checkBox5.Checked; StepperDevice.Motor2.KeepTourque = false; StepperDevice.Motor2.MinStepInterval = (byte)numericUpDown4.Value; StepperDevice.Motor2.MotorIndex = 1; StepperDevice.Motor2.ReverseDirection = checkBox4.Checked; StepperDevice.Motor2.StepsFor360 = (int)numericUpDown5.Value; DialogResult = DialogResult.OK; Close(); }