Пример #1
0
 /// <summary>
 /// simple test of dialing functionality
 /// </summary>
 static void Test1() 
 {
     try
     {
         SerialPort port = new SerialPort(Config.PortName, Config.BaudRate,
             Config.Parity, Config.DataBits, Config.StopBits);
         port.Open();
         Modem m = new Modem(port);
         ATResponseCode code = m.Dial(Config.DialNumber);
         if (code == ATResponseCode.AT_OK)
         {
             code = m.Dial(Config.DialData);
         }
         port.Close();
         Console.WriteLine("response: {0}", code);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #2
0
        /// <summary>
        /// full program with diagnostics output
        /// </summary>
        static void Test2()
        {
            try
            {
                Schedule s1 = new Schedule(Config.Schedule1_StartTime, Config.RandomDelay_s,
                  new TimeSpan(0, Config.RetryInterval_min, 0), Config.MaxRetry, 1);
                Schedule s2 = new Schedule(Config.Schedule2_StartTime, Config.RandomDelay_s,
                  new TimeSpan(0, Config.RetryInterval_min, 0), Config.MaxRetry, 2);

                SerialPort port = new SerialPort(Config.PortName, Config.BaudRate,
                    Config.Parity, Config.DataBits, Config.StopBits);
                port.Open();
                Modem m = new Modem(port);
                ATResponseCode code;
                string logMsg;
                while (true)
                {
                    if (s1.CheckSchedule())
                    {
                        code = m.Dial(Config.DialNumber);
                        logMsg = string.Format("Dialing response: {0}", code); 
                        MessageLog.LogMessage(logMsg, MessageLog.LogEntryType.Information);
                        if (code != ATResponseCode.AT_OK)
                        {
                            //report failure
                            s1.CompleteTask(false);
                        }
                        else
                        {
                            code = m.Dial(Config.DialData);
                            logMsg = string.Format("Send data response: {0}", code);
                            MessageLog.LogMessage(logMsg, MessageLog.LogEntryType.Information);
                            s1.CompleteTask(true);
                        }
                    }
                    else if (s2.CheckSchedule())
                    {
                        code = m.Dial(Config.DialNumber);
                        logMsg = string.Format("Dialing response: {0}", code);
                        MessageLog.LogMessage(logMsg, MessageLog.LogEntryType.Information);
                        if (code != ATResponseCode.AT_OK)
                        {
                            //report failure
                            s2.CompleteTask(false);
                        }
                        else
                        {
                            code = m.Dial(Config.DialData);
                            logMsg = string.Format("Send data response: {0}", code);
                            MessageLog.LogMessage(logMsg, MessageLog.LogEntryType.Information);
                            s2.CompleteTask(true);
                        }
                    }
                    else
                    { 
                        //idle, yield
                        Thread.Sleep(30000);
                    }
                }
                //never here
                port.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                MessageLog.LogException(e);
            }
        }