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); } }
public void Send(string message, string nr) { SmsSubmitPdu pdu = new SmsSubmitPdu(message, nr, ""); try { if (!comm.IsOpen()) { comm.Open(); } if (!comm.IsConnected()) { Singleton.Show_MessageBox("błąd portu"); return; } /*if (comm.GetPinStatus() != PinStatus.Ready) { * comm.EnterPin(PIN); * Thread.Sleep(1000); * }*/ comm.SendMessage(pdu); Thread.Sleep(1000); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); return; } //Singleton.Show_MessageBox("wysyłam " + message + "na numer: " + nr); }
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; } }
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()); } }
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 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 async void RegisterConfiguration(ISmsConfiguration Config) { _server = new GsmCommMain(Config.Port, Config.BaudRate, 5000); do { await Task.Delay(100); if (_server.IsOpen()) { // connect event OnServerConnected.CrossInvoke(this, new SmsServerConnected() { TimeConnected = DateTime.Now }); break; } else { try { _server.Open(); } catch (Exception ex) { OnServerConnectionFail.CrossInvoke(this, new ServerConnectErrorEventArgs() { DatePosted = DateTime.Now, guid = Guid.NewGuid(), Message = ex.InnerException.Message ?? ex.Message }); } } }while (true); }
public static bool connects() { cmbCOM = "COM20"; comm = new GsmCommMain(cmbCOM, 9600, 150); Console.WriteLine(cmbCOM); if (comm.IsConnected()) { MainForm._Form1.FeedBack("comm is already open"); state = true; } else { Console.WriteLine("comm is not open"); MainForm._Form1.FeedBack("comm is not open"); try { comm.Open(); state = true; } catch (Exception p) { state = false; MainForm._Form1.FeedBack(" Error" + p.Message.ToString()); } } Console.WriteLine(cmbCOM); return(state); }
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 void setConnected() { string cmbCOM = "COM22"; if (cmbCOM == "") { //MessageBox.Show("Invalid Port Name"); return; } comm = new GsmCommMain(cmbCOM, 115200, 150); //Cursor.Current = Cursors.Default; bool retry; do { retry = false; try { //Cursor.Current = Cursors.WaitCursor; comm.Open(); //Cursor.Current = Cursors.Default; //MessageBox.Show("Modem Connected Sucessfully"); } catch (Exception) { //Cursor.Current = Cursors.Default; } }while (retry); }
public static bool connects() { cmbCOM = "COM4"; comm = new GsmCommMain(cmbCOM, 9600, 150); Console.WriteLine(cmbCOM); if (comm.IsConnected()) { Console.WriteLine("comm is already open"); state = true; } else { Console.WriteLine("comm is not open"); try { comm.Open(); state = true; } catch (Exception) { state = false; } } Console.WriteLine(cmbCOM); return(state); }
private void btnConnect_Click(object sender, EventArgs e) { if (cmbCOM.Text == "") { MessageBox.Show("Invalid Port Name"); return; } comm = new GsmCommMain(cmbCOM.Text, 9600, 150); Cursor.Current = Cursors.Default; bool retry; do { retry = false; try { Cursor.Current = Cursors.WaitCursor; comm.Open(); Cursor.Current = Cursors.Default; MessageBox.Show("Modem Connected Sucessfully"); } catch (Exception) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "GSM Modem is not available", "Check", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { retry = true; } else { return; } } }while (retry); }
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 Open() { if (!gsObj.IsOpen()) { gsObj.Open(); } }
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 button5_Click(object sender, EventArgs e) { if (comboBox1.Text == "") { MessageBox.Show("invalid port number"); return; } comm = new GsmCommMain(comboBox1.Text, 9600, 150); Cursor.Current = Cursors.Default; bool retry; do { retry = false; try { Cursor.Current = Cursors.WaitCursor; comm.Open(); Cursor.Current = Cursors.Default; MessageBox.Show(" connected successfully"); } catch (Exception) { Cursor.Current = Cursors.Default; if (MessageBox.Show(this, "GSM COMMUNICATION IS Not AVAILABLE", "Check", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { retry = true; } else { return; } } }while (retry); }
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); }
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; } } }
public bool SetCOMNum(String com) { gsmcom = new GsmCommMain(com, 9600, 150); Cursor.Current = Cursors.Default; bool retry; do { retry = false; try { Cursor.Current = Cursors.WaitCursor; gsmcom.Open(); Cursor.Current = Cursors.Default; MessageBox.Show("Connected Successfully!"); return(true); } catch (Exception) { return(false); Cursor.Current = Cursors.Default; MessageBox.Show("Error in Connection With Provided COM Try an-Other COM!"); } } while (retry); }
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 Open() { //GsmCommMain comm = null; Close(); bool chk = false; try { try { if (GSMport.Length == 0) { ApplicationConfigManagement acm = new ApplicationConfigManagement(); GSMport = acm.ReadSetting("GSMport"); if (GSMport.Length > 0) { comm = new GsmCommMain(GSMport, 19200, 500); comm.Open(); return(true); } } } catch (Exception) { ; } string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { try { comm = new GsmCommMain(port, 19200, 500); comm.Open(); SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage("تست سلامت جی اس ام Port:" + port, true, "09195614157"); comm.SendMessages(pdu); chk = true; GSMport = port; AddUpdateAppSettings("GSMport", GSMport); logger.ErrorLog("Valid Port of GSM is : " + GSMport); //Close(ref comm); break; } catch (Exception err) { Close(); //ref comm } } } catch (Exception ex) { logger.ErrorLog("هیچ پورتی وجود ندارد..."); } if (!chk) { logger.ErrorLog("خطای ارتباط با مودم .... \n\r لطفا از ارتباط مودم با سیستم اطمینان حاصل نمایید...."); } return(chk); }
public string set(string comPort, string baudRate) { string status = ""; try { Comm_Port = Convert.ToInt16("6"); Comm_BaudRate = Convert.ToInt32(9600); Comm_TimeOut = Convert.ToInt32(100); comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); } catch (Exception E1) { MessageBox.Show("Error Converting COM Port Settings Values", "Check COM Port Values", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); try { comm.Open(); if (comm.IsConnected()) { MessageBox.Show("Connected Successfully To GSM Phone / Modem...!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); status = "connected"; } } catch (Exception E2) { MessageBox.Show("Error While Connecting To GSM Phone / Modem", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(status); }
//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 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 void Form1_Load(object sender, EventArgs e) { int noPortCom = 3; int bauRate = 9600; comm = new GsmCommMain(noPortCom, bauRate); comm.Open(); }
public bool sendlongMsg(string num, string msg) { Cursor.Current = Cursors.WaitCursor; bool Retourne = false; try { // Send an SMS message string message = msg; if (msg.Length >= 140) { double t = message.Length / 140; double f = Math.Round(t); int k = int.Parse(f.ToString()) + 1; pdus = new OutgoingSmsPdu[k]; string ps = message.Substring(0, 140); int dep = 0; for (int i = 0; i < k; i++) { pdu = new SmsSubmitPdu(ps, num); pdus[i] = pdu; dep = dep + ps.Length; if ((message.Length - dep) <= 140 && (message.Length - dep) > 2) { ps = message.Substring(ps.Length, message.Length - 1 - dep); } else if ((message.Length - dep) >= 139) { ps = message.Substring(dep, 140); } } if (!pubCon.comm.IsOpen()) { comm.Open(); } pubCon.comm.SendMessages(pdus); MessageBox.Show("Message envoye avec succes !!!!"); Retourne = true; } // Send the same message multiple times if this is set } catch (Exception ex) { //MessageBox.Show(ex.Message); Retourne = false; } Cursor.Current = Cursors.Default; return(Retourne); }
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 override void Start() { try { Log.Add(LogLevel.Info, "SMS", "Opening device to port."); _gsm.Open(); StartReceiving(); } catch (Exception ex) { Log.AddException("SMS", ex); } }
private void metroTextButton1_Click(object sender, EventArgs e) { //Database.DBStat stat = Database.DBStat.GetDataById(1); //if (stat.STAT != "okla") { // MessageBox.Show("Error in loading the system, please contact the administrator!"); // Environment.Exit(0); //} if (metroComboBox1.SelectedIndex > -1 && metroComboBox2.SelectedIndex > -1) { //port = SimPortsConnection.OpenPort(metroComboBox1.SelectedItem.ToString()); comm = new GsmCommMain(metroComboBox1.SelectedItem.ToString(), 115200, 300); try { Cursor.Current = Cursors.WaitCursor; comm.Open(); if (chkReceived.Checked == true) { comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived); comm.EnableMessageNotifications(); } metroTextButton1.Enabled ^= true; metroTextButton2.Enabled ^= true; metroComboBox1.Enabled ^= true; metroComboBox2.Enabled ^= true; selectedNetwork = metroComboBox2.SelectedItem.ToString(); limit = int.Parse(txtLimit.Text); thread = new Thread(Process); thread.Start(); thread2 = new Thread(TransactProcess); thread2.Start(); richTextBox1.Text += "Ok. Ready...\n"; Cursor.Current = Cursors.Default; } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Error opening port! " + ex.Message); } } else { MessageBox.Show("No Port / Network selected"); } }