private void btnTesKoneksi_Click(object sender, EventArgs e) { var port = "COM1"; // port yang digunakan menyesuaikan var baudRate = 9600; var timeout = 150; comm = new GsmCommMain(port, baudRate, timeout); comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived); try { comm.Open(); while (!comm.IsConnected()) { var msgResult = MessageBox.Show(this, "No phone connected.", "Connection setup", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation); if (msgResult == DialogResult.Cancel) { comm.Close(); return; } else { comm.Close(); comm.Open(); } } } catch (Exception ex) { MessageBox.Show(this, "Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// wysyłanie wiadomości; otwarcie połaczenia-->wysłanie-->zamknięcie /// </summary> public void send_message() { string port = ""; for (int i = 3; i < cb_port_name.Text.Length; i++) { port = port + cb_port_name.Text[i]; } int baudRate = 9600; int timeout = 300; GsmCommMain comm = new GsmCommMain(Convert.ToInt16(port), baudRate, timeout); string smsc = string.Empty; Cursor.Current = Cursors.WaitCursor; try { SmsSubmitPdu pdu; pdu = new SmsSubmitPdu(tb_text_message.Text, tb_phone_number.Text, smsc); comm.Open(); comm.SendMessage(pdu); comm.Close(); Output("Message sent to " + tb_phone_number.Text); Output(""); tb_text_message.Clear(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } Cursor.Current = Cursors.Default; }
private void Form1_Load(object sender, EventArgs e) { for (byte i = 0; i < 50; i++) { comm = new GsmCommMain((i + 1), 9600, 300); try { comm.Open(); if (comm.IsConnected() == true) { comboBox1.Items.Add((i+1)); } comm.Close(); } catch (Exception) { } } if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } else { MessageBox.Show("Tidak Ada port yang terbuka !!!\n "+ "Cek kembali bluetooth Anda !","Warning !!",MessageBoxButtons.OK,MessageBoxIcon.Warning); } }
public Sms(int port) { int port1 = GsmCommMain.DefaultPortNumber; int baudRate = GsmCommMain.DefaultBaudRate; int timeout = GsmCommMain.DefaultTimeout; comm = new GsmCommMain(port, baudRate, timeout); Cursor.Current = Cursors.Default; comm.PhoneConnected += new EventHandler(comm_PhoneConnected); comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected); bool retry; retry = false; try { comm.Open(); } catch(Exception) { if (MessageBox.Show("Unable to open the port.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) retry = true; else { return; } } }
protected override void InitRoutine() { string port = GetConfigString("Port"); int baud = GetConfigInteger("Baud"); _messagesPerTimerTick = GetConfigInteger("MessagesPerTick"); NormalizeNumbers = true; _resolveNumbers = true; _gsm = new GsmCommMain(port, baud); Log.Add(LogLevel.Debug, "SMS", String.Format("Initialising on port {0}:{1}baud", port, baud)); }
public bool check() { GsmCommMain comm = new GsmCommMain(newPort, 19200, 300); // try the connection at given COM port number try { comm.Open(); comm.Close(); return true; } // if the connection is unsuccesful exception is thrown catch (Exception) { return false; } }
/// <summary> /// Initializes a new instance of the <see cref="T:GsmComm.Server.SmsSender" /> class. /// </summary> /// <param name="portName">The COM port to connect to.</param> /// <param name="baudRate">The baud rate to use.</param> /// <param name="timeout">The communictaion timeout.</param> public SmsSender(string portName, int baudRate, int timeout) { this.disposed = false; this.comm = new GsmCommMain(portName, baudRate, timeout); this.ConnectEvents(); try { this.comm.Open(); } catch (Exception exception) { this.DisconnectEvents(); this.comm = null; throw; } }
public void connect() { string cmbCOM = "COM" + comms.Text; comm = new GsmCommMain(cmbCOM, 9600, 150); try { if (comm.IsConnected()) { info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.GetCurrentOperator(); info.Content = info.Content + Environment.NewLine + comm.GetSignalQuality(); info.Content = info.Content + Environment.NewLine + comm.GetSmscAddress(); info.Content = info.Content + Environment.NewLine + comm.GetSubscriberNumbers(); save.Visibility = Visibility.Visible; Console.WriteLine("comm is already open"); } else { Console.WriteLine("comm is not open"); comm.Open(); info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); save.Visibility = Visibility.Visible; } } catch (Exception r) { MessageBox.Show(r.Message); } }
public void SendSMS(string port,string nomer,string message) { try { GsmCommMain comm; SmsSubmitPdu pdu; comm = new GsmCommMain(Convert.ToInt32(port), 115200); comm.Open(); pdu = new SmsSubmitPdu(message, nomer, ""); comm.SendMessage(pdu); comm.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } }
private void btnDialogOk_Click(object sender, RoutedEventArgs e) { if (cmbCOM.Text == "") { System.Windows.MessageBox.Show("Invalid Port Name"); return; } comm = new GsmCommMain(cmbCOM.Text , 9600, 150); try { comm.Open(); System.Windows.MessageBox.Show("Modem Connected Sucessfully"); } catch (Exception) { System.Windows.MessageBox.Show("no modem connected"); } }
private void loadSettings_Load(object sender, EventArgs e) { comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); if (!comm.IsOpen()) { comm.Open(); } try { Phone_Name.Text = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); Phone_Model.Text = comm.IdentifyDevice().Model.ToUpper().ToString(); Revision_Num.Text = comm.IdentifyDevice().Revision.ToUpper().ToString(); Serial_Num.Text = comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); } catch (Exception e50) { MessageBox.Show("Error Retriving COM Port Phone Information"+e50.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool send_sms() { GsmCommMain comm = new GsmCommMain(newPort, 19200, 300); // sent the sms try { comm.Open(); // this pdu object stores the message and phone number SmsSubmitPdu pdu; string data = DateTime.Now.ToString(); pdu = new SmsSubmitPdu("Intrusion Occured At: "+data, phone_number); // the message is sent comm.SendMessage(pdu); comm.Close(); return true; } catch (Exception) { return false; } }
private void vistaButton1_Click(object sender, EventArgs e) { try { comm = new GsmCommMain(int.Parse(comboBox1.Text), 9600, 300); comm.Open(); if (comm.IsConnected() == true) { MessageBox.Show("Koneksi Suksess !!", "Information !!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Tidak Ada port yang terbuka !!!\n " + "Cek kembali bluetooth Anda !", "Warning !!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } comm.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public SMSDevice() { gsmDevice = new GsmComm.GsmCommunication.GsmCommMain(); gsmDevice.MessageReceived += GsmDevice_MessageReceived; }
private void test_phone_connection_button_Click(object sender, EventArgs e) { spacelocklinqDataContext dat = new spacelocklinqDataContext(); var match = (from d in dat.GetTable<setting>() where d.user == "admin" select d).SingleOrDefault(); try { match.Port_Number = int.Parse(com_port_box.Text.TrimEnd()); } catch (Exception) { match.Port_Number = 10; } dat.SubmitChanges(); GsmCommMain comm = new GsmCommMain(match.Port_Number, 19200, 300); try { comm.Open(); comm.Close(); MessageBox.Show("Phone Connection Successful"); } catch (Exception) { MessageBox.Show("Phone Connection Unsuccessful"); } }
// adds an sms to the log public void AddSMS(string SMS) { _smsLog.Add(SMS); try { GsmCommMain comm = new GsmCommMain("COM4", 19200, 300); // Send an SMS message SmsSubmitPdu pdu; // The straightforward version pdu = new SmsSubmitPdu(SMS, "+65" + _mobileNum, "+6596197777"); comm.Open(); comm.SendMessage(pdu); comm.Close(); } catch (Exception e) { return; } }
public static bool connected(string network, string comms) { netName = network; comm = new GsmCommMain(comms, 9600, 150); try { if (comm.IsConnected()) { Console.WriteLine(netName + "comm is already open"); okay = true; if (!comm2.IsConnected()) { comm2 = new GsmCommMain(comms, 9600, 150); comm2.Open(); CommNetwork _cm = new CommNetwork() { Names = netName, Comms = comm2 }; primes.Add(_cm); } else { Console.WriteLine(netName + "all comms are open comm is already open"); } } else { comm.Open(); CommNetwork _cm = new CommNetwork() { Names = netName, Comms = comm }; primes.Add(_cm); Console.WriteLine(netName + "comm has connected"); okay = true; } } catch (Exception r) { Console.WriteLine("comm has failed"); okay = false; } return okay; }
private int? findGSMCommPort() { String[] portNames = System.IO.Ports.SerialPort.GetPortNames(); int? portNumber = null; foreach (string portName in portNames) { String[] port = portName.Split(new string[] { "COM" }, StringSplitOptions.None); GsmCommMain comm = new GsmCommMain(Int32.Parse(port[1]), gsmBaudRate/*baudRate*/, gsmTimeOut/*timeout*/); try { comm.Open(); if (comm.IsConnected()) { AddressData addrData = comm.GetSmscAddress(); portNumber = Convert.ToInt32(port[1]); } comm.Close(); if (portNumber != null) break; } catch (Exception e) { if( comm.IsOpen()) comm.Close(); } } return portNumber; }
public bool initialize() { try { gsmComm = new GSM_SMS(); logger("Finding GSM Communication Port..."); gsmComm.initialize(); gsmComm.setMessageMode(GSM_SMS.MessageMode.TEXT); // int? commPort = findGSMCommPort(); if( gsmComm.ComPort == String.Empty) //if (commPort == null) { logger("None Found"); return false; } //logger("Found on port number :" + commPort.Value.ToString()); logger("Found on port :" + gsmComm.ComPort); //logger("Setting GSM Port ...."); // comm = new GsmCommMain(commPort.Value, gsmBaudRate, gsmTimeOut); // comm.Open(); // comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived); //// comm.EnableMessageNotifications(); // comm.MessageSendComplete += new GsmCommMain.MessageEventHandler(comm_MessageSendComplete); // smscAddress = comm.GetSmscAddress().Address; //logger("Successful"); return true; } catch (Exception e) { comm = null; logger(" Failure ...."); return false; } }
//public void OnNext(Events.Message value) //{ // if (value.majorType == (int)MajorType.Event) // { // try // { // if (isActive) // { // string message = value.ToSMSText(); // if (message.Length > 70) // message = message.Substring(0, 70); // if (comm == null || !comm.IsOpen()) // Connect(portName, baudRate, timeout); // SendSMS(true, message, receiversNo); // } // } // catch (Exception ex) // { // Log("ERROR","Exception in sending SMS: " + ex.Message); // //HITLog.Write("SMSPort@HITCEPLib", "Exception in sending SMS: " + ex.Message // // , EventLogEntryType.Error, false); // } // } //} public void Connect(string _portName, int _baudRate, int _timeout) { try { if (isActive) { string portName = _portName; int baudRate = _baudRate; int timeout = _timeout; comm = new GsmCommMain(portName, baudRate, timeout); comm.Open(); } } catch (Exception e) { Log("ERROR", "Exception in Connecting to GSM Modem: " + e.Message); } }
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e) { DataGridViewCellStyle style = new DataGridViewCellStyle(); style.Font = new Font(dataGridView3.Font, FontStyle.Bold); style.BackColor = Color.Green; style.ForeColor = Color.White; int i = dataGridView3.CurrentRow.Index; try { Comm_Port = Convert.ToInt16(dataGridView3.Rows[i].Cells[0].Value.ToString().Substring(3)); Comm_BaudRate = Convert.ToInt32(dataGridView3.Rows[i].Cells[2].Value.ToString()); Comm_TimeOut = Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString()); } catch (Exception E1) { MessageBox.Show("Error Converting COM Port Settings Values", "Check COM Port Values", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); try { comm.Open(); if (comm.IsConnected()) { pictureBox3.Image = imageList1.Images[1]; MessageBox.Show("Connected Successfully To GSM Phone / Modem...!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView3.Rows[i].Cells[4].Value = "Connected"; dataGridView3.Rows[i].DefaultCellStyle = style; dataGridView3.ClearSelection(); Single_SMS.Enabled = true; } try { Phone_Name.Text = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); Phone_Model.Text = comm.IdentifyDevice().Model.ToUpper().ToString(); Revision_Num.Text = comm.IdentifyDevice().Revision.ToUpper().ToString(); Serial_Num.Text = comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); } catch (Exception e50) { MessageBox.Show("Error Retriving COM Port Phone Information"+e50, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception E2) { MessageBox.Show("Error While Connecting To GSM Phone / Modem"+E2, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridView3.ClearSelection(); } }
private void timer1_Tick(object sender, EventArgs e) { PersianDateFormatter pdf = new PersianDateFormatter(); int date = pdf.convert(toolStripTextBox1.Text); OtherRepository otherRepository = new OtherRepository(); radGridView1.DataSource = otherRepository.getCustomerJoinContract(date); ///////////////////////////////////////////////// DefaultSettingsRepository dRepo = new DefaultSettingsRepository(); DefaultSetting gsmPort = dRepo.GetSetting("gsm_port"); DefaultSetting lastSend = dRepo.GetSetting("last_send"); if (lastSend == null) { DefaultSetting ls = new DefaultSetting(); ls.Value = "13000101"; ls.Name = "last_send"; dRepo.AddSettings(ls); } else { int lastSendInt = Convert.ToInt32(lastSend.Value); int todayInt = pdf.getDateInteger(DateTime.Now); int x = 0; if (todayInt <= lastSendInt) { return; } } if (gsmPort != null) { if (gsmPort.Value != "NULL") { try { GsmCommMain comm = new GsmCommMain(gsmPort.Value, 9600, 150); comm.Open(); byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha16Bit; DefaultSetting sendTime = dRepo.GetSetting("send_message_time"); DefaultSetting days = dRepo.GetSetting("days_before_send"); DefaultSetting text = dRepo.GetSetting("message_text"); int daysInteger = Convert.ToInt32(days.Value); TimeSpan ts = TimeSpan.Parse(sendTime.Value); TimeSpan nts = DateTime.Now.TimeOfDay; TimeSpan fivemin = TimeSpan.FromMinutes(5); if (nts.CompareTo(ts) >= 0) { if (nts.Subtract(ts).CompareTo(fivemin) > 0) { return; } } else { if (ts.Subtract(nts).CompareTo(fivemin) > 0) { return; } } DateTime dt = DateTime.Now; dt = dt.AddDays(daysInteger); string dateString = pdf.getDateString(dt); object customers = otherRepository.getCustomerJoinContract(dt); IEnumerable<object> collection = (IEnumerable<object>)customers; foreach (object item in collection) { var nameOfProperty = "PhoneNumber"; var propertyInfo = item.GetType().GetProperty(nameOfProperty); var phoneNumber = propertyInfo.GetValue(item, null); var nameOfProperty2 = "Time"; var propertyInfo2 = item.GetType().GetProperty(nameOfProperty2); var time = propertyInfo2.GetValue(item, null); string timeString = time.ToString(); timeString = timeString.Remove(timeString.Length-3); string smsText = text.Value + Environment.NewLine + dateString + Environment.NewLine + timeString; SmsSubmitPdu pdu = new SmsSubmitPdu(smsText, phoneNumber.ToString(), dcs); comm.SendMessage(pdu); } DefaultSettingsRepository dRepo2 = new DefaultSettingsRepository(); DefaultSetting lsls = dRepo2.GetSetting("last_send"); lsls.Value = pdf.getDateInteger(DateTime.Now).ToString(); dRepo2.UpdateSetting(lsls); } catch (Exception ex) { } } } }
public void sendSMS(string text, string MobileNumber) { GsmCommMain comm = new GsmCommMain("COM4", 19200, 300); // Send an SMS message SmsSubmitPdu pdu; // The straightforward version pdu = new SmsSubmitPdu(text, "+65" + MobileNumber, "+6596197777"); comm.Open(); comm.SendMessage(pdu); comm.Close(); }
private void btnTest_Click(object sender, System.EventArgs e) { if (!EnterNewSettings()) return; Cursor.Current = Cursors.WaitCursor; GsmCommMain comm = new GsmCommMain(port, baudRate, timeout); try { comm.Open(); while (!comm.IsConnected()) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "No phone connected.", "Connection setup", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { comm.Close(); return; } Cursor.Current = Cursors.WaitCursor; } comm.Close(); } catch(Exception ex) { MessageBox.Show(this, "Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } MessageBox.Show(this, "Successfully connected to the phone.", "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// This method constatly checks with the phone for any incomming message /// If a desired message is received from a particulaar number /// The application is either started or terminated /// </summary> private void read_sms() { SmsSubmitPdu pdu; string phone_number = ""; int newPort = 10; spacelocklinqDataContext data = new spacelocklinqDataContext(); var query = (from c in data.GetTable<setting>() where c.user == "admin" select c).SingleOrDefault(); try { phone_number = query.Phone_Number.TrimEnd(); newPort = query.Port_Number; } catch (Exception) { } send = "null"; GsmCommMain comm = new GsmCommMain(newPort, 19200, 300); string storage = string.Empty; while (true) { try { comm.Open(); } catch (Exception) { break; } storage = PhoneStorageType.Phone; SmsDeliverPdu del; DecodedShortMessage[] messages; try { messages = comm.ReadMessages(PhoneMessageStatus.All, storage); } catch (Exception) { break; } foreach (DecodedShortMessage message in messages) { try { del = (SmsDeliverPdu)(message.Data); } catch (Exception) { continue; } if (del.UserDataText == "STOP" && del.OriginatingAddress == phone_number) { if (stop_check == false) { try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } pdu = new SmsSubmitPdu("Space Lock has been deactivated", phone_number); comm.SendMessage(pdu); stop_check = true; send = "stop"; //MessageBox.Show("STOP"); --ideamonk commented try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } } } if (del.UserDataText == "STOP" && del.OriginatingAddress == phone_number) { if (stop_check == true) { pdu = new SmsSubmitPdu("Wrong message! Space Lock has ALREADY been deactivated", phone_number); comm.SendMessage(pdu); try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } } } if (del.UserDataText == "START" && del.OriginatingAddress == phone_number) { if (stop_check == true) { try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } pdu = new SmsSubmitPdu("Space Lock has started", phone_number); // the message is sent comm.SendMessage(pdu); stop_check = false; send = "start"; try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } } } if (del.UserDataText == "START" && del.OriginatingAddress == phone_number) { if (stop_check == false) { pdu = new SmsSubmitPdu("Space Lock is already running", phone_number); // the message is sent comm.SendMessage(pdu); try { comm.DeleteMessage(message.Index, storage); } catch (Exception) { continue; } } } } break; } try { comm.Close(); } catch (Exception) { } }
public static bool SendUpdate(DBObject parent, string id, string message, string number, string network, string cb) { _network = new Network(null); comm = new GsmCommMain(cb, 9600, 150); try { SmsSubmitPdu pdu; byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault; pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs); int times = 1; for (int i = 0; i < times; i++) { if (comm.IsConnected()) { Console.WriteLine("comm is already open"); Console.WriteLine("modem connected:" + network + "to:" + comm); _network.UpdateStatus(network, "connected"); } else { comm.Open(); _network.UpdateStatus(network, "connected"); } comm.SendMessage(pdu); _message = new Message(parent); _message.Update(id, "T"); sent = true; } sent = true; } catch (Exception r) { sent = false; _network.UpdateStatus(network, "disconnected"); Console.WriteLine("comm is already open"); } return sent; }
public static string connect() { state = "false"; int d = 0; do { d++; cmbCOM = "COM" + d.ToString(); comm = new GsmCommMain(cmbCOM, 9600, 150); Console.WriteLine(cmbCOM); try { if (comm.IsConnected()) { Console.WriteLine("comm is already open"); ports = true; state = "true"; break; } else { Console.WriteLine("comm is not open"); comm.Open(); ports = true; state = "true"; } } catch (Exception) { ports = false; state = "true"; } } while (!comm.IsConnected() && d < 30); Console.WriteLine(cmbCOM); return state; }
private void button1_Click(object sender, EventArgs e) { DataGridViewCellStyle style = new DataGridViewCellStyle(); style.Font = new Font(dataGridView3.Font, FontStyle.Bold); style.BackColor = Color.Green; style.ForeColor = Color.White; int i = dataGridView3.CurrentRow.Index; try { Comm_Port = Convert.ToInt16(listBox1.SelectedItem.ToString().Substring(3)); Comm_BaudRate = Convert.ToInt32(listBox2.SelectedItem.ToString()); Comm_TimeOut = Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString()); //load = new loadSettings(Comm_Port,Comm_BaudRate,Comm_TimeOut); // load.Show(); } catch (Exception E1) { MessageBox.Show("Error Converting COM Port Settings Values"+E1.Message.ToString(), "Check COM Port Values", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); try { if (!comm.IsOpen()) comm.Open(); if (comm.IsConnected()) { MessageBox.Show("Connected Successfully To GSM Phone / Modem...!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView3.Rows[i].Cells[4].Value = "Connected"; dataGridView3.Rows[i].DefaultCellStyle = style; dataGridView3.ClearSelection(); } } catch (Exception E2) { MessageBox.Show("Error While Connecting To GSM Phone / Modem/nError:" + E2.Message.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridView3.ClearSelection(); } //load.Close(); }