コード例 #1
0
ファイル: Form1.cs プロジェクト: Narrya/SmsAlarm
 /// <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;
 }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: smsgsm.cs プロジェクト: ideamonk/SpaceLock
 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;
         }
 }
コード例 #4
0
ファイル: SMS.cs プロジェクト: rizalafani/c-sharp-sms-sender
 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());
     }
 }
コード例 #5
0
ファイル: smsgsm.cs プロジェクト: ideamonk/SpaceLock
 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;
         }
 }
コード例 #6
0
 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());
     }
 }
コード例 #7
0
ファイル: User.cs プロジェクト: waynenguyen/EzyGoEzy
        // 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;
            }
        }
コード例 #8
0
ファイル: frmConnection.cs プロジェクト: briverac/SMS
		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);
			
				
		}
コード例 #9
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;
        }
コード例 #10
0
ファイル: Home.cs プロジェクト: ideamonk/SpaceLock
        /// <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)
            {

            }
        }
コード例 #11
0
ファイル: EzySystem.cs プロジェクト: waynenguyen/EzyGoEzy
        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();
        }
コード例 #12
0
ファイル: settings.cs プロジェクト: ideamonk/SpaceLock
 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");
     }
 }
コード例 #13
0
ファイル: Form1.cs プロジェクト: k4m4r82/SMSGatewayNET1
        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);
            }
        }