private void Form1_Load(object sender, System.EventArgs e) { // Prompt user for connection settings int port = GsmCommMain.DefaultPortNumber; int baudRate = 9600; // We Set 9600 as our Default Baud Rate int timeout = GsmCommMain.DefaultTimeout; frmConnection dlg = new frmConnection(); dlg.StartPosition = FormStartPosition.CenterScreen; dlg.SetData(port, baudRate, timeout); if (dlg.ShowDialog(this) == DialogResult.OK) { dlg.GetData(out port, out baudRate, out timeout); CommSetting.Comm_Port = port; CommSetting.Comm_BaudRate = baudRate; CommSetting.Comm_TimeOut = timeout; } else { Close(); return; } Cursor.Current = Cursors.WaitCursor; CommSetting.comm = new GsmCommMain(port, baudRate, timeout); Cursor.Current = Cursors.Default; CommSetting.comm.PhoneConnected += new EventHandler(comm_PhoneConnected); CommSetting.comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived); bool retry; do { retry = false; try { Cursor.Current = Cursors.WaitCursor; CommSetting.comm.Open(); Cursor.Current = Cursors.Default; } catch (Exception) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "Unable to open the port.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { retry = true; } else { Close(); return; } } }while(retry); }
private void Form1_Load(object sender, System.EventArgs e) { // Prompt user for connection settings int port = GsmCommMain.DefaultPortNumber; int baudRate = 9600; // We Set 9600 as our Default Baud Rate int timeout = GsmCommMain.DefaultTimeout; frmConnection dlg = new frmConnection(); dlg.StartPosition = FormStartPosition.CenterScreen; dlg.SetData(port, baudRate, timeout); if (dlg.ShowDialog(this) == DialogResult.OK) { dlg.GetData(out port, out baudRate, out timeout); CommSetting.Comm_Port=port; CommSetting.Comm_BaudRate=baudRate; CommSetting.Comm_TimeOut=timeout; } else { Close(); return; } Cursor.Current = Cursors.WaitCursor; CommSetting.comm = new GsmCommMain(port, baudRate, timeout); Cursor.Current = Cursors.Default; CommSetting.comm.PhoneConnected += new EventHandler(comm_PhoneConnected); CommSetting.comm.MessageReceived+=new MessageReceivedEventHandler(comm_MessageReceived); bool retry; do { retry = false; try { Cursor.Current = Cursors.WaitCursor; CommSetting.comm.Open(); Cursor.Current = Cursors.Default; } catch(Exception) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "Unable to open the port.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) retry = true; else { Close(); return; } } } while(retry); }