Ejemplo n.º 1
0
        private void ButtonConnect_Click_1(object sender, EventArgs e)
        {
            if (ButtonConnect.Tag == null)
            {
                try
                {
                    com = new ComConnection(comboBoxCOMList.SelectedItem.ToString(),
                                            Convert.ToInt32(comboBoxBIT.SelectedItem.ToString()));
                    com.ReceivedEvent += com_ReceivedOrReceiveEvent;
                    //com.SendingEvent += com_ReceivedOrReceiveEvent;
                    com.Open();

                    smsService = new SmsService(com);
                    ButtonConnect.Text = "Disconnect";
                    ButtonConnect.Tag = true;
                    tabControl1.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    com.Dispose();
                }
            }
            else
            {
                smsService.Dispose();
                ButtonConnect.Tag = null;
                ButtonConnect.Text = "Connect";
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            //Console.WriteLine(String.Format("\x01a"));
            //Console.ReadLine();
            //try
            //{
            //    // _log.Info("Start Sms Service");
            //    RemotePrivoder.SmsProvider=new SmsProvider();
            //    var _smsChannel = new TcpChannel(Configuration.Remoteing.Port);
            //    ChannelServices.RegisterChannel(_smsChannel, false);
            //    RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotePrivoder),
            //                                                       Configuration.Remoteing.ServiceName,
            //                                                       WellKnownObjectMode.Singleton);
            //}
            //catch (DeviceConnectionException ex)
            //{
            //    // _log.Error("Start sms service have error", ex);
            //}
            //catch (Exception ex)
            //{
            //    // _log.Error("Start sms service have error", ex);
            //    Thread.Sleep(1000);
            //}
            var conn = new ComConnection("COM1", 9600);
            conn.Open();
            try
            {

                //while (true)
                //{
                //    string command = Console.ReadLine();
                //    //var com = new Protocol.SendCommands.SetSmsFromatCommand(SmsFormat.Pdu);
                //    conn.Send(command);
                //}
                var service = new SmsService(conn, "8613800756500");
                service.SetSmsAutoRecieve();
                service.ReceiveSmsEvent += new EventHandler<NewMessageEventHandlerArgs>(service_ReceiveSmsEvent);
                //service.ChinaMobile = false;

                //service.ServiceCenterNumber = "8613800756500";//service.GetServicePhone();
                //ThreadPool.QueueUserWorkItem(MultiSend1, service);
                //ThreadPool.QueueUserWorkItem(MultiSend2, service);
                //ThreadPool.QueueUserWorkItem(MultiSend3, service);
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Exception exx = ex;
                Console.Read();
            }
            finally
            {
                conn.Close();
            }
            Console.Read();
            Console.Read();
            Console.Read();
        }
Ejemplo n.º 3
0
 public SmsProvider()
 {
     try
     {
         var com = new ComConnection(Configuration.PortName, Configuration.BaudRate);
         _handler = Configuration.SmsHandler;
         if (_handler != null)
             _handler.Priovider = this;
         _service = new SmsService(com);
         _service.ReceiveSmsEvent += ServiceNewSmsEvent;
         _log = LogManager.GetLogger(GetType());
         _service.SetSmsAutoRecieve();
     }
     catch (Exception ex)
     {
         _log.Error("Ini error.", ex);
     }
 }