Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        //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;
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 //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;
     }
 }
Ejemplo n.º 7
0
 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");
         }
     }
 }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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();
     }
 }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
 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());
     }
 }
Ejemplo n.º 16
0
        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);
            }
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        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();
            }
        }
Ejemplo n.º 19
0
        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();
                }
            }
        }
Ejemplo n.º 20
0
 private static bool _disconnect_from_gsm()
 {
     _GsmComm.Close();
     if (!_GsmComm.IsOpen())
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 21
0
        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();
            }
        }
Ejemplo n.º 22
0
 public void closeConnection()
 {
     try
     {
         comm.Close();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Ejemplo n.º 23
0
        }  // Message

        public void Close()
        {
            try
            {
                if (comm.IsOpen())
                {
                    comm.Close();
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 24
0
 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;
     }
 }
Ejemplo n.º 25
0
 public void closePort()
 {
     try
     {
         if (comm.IsOpen())
         {
             comm.Close();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
 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);
     }
 }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 public void Close() //ref GsmCommMain comm
 {
     try
     {
         while (comm != null && (comm.IsConnected() || comm.IsOpen()))
         {
             //comm.ResetToDefaultConfig();
             //comm.ReleaseProtocol();
             comm.Close();
         }
     }
     catch (Exception)
     {
         ;
     }
     comm = null;
 }
Ejemplo n.º 30
0
 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());
     }
 }