Example #1
0
        public bool Open()
        {
            //GsmCommMain comm = null;
            Close();
            bool chk = false;

            try
            {
                try
                {
                    if (GSMport.Length == 0)
                    {
                        ApplicationConfigManagement acm = new ApplicationConfigManagement();
                        GSMport = acm.ReadSetting("GSMport");
                        if (GSMport.Length > 0)
                        {
                            comm = new GsmCommMain(GSMport, 19200, 500);
                            comm.Open();
                            return(true);
                        }
                    }
                }
                catch (Exception)
                {
                    ;
                }

                string[] ports = SerialPort.GetPortNames();
                foreach (string port in ports)
                {
                    try
                    {
                        comm = new GsmCommMain(port, 19200, 500);
                        comm.Open();
                        SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage("تست سلامت جی اس ام Port:" + port, true, "09195614157");
                        comm.SendMessages(pdu);
                        chk     = true;
                        GSMport = port;
                        AddUpdateAppSettings("GSMport", GSMport);
                        logger.ErrorLog("Valid Port of GSM is : " + GSMport);
                        //Close(ref comm);
                        break;
                    }
                    catch (Exception err)
                    {
                        Close(); //ref comm
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorLog("هیچ پورتی وجود ندارد...");
            }

            if (!chk)
            {
                logger.ErrorLog("خطای ارتباط با مودم .... \n\r لطفا از ارتباط مودم با سیستم اطمینان حاصل نمایید....");
            }
            return(chk);
        }
Example #2
0
        public string SendSMSWithGSM(string bodyStr, string Phone, ref bool SendStatus)
        {
            string ReturnStr = "";

            try
            {
                if (comm != null)
                {
                    SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(bodyStr, true, Phone);
                    //SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(bodyStr, true, "09195614157");
                    comm.SendMessages(pdu);
                    ReturnStr += " --- از طریق گوشی محلی ارسال شد";
                    SendStatus = true;
                }
                else
                {
                    ReturnStr += " --- خطای ارسال از طریق گوشی محلی --- Comm Port is Null";
                }
            }
            catch (Exception err)
            {
                ReturnStr += " --- خطای ارسال از طریق گوشی محلی --- " + err.Message;
            }
            return(ReturnStr);
        }
        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);
        }
Example #4
0
        void SendMessages()
        {
            Log.Add(LogLevel.Verbose, "SMS", "Sending SMS...");

            List <TriggerMessage> msgs = new List <TriggerMessage>();

            for (int i = 0; i < _messagesPerTimerTick && _messagesToSend.Count > 0; i++)
            {
                msgs.Add(_messagesToSend.Dequeue());
            }

            foreach (TriggerMessage msg in msgs)
            {
                Log.Add(LogLevel.Info, "SMS", string.Format("Sending Message to {0}", msg.Destination));
                Log.Add(LogLevel.Verbose, "SMS",
                        string.Format("Message: {0} ({2}): {1}", msg.Destination, msg.Text, msg.FlashMessage));

                SmsSubmitPdu[] pdus = SmartMessageFactory.CreateConcatTextMessage(msg.Text, msg.Destination);

                if (msg.FlashMessage)
                {
                    foreach (var pdu in pdus)
                    {
                        pdu.DataCodingScheme = DataCodingScheme.Class0_7Bit;
                    }
                }

                _gsm.SendMessages(pdus);
            }
        }
Example #5
0
 static void Main(string[] args)
 {
     try
     {
         GsmCommMain comm = new GsmCommMain("COM7", 19200, 500);
         comm.Open();
         string         txtMessage            = "Input here very long message please ";
         string         txtDestinationNumbers = "+79235280406";
         bool           unicode = true;
         SmsSubmitPdu[] pdu     = SmartMessageFactory.CreateConcatTextMessage(txtMessage, unicode, txtDestinationNumbers);
         comm.SendMessages(pdu);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        void source_EventChanged(IEventDefinition ev, IEventState state)
        {
            if (!_isConnected && !(state is FreeSCADA.Common.Events.States.StartedEventState))
            {
                return;
            }
            try
            {
                SmsSubmitPdu[] pdus = _settings.TelNumbers.Cast <TelNumElement>().Select(t => new SmsSubmitPdu(state.FormatText(ev.Text), t.TelNum, (byte)DataCodingScheme.GeneralCoding.Alpha16Bit)).ToArray();

                _comm.SendMessages(pdus);
            }
            catch (Exception e)
            {
                Env.Current.Logger.LogInfo(e.Message);
            }
        }
Example #7
0
        public void AutoSMS(string m, string n)
        {
            try
            {
                // GsmCommMain comm = new GsmCommMain("COM78", 9600, 150);
                comm.Open();
                bool           unicode = true;
                SmsSubmitPdu[] pdu     = SmartMessageFactory.CreateConcatTextMessage(m, unicode, n);
                comm.SendMessages(pdu);
                comm.Close();
                // this.Alert("Message Sent!", SDRS.Alert.alertTypeEnum.Success);

                snd();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public static void SendMessage(SmsSubmitPdu[] pdus)
 {
     gsObj.SendMessages(pdus);
 }
Example #9
0
        public bool sendMsg(SMSQueue obj, BackgroundWorker worker, DoWorkEventArgs e)
        {
            try
            {
                bool isSend = false;
                i = 0;

                #region PDU Creation

                SmsSubmitPdu[] pdu;
                try
                {
                    if (m_IsEncoded)
                    {
                        pdu = CreateConcatTextMessage(obj.sms_message, true, Convert.ToString("+92" + obj.receiver_cell_no));
                    }
                    else
                    {
                        pdu = CreateConcatTextMessage(obj.sms_message, false, Convert.ToString("+92" + obj.receiver_cell_no));
                    }
                }
                catch (Exception ex)
                {
                    return(false);
                }

                #endregion

                #region Message Sedning

                if (comm.IsConnected() && comm.IsOpen())
                {
                    comm.SendMessages(pdu);
                    isSend         = true;
                    obj.sms_status = "Sent";
                }
                else
                {
                    Thread.Sleep(500);
                    openPort();
                    isSend         = false;
                    obj.sms_status = "Not Sent";
                    Thread.Sleep(1000);
                    return(false);
                }

                #endregion

                #region Insert History And Update queue

                sh              = new SMSHistory();
                sh.sender_id    = obj.id.ToString();
                sh.sender_name  = obj.receiver_name;
                sh.class_id     = obj.class_id.ToString();
                sh.class_name   = obj.class_name;
                sh.section_id   = obj.section_id.ToString();
                sh.section_name = obj.section_name;
                sh.cell         = obj.receiver_cell_no;
                sh.msg          = obj.sms_message;
                sh.sms_type     = obj.sms_type;
                sh.created_by   = obj.created_by;
                sh.date_time    = DateTime.Now;

                if (miscDAL.InsertSMSHistory(sh) > 0)
                {
                    if (miscDAL.UpdateSMSQueue(obj) > 0)
                    {
                    }
                    else
                    {
                        //MessageBox.Show("Not updated sms queue");
                    }
                }
                else
                {
                    //MessageBox.Show("Sms History not inserted");
                }


                return(isSend);

                #endregion
            }
            catch (Exception ex)

            {
                return(false);
            }
        }