private void btnTest_Click(object sender, System.EventArgs e) { if (!EnterNewSettings()) { return; } Cursor.Current = Cursors.WaitCursor; GsmCommMain comm = new GsmCommMain(portName, 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); }
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); } }
//Méthode pour tester la configuration des ports public void Test_port() { Cursor.Current = Cursors.WaitCursor; comm = new GsmCommMain(port, baudRate, timeout); try { comm.Open(); while (!comm.IsConnected()) { Cursor.Current = Cursors.Default; MessageBox.Show("La connexion au peripherique mobile a echoué\nREESAYER?", "TEST DE CONNEXION"); if (MessageBox.Show("La connexion au peripherique mobile a echoué\nREESAYER?", "TEST DE CONNEXION") != DialogResult.Cancel) { comm.Close(); return; } Cursor.Current = Cursors.WaitCursor; } MessageBox.Show("Successfully connected to the phone.", "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information); comm.Close(); } catch (Exception ex) { MessageBox.Show("Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public void Check_Connection(string port) { if (port.Length < 4) { return; } if (comm.IsOpen()) { comm.Close(); } comm = new GsmCommMain(port, baudrate, timeout); if (!comm.IsConnected()) { try { comm.Open(); connected = true; return; } catch (Exception ex) { connected = false; } } else { connected = true; } }
public List <string> GetConnectedPort() { List <string> ConnectedPorts = new List <string>(); string[] port = System.IO.Ports.SerialPort.GetPortNames(); foreach (string st in port) { comm = new GsmCommMain(st, 19200, 300); try { comm.Open(); if (comm.IsConnected()) { //Console.WriteLine("BhattiConsole: Modem Connected Successfully " + st); ConnectedPorts.Add(st); comm.Close(); } else { // Console.WriteLine("BhattiConsole: Modem noy Connected " + st); comm.Close(); } } catch (Exception ex) { // Console.WriteLine("BhattiConsole: " + ex.Message); } } return(ConnectedPorts); }
//Méthode pour tester la configuration des ports public void Test_port(Label infomodem) { Cursor.Current = Cursors.WaitCursor; comm = new GsmCommMain(port, baudRate, timeout); try { comm.Open(); if (!comm.IsConnected()) { Cursor.Current = Cursors.Default; infomodem.Text = "La connexion au peripherique mobile a echoué."; if (infomodem.Text == "La connexion au peripherique mobile a echoué.") { comm.Close(); return; } Cursor.Current = Cursors.WaitCursor; } else { infomodem.Text = "Successfully connected to the phone."; comm.Close(); } } catch (Exception) { new Error("Branchez un Modem SVP...").ShowDialog(); return; } }
public void LoadReloadListener(string portnumber, int baudrate) { if (gsmComm == null) { gsmComm = new GsmCommMain(portnumber, baudrate, 1000); try { gsmComm.Open(); worker.RunWorkerAsync(); Debug.WriteLine("RUNNING WITH SMS SUPPORT"); } catch (Exception) { Debug.WriteLine("RUNNING WITH NO SMS SUPPORT"); } } else { try { if (gsmComm.IsConnected()) { gsmComm.Close(); } gsmComm = new GsmCommMain(portnumber, baudrate, 1000); gsmComm.Open(); worker.RunWorkerAsync(); Debug.WriteLine("RUNNING WITH SMS SUPPORT"); } catch (Exception) { Debug.WriteLine("RUNNING WITH NO SMS SUPPORT"); } } }
public void SendSMS(string CELL_Number, string SMS_Message) { SmsSubmitPdu pdu1; if (comm.IsConnected() == true) { pdu1 = new SmsSubmitPdu(SMS_Message, CELL_Number, ""); comm.SendMessage(pdu1); comm.Close(); } }
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 bool Connect(int comPort, int baudRate, int timeout) { try { Gsm = new GsmCommMain(comPort, baudRate, timeout); if (!Gsm.IsOpen()) { Gsm.Open(); } return(true); } catch (System.Exception ex) { LogError(ex.Message); if (Gsm.IsConnected() && Gsm.IsOpen()) { Gsm.Close(); } return(false); } }
public static void Close() { if (gsObj.IsOpen()) { gsObj.Close(); } }
private void Comm_PhoneDisconnected(object sender, EventArgs e) { GsmCommMain obj = sender as GsmCommMain; try { message = obj.PortName + " Phone disconected"; AddLog(EventLevel.Warning.ToString(), DateTime.Now, EventSource.AddModem.ToString(), message); Modems.Remove(Modems.Where(x => x.GsmCommMain.PortName == obj.PortName).First()); } catch (Exception ex) { message = obj.PortName + " Comm_PhoneDisconnected() Exception: " + ex.Message; AddLog(EventLevel.Warning.ToString(), DateTime.Now, EventSource.AddModem.ToString(), message); } try { obj.Close(); } catch (Exception ex) { message = obj.PortName + " Comm_PhoneDisconnected() Exception: " + ex.Message; AddLog(EventLevel.Warning.ToString(), DateTime.Now, EventSource.AddModem.ToString(), message); } }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { lock (_commPortLock) { var communications = new GsmCommMain(_communicationsPort, _baudRate, _timeout); communications.Open(); communications.DeleteMessages(DeleteScope.All, _storage); communications.Close(); } while (!_backgroundWorker.CancellationPending) { DecodedShortMessage[] messages = null; lock (_commPortLock) { var communications = new GsmCommMain(_communicationsPort, _baudRate, _timeout); communications.Open(); messages = communications.ReadMessages(PhoneMessageStatus.ReceivedUnread, _storage); communications.Close(); } foreach (var message in messages) { _backgroundWorker.ReportProgress(0, message); } Thread.Sleep(1000); } }
public async Task <bool> SendSMS(string sms, List <string> phones) { try { await Task.FromResult(true); GsmCommMain comm = new GsmCommMain("COM6", 1, 80000); if (!comm.IsOpen()) { comm.Open(); } foreach (var phone in phones) { SmsSubmitPdu[] messagePDU = SmartMessageFactory.CreateConcatTextMessage(sms, true, phone); comm.SendMessages(messagePDU); } comm.Close(); return(true); } catch (Exception ex) { } return(false); }
private void vistaButton2_Click(object sender, EventArgs e) { try { main = new MainForm(); comm = new GsmCommMain(int.Parse(comboBox1.Text), 9600, 300); comm.Open(); if (comm.IsConnected() == true) { MessageBox.Show("Koneksi Suksess !!", "Information !!", MessageBoxButtons.OK, MessageBoxIcon.Information); main.Port = comboBox1.Text; main.Show(); this.Hide(); } else { MessageBox.Show("Tidak Ada port yang terbuka !!!\n " + "Cek kembali bluetooth Anda !", "Warning !!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } comm.Close(); main.Show(); this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void votecountsFrm_FormClosing(object sender, FormClosingEventArgs e) { // Kill SMS server if running DestroySmsServer(); // Clean up comm object if (comm != null) { // Unregister events comm.PhoneConnected -= new EventHandler(comm_PhoneConnected); comm.PhoneDisconnected -= new EventHandler(comm_PhoneDisconnected); if (registerMessageReceived) { comm.MessageReceived -= new MessageReceivedEventHandler(comm_MessageReceived); registerMessageReceived = false; } // Close connection to phone if (comm != null && comm.IsOpen()) { comm.Close(); } comm = null; Environment.Exit(0); } }
public Boolean closePort() { bool close = false; try { comm.Close(); if (!comm.IsOpen()) { try { sendBgWorker.CancelAsync(); } catch (Exception ex) { } close = true; portOpen = false; btn_connect.Text = "Connect"; btn_connect.BackColor = Color.DodgerBlue; btn_refresh.Enabled = true; cbo_port.SelectedIndex = -1; cbo_port.Enabled = true; } } catch (Exception ex) { MessageBox.Show("No port selected \n" + "Message : " + ex.Message); close = false; } return(close); }
private void metroTextButton2_Click(object sender, EventArgs e) { try { thread.Abort(); //port = SimPortsConnection.ClosePort(port); comm.Close(); metroTextButton1.Enabled ^= true; metroTextButton2.Enabled ^= true; metroComboBox1.Enabled ^= true; richTextBox1.Clear(); }catch (Exception ex) { ex.ToString(); } }
public static string sendATSMSCommand(string PortName, string cellNo, string messages, object _sendFailer) { int baudRate = 9600; int timeout = 300; GsmCommMain comm; comm = new GsmCommMain(PortName, baudRate, timeout); try { comm.Open(); } catch (Exception) { //return false; } try { SmsSubmitPdu[] pdus; bool unicode = Library.IsUnicode(messages); try { if (!unicode) { pdus = GsmComm.PduConverter.SmartMessaging.SmartMessageFactory.CreateConcatTextMessage(messages, cellNo); } else { pdus = GsmComm.PduConverter.SmartMessaging.SmartMessageFactory.CreateConcatTextMessage(messages, true, cellNo); } } catch (Exception ex) { return(null); } foreach (SmsSubmitPdu pdu in pdus) { comm.SendMessage(pdu); } return("1"); } catch (Exception ex) { return(ex.ToString()); //return false; } finally { if (comm != null) { comm.Close(); } } }
private static bool _disconnect_from_gsm() { _GsmComm.Close(); if (!_GsmComm.IsOpen()) { return(true); } return(false); }
private void ReciveSMS() { string COMPortNumber = System.Configuration.ConfigurationManager.AppSettings["COMPortNumber"]; GsmCommMain comm = new GsmCommMain(Convert.ToInt32(COMPortNumber), 2400); try { comm.Open(); //string storage = GetMessageStorage(); string storage = PhoneStorageType.Sim; DecodedShortMessage[] messages = comm.ReadMessages(PhoneMessageStatus.ReceivedRead, storage); int count = messages.Length; //MessageBox.Show(count.ToString()); int i = 0; while (count != 0) { GsmComm.PduConverter.SmsPdu pdu = messages[i].Data; //GsmComm.PduConverter.SmsSubmitPdu data = (GsmComm.PduConverter.SmsSubmitPdu)pdu; string messageSMS = pdu.UserDataText; string phoneNumber = pdu.SmscAddress; //MessageBox.Show(i +" -- "+messageSMS); string URL = System.Configuration.ConfigurationManager.AppSettings["IncomingSMSUrl"] + phoneNumber + "&incommingmessage=" + messageSMS; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); if (res.StatusCode == HttpStatusCode.OK) { comm.DeleteMessage(i, storage); //MessageBox.Show(i.ToString()); //WriteLogFile("SMS Sent", "SMS ID: " + Id + " |Status 1"); } else { WriteLogFile("SMS Not Recieved", "Error in reading the web page. Check internet connectivity"); } res.Close(); i++; count--; } } catch (Exception ex) { //Log WriteLogFile("Exception", ex.Message); } finally { comm.Close(); } }
public void closeConnection() { try { comm.Close(); } catch (Exception ex) { Console.WriteLine(ex); } }
} // Message public void Close() { try { if (comm.IsOpen()) { comm.Close(); } } catch (Exception ex) { } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (comm != null) { comm.PhoneConnected -= new EventHandler(comm_PhoneConnected); comm.PhoneDisconnected -= new EventHandler(comm_PhoneDisconnected); // Close connection to phone if (comm != null && comm.IsOpen()) { comm.Close(); } comm = null; } }
public void closePort() { try { if (comm.IsOpen()) { comm.Close(); } } catch (Exception ex) { throw ex; } }
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 void ReiniciarConexionCOM() { try { new LogAplicacion().Info("Reiniciando conexion de BAM..."); comm.Close(); LiberarPuertoCOM(); Thread.Sleep(10000); CrearConexionCOM(); } catch (Exception e) { new LogAplicacion().Error("Ocurrio un error al ejecutar la funcion ReiniciarConexionCOM() <br></br>Error: " + e); } }
public bool SendSMS(string Port, string message, string phoneNo) { try { comm = new GsmCommMain(Port, 19200, 300); comm.Open(); if (comm.IsConnected()) { byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault; SmsSubmitPdu pdu = new SmsSubmitPdu(message, phoneNo, dcs); comm.SendMessage(pdu); // Console.WriteLine("BhattiConsole: Message sent from Port " + item); comm.Close(); return(true); } } catch (Exception ex) { // Console.WriteLine("BhattiConsole: " + ex); comm.Close(); } return(false); }
public void Close() //ref GsmCommMain comm { try { while (comm != null && (comm.IsConnected() || comm.IsOpen())) { //comm.ResetToDefaultConfig(); //comm.ReleaseProtocol(); comm.Close(); } } catch (Exception) { ; } comm = null; }
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()); } }