private void portNameBox_SelectedIndexChanged(object sender, EventArgs e) { try { port = new System.IO.Ports.SerialPort(portNameBox.SelectedItem as string, 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One); port.NewLine = "\r\n"; listener = new SerialPortListener(port); if (listener.AreHandlersEmpty) { SetListenerProperties(); } //port.Open(); } catch (Exception except) { //MessageBox.Show(except.Message, except.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); listener_ErrorReceived(this, new StringDataReceivedEventArgs(except.Message)); } }
private void CalibrateForm_Load(object sender, EventArgs e) { listener = (this.Owner as GsmConfig).Listener; try { ErrorReceivedHandler = new DeviceDataReceivedEventHandler(listener_ErrorReceived); listener.ErrorReceived += ErrorReceivedHandler; ADCParamsReceivedHandler = new DeviceDataReceivedEventHandler(listener_GetADCParamsReceived); listener.GetADCParamsReceived += ADCParamsReceivedHandler; CurrentADCReceivedHandler = new DeviceDataReceivedEventHandler(listener_GetCurrentADCReceived); listener.GetCurrentADCReceived += CurrentADCReceivedHandler; SetADCParamsOKReceivedHandler = new DeviceDataReceivedEventHandler(listener_SetADCParamsOKReceived); listener.SetADCParamsOKReceived += SetADCParamsOKReceivedHandler; setValue = SetValue; MessageBox.Show("Внимание! Перед калибровкой убедитесь, что все контролируемые точки находятся в закрытом состоянии", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } #pragma warning disable 168 catch (NullReferenceException except) { MessageBox.Show("Сначала выберите порт", "Порт не выбран", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } #pragma warning restore 168 toolTip1.SetToolTip(readCurrADCBtn, "Считать текущие значения зон"); toolTip1.SetToolTip(readZone1Params, "Считать"); toolTip1.SetToolTip(readZone2Params, "Считать"); toolTip1.SetToolTip(readZone3Params, "Считать"); toolTip1.SetToolTip(readZone4Params, "Считать"); toolTip1.SetToolTip(writeZone1Params, "Записать"); toolTip1.SetToolTip(writeZone2Params, "Записать"); toolTip1.SetToolTip(writeZone3Params, "Записать"); toolTip1.SetToolTip(writeZone4Params, "Записать"); }
private void SendCommand(string cmd) { try { if (!port.IsOpen) { port.Open(); } listener.BeginListening(); port.WriteLine("$" + cmd + "*" + SerialPortListener.CalculateCRC(cmd)); } #pragma warning disable 168 catch (NullReferenceException except) { //MessageBox.Show("Сначала выберите порт", "Порт не выбран", MessageBoxButtons.OK, MessageBoxIcon.Error); listener_ErrorReceived(this, new StringDataReceivedEventArgs("Сначала выберите порт")); } #pragma warning restore 168 catch (Exception except) { //MessageBox.Show(except.Message, except.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); listener_ErrorReceived(this, new StringDataReceivedEventArgs(except.Message)); } }