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); }
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; } }
//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()); } }
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 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); }
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); }
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; } } }
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 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); }
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); }
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); }
//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; } }
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 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); }
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); } }
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); } }
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 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); }
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 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); } }
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); } }
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 void ModemConnectTest() { ModemService modemService = ModemService.Instance; //var result = modemService.ModemConnect(3,115200,100); var result = new GsmCommMain("COM3"); Assert.AreEqual(true, result); }
public ModemService(int commPort, int commBaudRate, int commTimeOut) { Comm_Port = commPort; Comm_BaudRate = commBaudRate; Comm_TimeOut = commTimeOut; comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut); }
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 votecountsFrm() { InitializeComponent(); this.comm = null; this.registerMessageReceived = false; this.smsServer = null; this.remotingSecurity = new SecuritySettings(); }