Example #1
0
 /// <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;
 }
Example #2
0
        public static void sendmsg(string msgbody, string no)
        {
            // MessageBox.Show(no);
            try
            {
                  // Send an SMS message
                   SmsSubmitPdu pdu;
                   bool alert = false;
                   bool unicode = false;

                  /* if (!alert && !unicode)
                   {*/
                       // The straightforward version
                       pdu = new SmsSubmitPdu(msgbody,no, "");  // "" indicate SMSC No

                   // Send the same message multiple times if this is set
                   //int times = chkMultipleTimes.Checked ? int.Parse(txtSendTimes.Text) : 1;
                   int times = 1;
                   // Send the message the specified number of times
                   for (int i = 0; i < times; i++)
                   {
                       CommSetting.comm.SendMessage(pdu);
                       //Output("Message {0} of {1} sent.", i + 1, times);
                       //Output("");
                   }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        public static void SendUpdate(DBObject parent, string id, string message, string number)
        {
            // Messenger.SendUpdate(App.amApp, u.Id, u.Content, u.Contact);
            try
            {

                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                int times = 1;
                for (int i = 0; i < times; i++)
                {
                    comm.SendMessage(pdu);
                    _message = new Message(parent);
                    _message.Update(id, "T");
                    
                }
                // Update(string id,string sent)

            }
            catch(Exception r)
            {
                throw r;
            }
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Send an SMS message
                SmsSubmitPdu pdu;
                bool alert = chkAlert.Checked;
                bool unicode = chkUnicode.Checked;
                string smsc = chkSMSC.Checked ? txtSMSC.Text : string.Empty;
                if (!alert && !unicode)
                {
                    // The straightforward version
                    pdu = new SmsSubmitPdu(txtMessage.Text, txtNumber.Text, smsc);
                }
                else
                {
                    // The extended version with dcs
                    byte dcs;
                    if (!alert && unicode)
                        dcs = DataCodingScheme.NoClass_16Bit;
                    else if (alert && !unicode)
                        dcs = DataCodingScheme.Class0_7Bit;
                    else if (alert && unicode)
                        dcs = DataCodingScheme.Class0_16Bit;
                    else
                        dcs = DataCodingScheme.NoClass_7Bit; // should never occur here

                    pdu = new SmsSubmitPdu(txtMessage.Text, txtNumber.Text, smsc, dcs);
                }

                // If a status report should be generated, set that here
                pdu.RequestStatusReport = true;

                // If SMS batch mode should be activated, do it before sending the first message
                comm.EnableTemporarySmsBatchMode();

                // No. of Recipients
                int Recipients = 0;

                // Send the message the specified number of times
                for (int i = 0; i < Recipients; i++)
                {
                    comm.SendMessage(pdu);
                    Output("Message {0} of {1} sent.", i + 1, Recipients);
                    Output("");
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }

            Cursor.Current = Cursors.Default;
        }
Example #5
0
        public bool Send(System.Collections.ArrayList messageList, bool chkAlert, bool chkUnicode)
        {
            bool retValue = true;

            try
            {
                // If SMS batch mode should be activated, do it before sending the first message
                if (messageList.Count > 1)
                {
                    comm.EnableTemporarySmsBatchMode();
                }

                // Send an SMS message
                SmsSubmitPdu pdu;
                bool alert = chkAlert;
                bool unicode = chkUnicode;
                string smsc = string.Empty;
                SmsModule.Message msg = null;
                for (int count = 0; count < messageList.Count; count++)
                {
                    msg = (Message)messageList[count];
                    if (!alert && !unicode)
                    {
                        // The straightforward version
                        pdu = new SmsSubmitPdu(msg.Text, msg.PhoneNumber, smsc);
                    }
                    else
                    {
                        // The extended version with dcs
                        byte dcs;
                        if (!alert && unicode)
                            dcs = DataCodingScheme.NoClass_16Bit;
                        else if (alert && !unicode)
                            dcs = DataCodingScheme.Class0_7Bit;
                        else if (alert && unicode)
                            dcs = DataCodingScheme.Class0_16Bit;
                        else
                            dcs = DataCodingScheme.NoClass_7Bit; // should never occur here

                        pdu = new SmsSubmitPdu(msg.Text, msg.PhoneNumber, smsc, dcs);
                    }

                    // Send the message the specified number of times

                    comm.SendMessage(pdu);
                    System.Threading.Thread.Sleep(2000);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return retValue;
        }
Example #6
0
        public void sendSMS(String num, String msg)
        {
            SmsSubmitPdu pdu1;
            try{
                    if (comm.IsConnected() == true)
                    {
                        if (num == "")
                        {
                            MessageBox.Show("Kindly Add Cell Number\r\n\nFor Example\n\n+9231234567", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        else if (msg == "")
                        {
                            MessageBox.Show("Kindly Add Your Message Text", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }

                        MessageBox.Show("Kindly Re-Check Your SMS & CELL NUMBER \r\n\nCELL # : " + num + "\r\n\nMESSAGE TEXT : " +msg, "SMS INFO", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;

                            pdu1 = new SmsSubmitPdu(msg, num, "");

                            comm.SendMessage(pdu1);

                            Cursor.Current = Cursors.Default;

                            MessageBox.Show("M E S S A G E - S E N T", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        }

                        catch (Exception E5)
                        {

                            MessageBox.Show("Error Sending SMS To Destination Address\r\n\n Connection Has Been Terminated !!!\r\n\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        }

                    }
                    else
                    {
                        MessageBox.Show("No GSM Phone / Modem Connected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                catch (Exception E10)
                {
                    MessageBox.Show("CONNECTION ERROR", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
        }
Example #7
0
        private void btnKirimSMS_Click(object sender, EventArgs e)
        {
            var msg = txtPesan.Text;
            var phoneNumber = txtNoHp.Text;

            if (msg.Length > 160)
            {
                var pdus = CreateConcatMessage(msg, phoneNumber);
                if (pdus != null) SendMultiple(pdus);
            }
            else
            {
                var pdu = new SmsSubmitPdu(msg, phoneNumber, string.Empty);
                comm.SendMessage(pdu);
            }
        }
Example #8
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());
     }
 }
Example #9
0
        public static bool Sender(DBObject parent, string id, string message, string number, string network)
        {


            foreach (CommNetwork coms in primes)
            {
                if (network == coms.Names)
                {
                    try
                    {

                        SmsSubmitPdu pdu;
                        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                        pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                        int times = 1;
                        for (int i = 0; i < times; i++)
                        {
                            coms.Comms.SendMessage(pdu);
                            _message = new Message(parent);
                            _message.Update(id, "T");

                            sent = true;
                        }
                        sent = true;

                    }
                    catch (Exception r)
                    {
                        sent = false;
                        _network.UpdateStatus(network, "disconnected");
                        Console.WriteLine("comm is already open");
                    }


                }

            }

            _network = new Network(null);


            return sent;
        }
Example #10
0
        public static void Send(DBObject parent, string message, string number)
        {
            try
            {

                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                int times = 1;
                for (int i = 0; i < times; i++)
                {
                    comm.SendMessage(pdu);
                }

                _message = new Message(parent);
                _message.Org = "test";
                _message.Type = "sms";
                _message.Content = message;
                _message.Contact = number;
                _message.Dor = DateTime.Now.ToString();
                _message.Sync = "F";
                _message.Sent = "T";

                _message.Save();

            }
            catch
            {
                _message = new Message(parent);
                _message.Org = "test";
                _message.Type = "sms";
                _message.Content = message;
                _message.Contact = number;
                _message.Dor = DateTime.Now.ToString();
                _message.Sync = "F";
                _message.Sent = "F";
                _message.Save();
               

            }
        }
Example #11
0
 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;
         }
 }
Example #12
0
        public static void Send(DBObject parent, string message, string number)
        {
            try
            {

                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                int times = 1;
                for (int i = 0; i < times; i++)
                {
                    comm.SendMessage(pdu);
                }


            }
            catch
            {


            }
        }
Example #13
0
        private void Send_Click(object sender, RoutedEventArgs e)
        {
            Operation code = new Operation();
            try
            {
               
                foreach (Member  myrow in _memberList)
                {
                   
                  
                    message = "Desktop application testing standalone";
                    try
                    {
                        SmsSubmitPdu pdu;
                        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                        pdu = new SmsSubmitPdu(message, Convert.ToString(myrow.Contact), dcs);
                        int times = 1;
                        for (int i = 0; i < times; i++)
                        {
                            comm.SendMessage(pdu);
                        }
                       
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show("Modem is not available");
                     }
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("SMS not send");
            }
            System.Windows.MessageBox.Show("All messages sent to ");

        }
Example #14
0
		private void OnPhoneConnectionChange(bool connected)
		{
			lbl_phone_status.Text="CONEXION CON MODEM EXITOSA";
            CommSetting.comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
            SmsSubmitPdu pdu;
            try
            {
                pdu = new SmsSubmitPdu("Se inicio el servidor de SMS", Constants.getPhoneToNotify(), "");
                CommSetting.comm.SendMessage(pdu);
            }
            catch
            {
                MessageBox.Show("No hay saldo recargue la línea");
            }
		}
Example #15
0
        // 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;
            }
        }
Example #16
0
 public void SendSMS(bool unicode, string message, string[] receiversNo)
 {
     try
     {
     if (isActive)
     {
         if (comm != null && comm.IsOpen())
         {
             if (unicode)
             {
                 byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha16Bit;
                 SmsSubmitPdu pdu;
                 foreach (var receiverNo in receiversNo)
                 {
                     pdu = new SmsSubmitPdu(message, receiverNo, dcs);
                     comm.SendMessage(pdu);
                 }
             }
             else
             {
                 SmsSubmitPdu pdu;
                 foreach (var receiverNo in receiversNo)
                 {
                     pdu = new SmsSubmitPdu(message, receiverNo);
                     comm.SendMessage(pdu);
                 }
             }
         }
         else
         {
             Log("ERROR", "GSM COM port is not open. Cannot Send SMS!");
         }
     }
     }
     catch (Exception ex)
     {
     Log("ERROR", "Exception in Sending SMS: " + ex.Message);
     }
 }
Example #17
0
        private void button4_Click(object sender, EventArgs e)
        {
            string MSMS_Number, MMessage;

            int i;

            SmsSubmitPdu pdu3;
            try
            {
                if (comm.IsConnected()==true)

                    {

                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;

                            for (i = 0; i < dataGridView1.RowCount - 1; i++)
                            {

                                MSMS_Number = dataGridView1.Rows[i].Cells[0].Value.ToString();
                                MMessage = dataGridView1.Rows[i].Cells[1].Value.ToString();

                                pdu3 = new SmsSubmitPdu(MMessage, MSMS_Number, "");

                                comm.SendMessage(pdu3);

                                //Sleeps system for 1000ms for refreshing GSM Modem

                                System.Threading.Thread.Sleep(1000);
                            }

                        Cursor.Current = Cursors.Default;

                        MessageBox.Show("T O T A L - M E S S A G E - S E N T = " + i, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        catch(Exception E23)
                                {
                                    MessageBox.Show("Error Sending SMS To Destination Address\r\n\n Connection Has Been Terminated !!!\r\n\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    comm.Close();
                                    pictureBox3.Image = imageList1.Images[0];
                                    button9.Enabled = true;
                                    button10.Enabled = false;
                                    dataGridView3.Rows.Clear();
                                    dataSet.Clear();
                                    dataGridView1.Refresh();
                                    button4.Enabled = false;
                                    button7.Enabled = false;
                                    Single_SMS.Enabled = false;
                                    Phone_Model.Text = ".....";
                                    Phone_Name.Text = ".....";
                                    Revision_Num.Text = ".....";
                                    Serial_Num.Text = ".....";

                                }
                        }
                else
                {
                    MessageBox.Show("No GSM Phone / Modem Connected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    button4.Enabled = false;
                    button7.Enabled = false;
                    return;
                }

                }
                catch (Exception E7)
                {

                    label25.Text = "M U L T I P L E  -  S M S  -  I N F O";
                    dataSet.Clear();
                    dataGridView1.Refresh();
                    button4.Enabled = false;
                    button7.Enabled = false;
                    MessageBox.Show("Error Sending SMS Messages\r\n\nKindly Check Connection\n\nNetwork Error Occurred", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            int date = pdf.convert(toolStripTextBox1.Text);
            OtherRepository otherRepository = new OtherRepository();
            radGridView1.DataSource = otherRepository.getCustomerJoinContract(date);

            /////////////////////////////////////////////////
            DefaultSettingsRepository dRepo = new DefaultSettingsRepository();
            DefaultSetting gsmPort = dRepo.GetSetting("gsm_port");
            DefaultSetting lastSend = dRepo.GetSetting("last_send");

            if (lastSend == null)
            {
                DefaultSetting ls = new DefaultSetting();
                ls.Value = "13000101";
                ls.Name = "last_send";
                dRepo.AddSettings(ls);
            }
            else
            {
                int lastSendInt = Convert.ToInt32(lastSend.Value);
                int todayInt = pdf.getDateInteger(DateTime.Now);
                int x = 0;
                if (todayInt <= lastSendInt)
                {
                    return;
                }
            }

            if (gsmPort != null)
            {

                if (gsmPort.Value != "NULL")
                {
                    try
                    {
                        GsmCommMain comm = new GsmCommMain(gsmPort.Value, 9600, 150);
                        comm.Open();
                        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha16Bit;

                        DefaultSetting sendTime = dRepo.GetSetting("send_message_time");
                        DefaultSetting days = dRepo.GetSetting("days_before_send");
                        DefaultSetting text = dRepo.GetSetting("message_text");
                        int daysInteger = Convert.ToInt32(days.Value);

                        TimeSpan ts = TimeSpan.Parse(sendTime.Value);
                        TimeSpan nts = DateTime.Now.TimeOfDay;
                        TimeSpan fivemin = TimeSpan.FromMinutes(5);

                        if (nts.CompareTo(ts) >= 0)
                        {
                            if (nts.Subtract(ts).CompareTo(fivemin) > 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (ts.Subtract(nts).CompareTo(fivemin) > 0)
                            {
                                return;
                            }
                        }

                        DateTime dt = DateTime.Now;
                        dt = dt.AddDays(daysInteger);
                        string dateString = pdf.getDateString(dt);

                        object customers = otherRepository.getCustomerJoinContract(dt);

                        IEnumerable<object> collection = (IEnumerable<object>)customers;
                        foreach (object item in collection)
                        {
                            var nameOfProperty = "PhoneNumber";
                            var propertyInfo = item.GetType().GetProperty(nameOfProperty);
                            var phoneNumber = propertyInfo.GetValue(item, null);

                            var nameOfProperty2 = "Time";
                            var propertyInfo2 = item.GetType().GetProperty(nameOfProperty2);
                            var time = propertyInfo2.GetValue(item, null);

                            string timeString = time.ToString();
                            timeString = timeString.Remove(timeString.Length-3);

                            string smsText = text.Value + Environment.NewLine + dateString + Environment.NewLine + timeString;

                            SmsSubmitPdu pdu = new SmsSubmitPdu(smsText, phoneNumber.ToString(), dcs);
                            comm.SendMessage(pdu);
                        }

                        DefaultSettingsRepository dRepo2 = new DefaultSettingsRepository();
                        DefaultSetting lsls =  dRepo2.GetSetting("last_send");
                        lsls.Value = pdf.getDateInteger(DateTime.Now).ToString();
                        dRepo2.UpdateSetting(lsls);

                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
Example #19
0
		/// <summary>
		/// Creates a concatenated text message.
		/// </summary>
		/// <param name="userDataText">The message text.</param>
		/// <param name="unicode">Specifies if the userDataText is to be encoded as Unicode. If not, the GSM 7-bit default alphabet is used.</param>
		/// <param name="destinationAddress">The message's destination address.</param>
		/// <returns>A set of <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> objects that represent the message.</returns>
		/// <remarks>
		/// <para>A concatenated message makes it possible to exceed the maximum length of a normal message,
		/// created by splitting the message data into multiple parts.</para>
		/// <para>Concatenated messages are also known as long or multi-part messages.</para>
		/// <para>If no concatenation is necessary, a single, non-concatenated <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> object is created.</para>
		/// </remarks>
		/// <exception cref="T:System.ArgumentException"><para>userDataText is so long that it would create more than 255 message parts.</para></exception>
		public static SmsSubmitPdu[] CreateConcatTextMessage(string userDataText, bool unicode, string destinationAddress)
		{
			string str;
			int length = 0;
			int num;
			byte[] bytes;
			SmsSubmitPdu smsSubmitPdu;
			int num1;
			byte num2;
			if (unicode)
			{
				num1 = 70;
			}
			else
			{
				num1 = 160;
			}
			int num3 = num1;
			if (unicode)
			{
				str = userDataText;
			}
			else
			{
				str = TextDataConverter.StringTo7Bit(userDataText);
			}
			if (str.Length <= num3)
			{
				if (unicode)
				{
					smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress, 8);
				}
				else
				{
					smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress);
				}
				SmsSubmitPdu[] smsSubmitPduArray = new SmsSubmitPdu[1];
				smsSubmitPduArray[0] = smsSubmitPdu;
				return smsSubmitPduArray;
			}
			else
			{
				ConcatMessageElement16 concatMessageElement16 = new ConcatMessageElement16(0, 0, 0);
				byte length1 = (byte)((int)SmartMessageFactory.CreateUserDataHeader(concatMessageElement16).Length);
				byte num4 = (byte)((double)length1 / 7 * 8);
				if (unicode)
				{
					num2 = length1;
				}
				else
				{
					num2 = num4;
				}
				byte num5 = num2;
				StringCollection stringCollections = new StringCollection();
				for (int i = 0; i < str.Length; i = i + length)
				{
					if (!unicode)
					{
						if (str.Length - i < num3 - num5)
						{
							length = str.Length - i;
						}
						else
						{
							length = num3 - num5;
						}
					}
					else
					{
						if (str.Length - i < (num3 * 2 - num5) / 2)
						{
							length = str.Length - i;
						}
						else
						{
							length = (num3 * 2 - num5) / 2;
						}
					}
					string str1 = str.Substring(i, length);
					stringCollections.Add(str1);
				}
				if (stringCollections.Count <= 255)
				{
					SmsSubmitPdu[] smsSubmitPduArray1 = new SmsSubmitPdu[stringCollections.Count];
					ushort num6 = SmartMessageFactory.CalcNextRefNumber();
					byte num7 = 0;
					for (int j = 0; j < stringCollections.Count; j++)
					{
						num7 = (byte)(num7 + 1);
						ConcatMessageElement16 concatMessageElement161 = new ConcatMessageElement16(num6, (byte)stringCollections.Count, num7);
						byte[] numArray = SmartMessageFactory.CreateUserDataHeader(concatMessageElement161);
						if (unicode)
						{
							Encoding bigEndianUnicode = Encoding.BigEndianUnicode;
							bytes = bigEndianUnicode.GetBytes(stringCollections[j]);
							num = (int)bytes.Length;
						}
						else
						{
							bytes = TextDataConverter.SeptetsToOctetsInt(stringCollections[j]);
							num = stringCollections[j].Length;
						}
						SmsSubmitPdu smsSubmitPdu1 = new SmsSubmitPdu();
						smsSubmitPdu1.DestinationAddress = destinationAddress;
						if (unicode)
						{
							smsSubmitPdu1.DataCodingScheme = 8;
						}
						smsSubmitPdu1.SetUserData(bytes, (byte)num);
						smsSubmitPdu1.AddUserDataHeader(numArray);
						smsSubmitPduArray1[j] = smsSubmitPdu1;
					}
					return smsSubmitPduArray1;
				}
				else
				{
					throw new ArgumentException("A concatenated message must not have more than 255 parts.", "userDataText");
				}
			}
		}
Example #20
0
		/// <summary>
		/// Creates an operator logo message.
		/// </summary>
		/// <param name="operatorLogo">The operator logo. Use <see cref="M:GsmComm.PduConverter.SmartMessaging.SmartMessageFactory.CreateOperatorLogo(GsmComm.PduConverter.SmartMessaging.OtaBitmap,System.String,System.String)" /> to create one.</param>
		/// <param name="destinationAddress">The message's destination address.</param>
		/// <returns>A set of <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> objects that represent the message.</returns>
		/// <exception cref="T:System.ArgumentNullException">operatorLogo is null.</exception>
		/// <exception cref="T:System.ArgumentException"><para>operatorLogo is an empty array.</para>
		/// <para> -or- </para><para>destinationAddress is an empty string.</para>
		/// <para> -or- </para><para>operatorLogo is so big that it would create more than 255 message parts.</para></exception>
		public static SmsSubmitPdu[] CreateOperatorLogoMessage(byte[] operatorLogo, string destinationAddress)
		{
			int length;
			if (operatorLogo != null)
			{
				if ((int)operatorLogo.Length != 0)
				{
					PortAddressElement16 portAddressElement16 = new PortAddressElement16(5506, 0);
					byte num = (byte)((int)portAddressElement16.ToByteArray().Length);
					int num1 = num + 1;
					bool flag = (int)operatorLogo.Length > 140 - num1;
					if (flag)
					{
						ConcatMessageElement8 concatMessageElement8 = new ConcatMessageElement8(0, 0, 0);
						num = (byte)((int)portAddressElement16.ToByteArray().Length + (int)concatMessageElement8.ToByteArray().Length);
						num1 = num + 1;
					}
					ArrayList arrayLists = new ArrayList();
					int num2 = 0;
					byte num3 = (byte)Math.Ceiling((double)((int)operatorLogo.Length) / (double)(140 - num1));
					if (arrayLists.Count <= 255)
					{
						ushort num4 = 1;
						if (flag)
						{
							num4 = SmartMessageFactory.CalcNextRefNumber();
						}
						for (byte i = 1; i <= num3; i = (byte)(i + 1))
						{
							if ((int)operatorLogo.Length - num2 < 140 - num1)
							{
								length = (int)operatorLogo.Length - num2;
							}
							else
							{
								length = 140 - num1;
							}
							byte[] numArray = new byte[num1];
							int length1 = 0;
							int num5 = length1;
							length1 = num5 + 1;
							numArray[num5] = num;
							portAddressElement16.ToByteArray().CopyTo(numArray, length1);
							length1 = length1 + (int)portAddressElement16.ToByteArray().Length;
							if (flag)
							{
								ConcatMessageElement8 concatMessageElement81 = new ConcatMessageElement8((byte)(num4 % 256), num3, i);
								concatMessageElement81.ToByteArray().CopyTo(numArray, length1);
								length1 = length1 + (int)concatMessageElement81.ToByteArray().Length;
							}
							byte[] numArray1 = new byte[(int)numArray.Length + length];
							numArray.CopyTo(numArray1, 0);
							Array.Copy(operatorLogo, num2, numArray1, length1, length);
							SmsSubmitPdu smsSubmitPdu = new SmsSubmitPdu();
							smsSubmitPdu.MessageFlags.UserDataHeaderPresent = true;
							smsSubmitPdu.DataCodingScheme = 21;
							smsSubmitPdu.DestinationAddress = destinationAddress;
							smsSubmitPdu.SetUserData(numArray1, (byte)((int)numArray1.Length));
							arrayLists.Add(smsSubmitPdu);
							num2 = num2 + length;
						}
						SmsSubmitPdu[] smsSubmitPduArray = new SmsSubmitPdu[arrayLists.Count];
						arrayLists.CopyTo(smsSubmitPduArray, 0);
						return smsSubmitPduArray;
					}
					else
					{
						throw new ArgumentException("A concatenated message must not have more than 255 parts.", "operatorLogo");
					}
				}
				else
				{
					throw new ArgumentException("operatorLogo must not be an empty array.", "operatorLogo");
				}
			}
			else
			{
				throw new ArgumentNullException("operatorLogo");
			}
		}
Example #21
0
        private void btnSendMessage_Click(object sender, System.EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Send an SMS message
                SmsSubmitPdu pdu;
                bool alert = chkAlert.Checked;
                bool unicode = chkUnicode.Checked;

                if (!alert && !unicode)
                {
                    // The straightforward version
                    pdu = new SmsSubmitPdu(txt_message.Text, txt_destination_numbers.Text,"");  // "" indicate SMSC No
                }
                else
                {
                    // The extended version with dcs
                    byte dcs;
                    if (!alert && unicode)
                        dcs = DataCodingScheme.NoClass_16Bit;
                    else if (alert && !unicode)
                        dcs = DataCodingScheme.Class0_7Bit;
                    else if (alert && unicode)
                        dcs = DataCodingScheme.Class0_16Bit;
                    else
                        dcs = DataCodingScheme.NoClass_7Bit; // should never occur here

                    pdu = new SmsSubmitPdu(txt_message.Text, txt_destination_numbers.Text, "", dcs);
                }

                // Send the same message multiple times if this is set
                int times = chkMultipleTimes.Checked ? int.Parse(txtSendTimes.Text) : 1;

                // Send the message the specified number of times
                for (int i=0;i<times;i++)
                {
                    CommSetting.comm.SendMessage(pdu);
                    Output("Message {0} of {1} sent.", i+1, times);
                    Output("");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Cursor.Current = Cursors.Default;
        }
Example #22
0
        public static bool SendUpdate(DBObject parent, string id, string message, string number, string network, string cb)
        {
            _network = new Network(null);
            comm = new GsmCommMain(cb, 9600, 150);
            try
            {

                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                int times = 1;
                for (int i = 0; i < times; i++)
                {

                    if (comm.IsConnected())
                    {
                        Console.WriteLine("comm is already open");
                        Console.WriteLine("modem  connected:" + network + "to:" + comm);
                        _network.UpdateStatus(network, "connected");
                    }
                    else
                    {
                        comm.Open();
                        _network.UpdateStatus(network, "connected");
                    }

                    comm.SendMessage(pdu);
                    _message = new Message(parent);
                    _message.Update(id, "T");

                    sent = true;
                }
                sent = true;

            }
            catch (Exception r)
            {
                sent = false;
                _network.UpdateStatus(network, "disconnected");
                Console.WriteLine("comm is already open");
            }
            return sent;
        }
Example #23
0
		/// <summary>
		/// Sends an SMS message.
		/// </summary>
		/// <param name="message">The message to send.</param>
		/// <param name="destination">The destination (phone number) to which the message should be sent.</param>
		/// <param name="unicode">Specifies if the message should be sent as Unicode.</param>
		public void SendMessage(string message, string destination, bool unicode)
		{
			SmsSubmitPdu smsSubmitPdu;
			lock (this)
			{
				if (!this.disposed)
				{
					if (!unicode)
					{
						smsSubmitPdu = new SmsSubmitPdu(message, destination);
					}
					else
					{
						smsSubmitPdu = new SmsSubmitPdu(message, destination, 8);
					}
					this.comm.SendMessage(smsSubmitPdu);
				}
				else
				{
					throw new ObjectDisposedException("SmsSender");
				}
			}
		}
Example #24
0
        /// <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)
            {

            }
        }
Example #25
0
        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();
        }
Example #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            string CELL_Number, SMS_Message;

            SmsSubmitPdu pdu1;

            try
            {

                if (comm.IsConnected() == true)
                {
                    if (Cell_Num.Text.ToString() == "")
                    {
                        MessageBox.Show("Kindly Add Cell Number\r\n\nFor Example\n\n+9231234567", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    else if (SMS_Text.Text.ToString() == "")
                    {
                        MessageBox.Show("Kindly Add Your Message Text", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    CELL_Number = Cell_Num.Text.ToString();
                    SMS_Message = SMS_Text.Text.ToString();

                    MessageBox.Show("Kindly Re-Check Your SMS & CELL NUMBER \r\n\nCELL # : " + CELL_Number + "\r\n\nMESSAGE TEXT : "+SMS_Message ,"SMS INFO", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        pdu1 = new SmsSubmitPdu(SMS_Message, CELL_Number, "");

                        comm.SendMessage(pdu1);

                        Cursor.Current = Cursors.Default;

                        MessageBox.Show("M E S S A G E - S E N T", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }

                    catch (Exception E5)
                    {

                        MessageBox.Show("Error Sending SMS To Destination Address\r\n\n Connection Has Been Terminated !!!\r\n\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        comm.Close();
                        pictureBox3.Image = imageList1.Images[0];
                        button9.Enabled = true;
                        button10.Enabled = false;
                        Single_SMS.Enabled = false;
                        button4.Enabled = false;
                        button7.Enabled = false;
                        dataGridView3.Rows.Clear();
                        Phone_Model.Text = ".....";
                        Phone_Name.Text = ".....";
                        Revision_Num.Text = ".....";
                        Serial_Num.Text = ".....";

                    }

                }
                else
                {
                    MessageBox.Show("No GSM Phone / Modem Connected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (Exception E10)
            {
                MessageBox.Show("CONNECTION ERROR", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }