/// <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; }
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()); } }
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; } }
// 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; } }
/// <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) { } }
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) { } } } }
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(); }
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; }