private void button_exit_3_Click(object sender, EventArgs e) { if (groupBox_presets.Enabled) { if (MessageBox.Show( TB.L.Phrase["Form_MacroPack.SessianAlreadyActive"], TB.L.Phrase["Form_MacroPack.Exit"], MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Master.CloseConnection(); Close(); } } }
private void button_mc_Click(object sender, EventArgs e) { if (button_mc.Text == TB.L.Phrase["Form_PrintMaster.Disconnect"]) { combobox_bdrate.Enabled = true; combobox_com.Enabled = true; master?.CloseConnection(); button_mc.Text = TB.L.Phrase["Form_PrintMaster.Connect"]; return; } try { var port = new SerialPort(combobox_com.Text, int.Parse(combobox_bdrate.Text.Remove(0, 2))); port.Open(); var Listener = new PacketListener(new SerialPacketReader(port, 3000), new SerialPacketWriter(port)); master = new DTPMaster(new Sender("Coestar"), Listener); Pens = master.PlotterConfig().Pens; movingControl = master.PlotterMovingControl(); comboBox1.Items.Clear(); comboBox1.Items.AddRange(Pens.Select(p => p.Name).ToArray()); comboBox1.SelectedIndex = 0; //Control.Enabled = true; combobox_bdrate.Enabled = false; combobox_com.Enabled = false; button_mc.Text = TB.L.Phrase["Form_PrintMaster.Disconnect"]; if (master.SecurityManager.IsValidationRequired) { if (new ValidateForm(master).ShowDialog() != DialogResult.OK) { combobox_bdrate.Enabled = true; combobox_com.Enabled = true; master?.CloseConnection(); button_mc.Text = TB.L.Phrase["Form_PrintMaster.Connect"]; } } } catch { MessageBox.Show( string.Format(TB.L.Phrase["Connection.UnableToOpenPort"], combobox_com.Text), TB.L.Phrase["Connection.Error"], MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void MainFormLoad(object sender, EventArgs e) { string DllName = "Lib\\FileBrowserResources.dll"; if (!File.Exists(DllName)) { throw new DllNotFoundException($"Dll {DllName} not found"); } var ie = new IconExtractor(DllName); backImage = ie.GetIcon(0).ToBitmap(); forwardImage = ie.GetIcon(1).ToBitmap(); folderImage = ie.GetIcon(2).ToBitmap(); emptyImage = new Bitmap(5, 5); //folderImage = new Bitmap("Icons\\folder.png"); //backImage = new Bitmap("Icons\\back.png"); //forwardImage = new Bitmap("Icons\\forward.png"); MainForm_SizeChanged(null, null); try { port?.Close(); port = new SerialPort(portName, 115200); Master = new DTPMaster(new SerialPacketReader(port, 4000), new SerialPacketWriter(port)); Master.Device.SyncTyme(); } catch (SecurityException) { if (new ValidateForm(Master).ShowDialog() == DialogResult.Cancel) { Master.CloseConnection(); Close(); return; } } catch (WrongPacketInputException ex) { if (System.Windows.Forms.MessageBox.Show( string.Format("Невозможно получить данные. Произошла ошибка типа WrongPacketInputException (причина {0}. Сообщение: {1}), это может означать что устройство работает не коректно и не грамотно обрабатывает входящие и исходящие пакеты. Попробуйте перезагрузить его и нажать \"Повтор\"", ex.Type.ToString(), ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { MainFormLoad(null, null); } else { Close(); return; } } catch (Exception ex) { if (System.Windows.Forms.MessageBox.Show( string.Format("Произошла ошибка типа {0}.\n{2}\n\nНажмите \"Повтор\" для повторной попытки. Стек вызовов:\n{1}", ex.GetType().FullName, ex.StackTrace, ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { MainFormLoad(null, null); } else { Close(); return; } } try { GetData(); } catch (WrongPacketInputException ex) { if (System.Windows.Forms.MessageBox.Show( string.Format("Невозможно получить данные. Произошла ошибка типа WrongPacketInputException (причина {0}. Сообщение: {1}), это может означать что устройство работает не коректно и не грамотно обрабатывает входящие и исходящие пакеты. Попробуйте перезагрузить его и нажать \"Повтор\"", ex.Type.ToString(), ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { MainFormLoad(null, null); } else { Close(); return; } } catch (Exception ex) { if (System.Windows.Forms.MessageBox.Show( string.Format("Невозможно получить данные.\n{2}\n\nПроизошла ошибка типа {0}, нажмите \"Повтор\" для повторной попытки. Стек вызовов:\n{1}", ex.GetType().FullName, ex.StackTrace, ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { MainFormLoad(null, null); } else { Close(); return; } } }
private void ResetConntection() { master?.CloseConnection(); }
private void button_connect_Click(object sender, EventArgs e) { if (button_connect.Text == TB.L.Phrase["Connection.Disconnect"]) { Master?.CloseConnection(); groupBox_presets.Enabled = false; groupBox_macro.Enabled = false; button_connect.Text = TB.L.Phrase["Connection.Connect"]; comboBox_bd.Enabled = true; comboBox_port.Enabled = true; } else { if (comboBox_bd.Text == "") { MessageBox.Show( TB.L.Phrase["Connection.EnterBDRate"], TB.L.Phrase["Connection.Error"], MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Master?.CloseConnection(); groupBox_presets.Enabled = false; groupBox_macro.Enabled = false; SerialPort port = new SerialPort(comboBox_port.Text, int.Parse(comboBox_bd.Text)); try { port.Open(); } catch { MessageBox.Show( string.Format(TB.L.Phrase["Connection.UnableToOpenPort"], comboBox_port.Text), TB.L.Phrase["Connection.Error"], MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Master = new DTPMaster( new SerialPacketReader(port), new SerialPacketWriter(port)); try { if (!Master.Device.Test()) { MessageBox.Show( TB.L.Phrase["Connection.DeviceNotAnswered"], TB.L.Phrase["Connection.Error"], MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch { MessageBox.Show( TB.L.Phrase["Connection.DeviceNotAnswered"], TB.L.Phrase["Connection.Error"], MessageBoxButtons.OK, MessageBoxIcon.Error); return; } groupBox_presets.Enabled = true; groupBox_macro.Enabled = true; comboBox_bd.Enabled = false; comboBox_port.Enabled = false; button_connect.Text = TB.L.Phrase["Connection.Disconnect"]; ContentMaster = new PlotterContent(Master); tabControl1.Enabled = false; loadingCircle_previewLoad.Visible = true; backgroundWorker1.RunWorkerAsync(); } }