예제 #1
0
        private void ConnectModemCommandExecute(ModemConfigInfo modemInfo)
        {
            if (Project.SmsModule != null && Project.SmsModule.StartupCommands != null && !String.IsNullOrEmpty(Project.SmsModule.StartupCommands))
            {
                string[] commands = Project.SmsModule.StartupCommands.Split('\n');
                foreach (string command in commands)
                {
                    modemInfo.StartupCommands.Add(command);
                }
            }

            // save the most recent settings to the server's config for faster re-use later
            Properties.Settings.Default.LastUsedBaudRate = int.Parse(modemInfo.BaudRate);
            Properties.Settings.Default.LastUsedComPort  = modemInfo.ComPort;
            Properties.Settings.Default.Save();

            try
            {
                SmsController      = new SmsController(modemInfo, Project.SmsModule.PollRate);
                IsConnectedToModem = true;

                AddStatusMessage(String.Format("Connected to modem on {0}", modemInfo.ComPort), "Server");

                SmsController.SmsReceived += SmsController_SmsReceived;
            }
            catch (Exception ex)
            {
                ShowErrorBoxCommand.Execute(String.Format("Could not connect to the modem. Exception: {0}", ex.Message));
                IsConnectedToModem = false;
            }
        }
예제 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="modemInfo">Configuration information for the Sms modem</param>
        /// <param name="pollRate">The rate at which to check the modem for incoming SMS messages in milliseconds</param>
        public SmsController(ModemConfigInfo modemInfo, int pollRate)
        {
            ModemConfiguration = modemInfo;

            OpenPort();

            ExecuteStartupCommands();

            SmsMessages          = new Queue <ShortMessage>();
            UpdateTimer          = new System.Timers.Timer(pollRate); // 6 seconds
            UpdateTimer.Elapsed += UpdateTimer_Elapsed;
            UpdateTimer.Start();
        }