Пример #1
0
        /// <summary>
        /// Add SMS Modem to SMS Modem Pool.
        /// 根据指定的 COM 端口标志和波特率创建发送器并返回该对象
        /// </summary>
        /// <param name="port"></param>
        /// <param name="bute"></param>
        public SMSSender CreateModem(string port, int bute)
        {
            SMSSender smsSender = new SMSSender(port, bute);

            if (smsSender.Init())
            {
                smsSender.Sent     += smsSender_Sent;
                smsSender.Received += smsSender_Received;
                //
                if (!_smsPool.ContainsKey(port))
                {
                    _smsPool.Add(port, smsSender);
                }

                InvokeEventLog(String.Format("插入设备:{0},{1}", port, bute));

                _ports.Remove(port);
            }
            else
            {
                InvokeEventLog(String.Format("初始化失败:{0}", port));

                return(null);
            }
            return(smsSender);
        }
Пример #2
0
        public void RequestMessage(object state)
        {
            System.Collections.Generic.Dictionary <string, SMSSender> .ValueCollection valueCollection = _smsPool.Values;
            SMSSender[] smsSenders = new SMSSender[valueCollection.Count];
            valueCollection.CopyTo(smsSenders, 0);
            foreach (SMSSender smsSender in smsSenders)
            {
                InvokeEventLog(String.Format("请求数据:{0}", smsSender.Name));
                List <SMSSendInfo> list = _smsQueue.Get(smsSender.Name);
                foreach (SMSSendInfo smsSendInfo in list)
                {
                    smsSender.AsyncSend(smsSendInfo);

                    InvokeEventLog(String.Format("压入:{0}", smsSendInfo));
                }
            }
        }
Пример #3
0
        public void RequestMessage(object state)
        {
            System.Collections.Generic.Dictionary<string, SMSSender>.ValueCollection valueCollection = _smsPool.Values;
            SMSSender[] smsSenders = new SMSSender[valueCollection.Count];
            valueCollection.CopyTo(smsSenders,0);
            foreach (SMSSender smsSender in smsSenders)
            {
                InvokeEventLog(String.Format("请求数据:{0}", smsSender.Name));
                List<SMSSendInfo> list = _smsQueue.Get(smsSender.Name);
                foreach (SMSSendInfo smsSendInfo in list)
                {
                    smsSender.AsyncSend(smsSendInfo);

                    InvokeEventLog(String.Format("压入:{0}", smsSendInfo));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Add SMS Modem to SMS Modem Pool.
        /// 根据指定的 COM 端口标志和波特率创建发送器并返回该对象
        /// </summary>
        /// <param name="port"></param>
        /// <param name="bute"></param>
        public SMSSender CreateModem(string port, int bute)
        {
            SMSSender smsSender = new SMSSender(port,bute);
            if (smsSender.Init())
            {
                smsSender.Sent += smsSender_Sent;
                smsSender.Received += smsSender_Received;
                //
                if(!_smsPool.ContainsKey(port))
                {
                    _smsPool.Add(port, smsSender);
                }

                InvokeEventLog(String.Format("插入设备:{0},{1}",port,bute));

                _ports.Remove(port);
            }
            else
            {
                InvokeEventLog(String.Format("初始化失败:{0}", port));

                return null;
            }
            return smsSender;
        }
Пример #5
0
        public void OnSent(SentEventArgs args)
        {
            InvokeEventLog(String.Format("状态:{0}:{1}", args.SmsInfo, args.Result));

            _smsQueue.Set(args.SmsInfo, args.Result ? 500 : 501);

            EventHandler <SentEventArgs> handler = Sent;

            if (handler != null)
            {
                handler(this, args);
            }


            #region 故障处理

            //TODO:16:32 2011-12-07 临时代码 // 重新设置 Modem
            if (args.Result == false)
            {
                //设备重置次数
                const int MAX_RESET = 3;

                string com = args.SmsInfo.Com;
                if (_smsPool.ContainsKey(args.SmsInfo.Com))
                {
                    SMSSender smsSender = _smsPool[args.SmsInfo.Com];
                    if (smsSender.HasError)
                    {
                        int reset = ++smsSender.Reset;
                        if (reset < MAX_RESET)
                        {
                            InvokeEventLog(String.Format("重置:{0}", com));

                            Queue <SMSSendInfo> smsSendInfos = smsSender.Stop();

                            foreach (SMSSendInfo sendInfo in _smsPool[com].Result)
                            {
                                if (sendInfo.State == 1)
                                {
                                    smsSendInfos.Enqueue(sendInfo);
                                }
                            }

                            RemoveModem(com);


                            ////Create
                            smsSender = CreateModem(com, 9600);
                            if (smsSender != null)
                            {
                                foreach (SMSSendInfo sendInfo in smsSendInfos)
                                {
                                    args.SmsInfo.State = 0;
                                    //smsSender.AsyncSend(sendInfo);
                                    AsyncSend(sendInfo);
                                }
                                _smsPool[com].Reset = reset;
                            }
                        }
                        else
                        {
                            //drive has a error .
                            InvokeEventLog(String.Format("设备错误:{0}", com));
                            RemoveModem(com);
                        }
                    }
                }
            }
            //TODO:End

            #endregion
        }