Beispiel #1
0
 public void WaitForCall()
 {
     try
     {
         if (!this.IsOpen)
         {
             this.Open();
         }
         if (!this.IsOpen)
         {
             throw new Exception("Cannot open com port");
         }
         // Force the DTR line high, used sometimes to hang up modems
         this.DtrEnable = true;
         this.RtsEnable = true;
         // Trigger the OnComm event whenever data is received
         this.ReceivedBytesThreshold = 1;
         //
         _status = EnumModemStatus.WaitCaller_Reset;
         this.Write("\rATZ\r");
     }
     catch (Exception e)
     {
         if (this.OperationError != null)
         {
             _error = e.Message;
             OperationError(this, EventArgs.Empty);
         }
         this.DtrEnable = false;
         this.RtsEnable = false;
     }
 }
Beispiel #2
0
 public void TestBySimulation(string messageFeedFile)
 {
     if (string.IsNullOrEmpty(messageFeedFile))
     {
         if (OperationError != null)
         {
             _error = "message feed file not provided";
             OperationError(this, EventArgs.Empty);
         }
     }
     else if (!File.Exists(messageFeedFile))
     {
         if (OperationError != null)
         {
             _error = "message feed file does not exist";
             OperationError(this, EventArgs.Empty);
         }
     }
     else
     {
         try
         {
             _status  = EnumModemStatus.WaitCaller_Reset;
             _testing = true;
             StreamReader sr = new StreamReader(messageFeedFile);
             while (!sr.EndOfStream)
             {
                 _testSignal = string.Format(CultureInfo.InvariantCulture, "{0}\r", sr.ReadLine());
                 if (!string.IsNullOrEmpty(_testSignal))
                 {
                     processMessage();
                 }
             }
             sr.Close();
         }
         catch (Exception err)
         {
             _error = err.Message;
             OperationError(this, EventArgs.Empty);
         }
         _testing = false;
     }
 }
Beispiel #3
0
 private void processEvent()
 {
     if (_signal.Length > 0)
     {
         string cmd = _signal.ToString();
         if (cmd.StartsWith("OK", StringComparison.Ordinal))
         {
             _signal.Length = 0;
             cmd            = cmd.Substring(2);
             _signal.Append(cmd);
             if (OK != null)
             {
                 OK(this, EventArgs.Empty);
             }
             if (_status == EnumModemStatus.WaitCaller_Reset)
             {
                 _status = EnumModemStatus.WaitCaller_EnableCallerID;
                 if (!_testing)
                 {
                     this.Write(this.CallerIDCommand + "\r");
                 }
             }
             else if (_status == EnumModemStatus.WaitCaller_EnableCallerID)
             {
                 _status = EnumModemStatus.WaitCaller_Wait;
             }
         }
         else if (cmd.StartsWith("ERROR", StringComparison.Ordinal))
         {
             _signal.Length = 0;
             cmd            = cmd.Substring(5);
             _signal.Append(cmd);
             _status = EnumModemStatus.WaitCaller_Error;
             if (OperationError != null)
             {
                 OperationError(this, EventArgs.Empty);
             }
         }
         else if (cmd.StartsWith("RING", StringComparison.Ordinal))
         {
             _signal.Length = 0;
             cmd            = cmd.Substring(4);
             _signal.Append(cmd);
             if (Ring != null)
             {
                 Ring(this, EventArgs.Empty);
             }
         }
         else
         {
             if (_status == EnumModemStatus.WaitCaller_Wait)
             {
                 if (cmd.Length > 7)
                 {
                     if (cmd.StartsWith("NMBR", StringComparison.Ordinal))
                     {
                         _callerId      = cmd.Substring(7).Trim();
                         _signal.Length = 0;
                         if (GotCallerID != null)
                         {
                             GotCallerID(this, EventArgs.Empty);
                             _status = EnumModemStatus.WaitCaller_GotCallerId;
                         }
                     }
                 }
             }
             else
             {
                 if (cmd.Length > 0)
                 {
                     checkWatchSignals(cmd);
                 }
             }
         }
     }
 }