Ejemplo n.º 1
0
        protected void SetDataFrame(int id, ATFrame frame)
        {
            ATConnectionState connectionState = this.ipConnectionState[id];

            lock (this.ipConnectionSyncRoot)
            {
                if (this.ipConnectionDataCount < this.ipConnectionDataLength)
                {
                    ATConnectionState previousConnectionState = this.ipConnectionState[this.ipConnectionId];

                    //La connessione con ipConnectionId ha perso dei dati in ricezione.
                    previousConnectionState.ipConnectionDataDiscarded = true;
                    previousConnectionState.ipConnectionDataReady.Set();
                }

                if (connectionState.ipConnectionOpened && !connectionState.ipConnectionDataDiscarded)
                {
                    this.ipConnectionId         = id;
                    this.ipConnectionDataCount  = 0;
                    this.ipConnectionDataLength = frame.DataStream.Length;
                    this.ipConnectionDataStream = frame.DataStream;

                    connectionState.ipConnectionDataReady.Set();
                }
            }
        }
Ejemplo n.º 2
0
        public int GetCallWaitingControl()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CCWA, ATCommandType.Read, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            return(Convert.ToInt32(responseFrame.OutParameters));
        }
Ejemplo n.º 3
0
        public void GetFirmwareVersion()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_GMR, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame, true, 10000);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 4
0
        public void StartUpMultiIPConnection(bool mode)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPMUX, ATCommandType.Write, mode ? "1" : "0");

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 5
0
        public void BringUpWirelessConnection()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIICR, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 6
0
        public override void SetDNSSettings(string primaryIPAddress, string secondaryIPAddress)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CDNSCFG, ATCommandType.Write, String.Concat(primaryIPAddress, ",", secondaryIPAddress));

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 7
0
        public void SetEchoMode(bool mode)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(mode ? ATCommand.ATE1 : ATCommand.ATE0, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 8
0
        public override void Test()
        {
            ATFrame responseFrame = null;
            ATFrame requestFrame  = this.protocol.CreateRequestFrame(ATCommand.AT, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 9
0
        public override void StopListening()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPSERVER, ATCommandType.Write, "0");

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 10
0
        private void JoinWIFIAccessPoint(string ssid, string password)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CWJAP, ATCommandType.Write, String.Concat("\"", ssid, "\",\"", password, "\""));

            responseFrame = (ATFrame)this.protocol.Process(requestFrame, true, 10000);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 11
0
        public void SetWIFIMode(int mode)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CWMODE, ATCommandType.Write, mode.ToString());

            responseFrame = (ATFrame)this.protocol.Process(requestFrame, true, 10000);

            if (responseFrame.Result == "ERROR")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 12
0
        public override void CloseDataConnection()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPSHUT, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result == "ERROR")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 13
0
        public void SetPromptWhenModuleSendsData(int mode)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPSPRT, ATCommandType.Write, mode.ToString());

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 14
0
        private void protocol_FrameReceived(object sender, ATModemFrameEventArgs e)
        {
            ATFrame responseFrame = e.Frame;

            if (responseFrame.Command == ATCommand.CONNECT)
            {
                if (Convert.ToInt32(responseFrame.OutParameters) == this.openingConnectionId)
                {
                    this.connectionEvent.Set();
                }
            }
            else if (responseFrame.Command == ATCommand.CDNSGIP)
            {
                this.dnsQueryParameters = responseFrame.OutParameters;
                this.dnsQueryEvent.Set();
            }
            else if (responseFrame.Command == ATCommand.SEND)
            {
                if (Convert.ToInt32(responseFrame.OutParameters) == this.sendingConnectionId)
                {
                    this.sendResult = responseFrame.Result;
                    this.sendEvent.Set();
                }
            }
            else if (responseFrame.Command == ATCommand.CLOSED)
            {
                lock (connectionSyncRoot)
                {
                    this.OnIPConnectionClosed(Convert.ToInt32(responseFrame.OutParameters));
                }
            }
            else if (responseFrame.Command == ATCommand.NORMAL_POWER_DOWN)
            {
                this.Initialize();
            }
            else if (responseFrame.Command == ATCommand.SEND_PROMPT)
            {
                this.sendPromptEvent.Set();
            }
            else if (responseFrame.Command == ATCommand.IPD)
            {
                this.SetDataFrame(0, responseFrame);
            }
            else if (responseFrame.Command == ATCommand.REMOTE_IP)
            {
                this.OnIPConnectionOpened(Convert.ToInt32(responseFrame.OutParameters), true);
            }
            else if (responseFrame.Command == ATCommand.RECEIVE)
            {
                this.SetDataFrame(Convert.ToInt32(responseFrame.OutParameters), responseFrame);
            }
        }
Ejemplo n.º 15
0
        public override string GetLocalIPAddress()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIFSR, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result == "ERROR")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(responseFrame.OutParameters.Trim('"'));
        }
Ejemplo n.º 16
0
        private void SetAPNSettings(string apn, string username, string password)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CSTT, ATCommandType.Write,
                                                                    (username != null && username.Length > 0 && password != null && password.Length > 0) ?
                                                                    String.Concat("\"", apn, "\",\"", username, "\",\"", password, "\"") : String.Concat("\"", apn, "\""));

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }
        }
Ejemplo n.º 17
0
        private string GetIPConnectionStatus()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPSTATUS, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(responseFrame.OutParameters);
        }
Ejemplo n.º 18
0
        public override string GetIPConnectionStatus(int id)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CIPSTATUS, ATCommandType.Write, id.ToString());

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(responseFrame.OutParameters);
        }
Ejemplo n.º 19
0
        public override string GetSerial()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_GSN, ATCommandType.Execution, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(responseFrame.OutParameters);
        }
Ejemplo n.º 20
0
        public string GetGPRSServiceState()
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CGATT, ATCommandType.Read, null);

            responseFrame = (ATFrame)this.protocol.Process(requestFrame);

            if (responseFrame.Result != "OK")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(responseFrame.OutParameters);
        }
Ejemplo n.º 21
0
        public string QueryDNSIPAddress(string domainName, int timeout)
        {
            ATFrame responseFrame;
            ATFrame requestFrame = this.protocol.CreateRequestFrame(ATCommand.AT_CDNSGIP, ATCommandType.Write,
                                                                    String.Concat("\"" + domainName + "\""));

            string[] dnsParametersTokens = null;
            int      endTimeoutTicks     = 0;

            if (timeout != Timeout.Infinite)
            {
                endTimeoutTicks = Environment.TickCount + timeout;
            }

            do
            {
                this.dnsQueryEvent.Reset();

                responseFrame = (ATFrame)this.protocol.Process(requestFrame);

                if (responseFrame.Result != "OK")
                {
                    throw new ATModemException(ATModemError.Generic);
                }

                if (!this.dnsQueryEvent.WaitOne(timeout, true))
                {
                    throw new ATModemException(ATModemError.Timeout);
                }

                dnsParametersTokens = this.dnsQueryParameters.Split(',');

                if (timeout != Timeout.Infinite)
                {
                    timeout -= endTimeoutTicks - Environment.TickCount;
                }
            }while ((dnsParametersTokens == null || dnsParametersTokens.Length < 1 || dnsParametersTokens[0] != "1") &&
                    (timeout == Timeout.Infinite || timeout > 0));

            if (dnsParametersTokens == null || dnsParametersTokens.Length < 1 || dnsParametersTokens[0] != "1")
            {
                throw new ATModemException(ATModemError.Generic);
            }

            return(dnsParametersTokens[2].Trim('"'));
        }
Ejemplo n.º 22
0
        public IAsyncResult BeginProcess(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback, Object state)
        {
            lock (this.syncRoot)
            {
                lock (this.waitingLock)
                {
                    this.waitingEcho        = this.echoEnabled;
                    this.waitingResponse    = waitResponse;
                    this.waitingTimeout     = Environment.TickCount + timeout;
                    this.waitingCommand     = frame.Command;
                    this.waitingCommandType = frame.CommandType;

                    this.waitingCallback               = callback;
                    this.waitingAsyncResult            = WaitingAsyncResult.GetInstance();
                    this.waitingAsyncResult.AsyncState = state;
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

#if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
#endif


                    return(this.waitingAsyncResult);
                }
                catch
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho     = false;
                        this.waitingResponse = false;
                    }

                    throw new ATModemException(ATModemError.Generic);
                }
            }
        }
Ejemplo n.º 23
0
        private void ReceiverThreadRun()
        {
            try
            {
                while (!this.closed)
                {
                    readBytes = this.stream.Read(this.receivingBuffer, this.receivingBufferIndex + this.receivingBufferCount,
                                                 receivingBufferSize - this.receivingBufferIndex - this.receivingBufferCount);

                    if (readBytes > 0)
                    {
                        this.receivingBufferCount += readBytes;

#if (DEBUG)
                        Debug.Print("ReadBuffer > " + readBytes);
                        Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.receivingBufferIndex, this.receivingBufferCount)));
#endif
                        while (this.receivingBufferCount > 0)
                        {
                            lock (this.waitingLock)
                            {
                                this.parserResult = null;

                                //Verifico se sono in attesa del comando inviato.
                                if (this.waitingEcho)
                                {
                                    //Verifico se è scaduto il timeout di attesa.
                                    if (Environment.TickCount - this.waitingTimeout > 0)
                                    {
                                        this.waitingEcho = false;
                                    }
                                    else
                                    {
                                        //Cerco il comando inviato.
                                        this.frameIndex = ATParser.IndexOfSequence(this.receivingBuffer, this.receivingBufferIndex, this.receivingBufferCount, this.sendingBuffer, 0, this.sendingLength, true);

                                        //Verifico se ho trovato il comando inviato.
                                        if (this.frameIndex != -1)
                                        {
                                            this.waitingEcho = false;
                                            this.waitingEchoEvent.Set();

                                            //Cancello il contenuto del buffer relativo al comando inviato.
                                            movingBytes = this.receivingBufferIndex + this.receivingBufferCount -
                                                          this.frameIndex - this.sendingLength;

                                            if (movingBytes > 0)
                                            {
                                                Array.Copy(this.receivingBuffer, this.receivingBufferIndex + this.receivingBufferCount -
                                                           movingBytes, this.receivingBuffer, this.frameIndex, movingBytes);
                                            }

                                            this.receivingBufferCount -= this.sendingLength;
                                        }
                                    }
                                }

                                //Verifico se sono in attesa di una risposta attesa.
                                if (this.receivingBufferCount > 0 && this.waitingResponse && !this.waitingEcho)
                                {
                                    //Verifico se è scaduto il timeout di attesa.
                                    if (Environment.TickCount - this.waitingTimeout > 0)
                                    {
                                        this.waitingResponse = false;

                                        //Verifico se bisogna invocare una callback.
                                        if (this.waitingCallback != null)
                                        {
                                            this.waitingAsyncResult.AsyncException =
                                                new ATModemException(ATModemError.Timeout);

                                            this.waitingCallback(this.waitingAsyncResult);
                                        }
                                    }
                                    else
                                    {
                                        //Eseguo il parse della risposta attesa.
                                        this.parserResult = this.parser.ParseResponse(this.waitingCommand,
                                                                                      this.waitingCommandType, this.receivingBuffer,
                                                                                      this.receivingBufferIndex, this.receivingBufferCount);

                                        if (this.parserResult != null && parserResult.Success)
                                        {
#if (DEBUG)
                                            Debug.Print("ParserResult.Success > " + this.parserResult.Command);
#endif

                                            this.dataLength = this.parserResult.DataLength;
                                            this.dataStream = this.dataLength > 0 ? ATResponseDataStream.GetInstance(this.dataLength) : null;

                                            //Notifico la ricezione della risposta attesa.
                                            this.waitingResponse = false;
                                            this.waitingFrame    = ATFrame.GetInstance(parserResult.Command, parserResult.CommandType, this.dataStream, parserResult.Unsolicited, parserResult.Result, parserResult.OutParameters);
                                            this.waitingResponseEvent.Set();

                                            //Verifico se bisogna invocare una callback.
                                            if (this.waitingCallback != null)
                                            {
                                                this.waitingCallback(this.waitingAsyncResult);
                                            }
                                        }
                                    }
                                }

                                if (this.receivingBufferCount > 0 && (this.parserResult == null || !parserResult.Success))
                                {
                                    //Eseguo il parse della risposta non attesa.
                                    this.parserResult = this.parser.ParseUnsolicitedResponse(this.receivingBuffer,
                                                                                             this.receivingBufferIndex, this.receivingBufferCount);

                                    if (this.parserResult != null && parserResult.Success)
                                    {
#if (DEBUG)
                                        Debug.Print("ParserUnsolicitedResult.Success > " + this.parserResult.Command);
#endif

                                        this.dataLength = this.parserResult.DataLength;
                                        this.dataStream = this.dataLength > 0 ? ATResponseDataStream.GetInstance(this.dataLength) : null;

                                        //Notifico la ricezione della risposta non attesa.
                                        if (this.FrameReceived != null)
                                        {
                                            this.FrameReceived(this, ATModemFrameEventArgs.GetInstance(ATFrame.GetInstance(parserResult.Command, parserResult.CommandType, this.dataStream, parserResult.Unsolicited, parserResult.Result, parserResult.OutParameters)));
                                        }
                                    }
                                }

                                if (this.parserResult != null && parserResult.Success)
                                {
                                    this.frameIndex  = this.parserResult.Index;
                                    this.frameLength = this.parserResult.Length;

                                    if (this.dataLength > 0)
                                    {
                                        this.dataIndex = this.frameIndex + this.frameLength;
                                        this.dataCount = 0;

                                        this.readDataLength = this.receivingBufferIndex + this.receivingBufferCount - this.dataIndex;

                                        if (this.readDataLength > this.dataLength)
                                        {
                                            this.readDataLength = this.dataLength;
                                        }

                                        if (this.readDataLength > 0)
                                        {
                                            this.dataCount += this.readDataLength;
#if (DEBUG)
                                            Debug.Print("ReadData > " + this.readDataLength + "/" + this.dataCount);
                                            //Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.dataIndex, this.readDataLength)));
#endif

                                            this.dataStream.WriteBuffer(this.receivingBuffer, this.dataIndex, this.readDataLength);
                                        }

                                        //Check if read bytes from the serial port.
                                        if (this.dataCount < this.dataLength)
                                        {
                                            while (this.dataCount < this.dataLength)
                                            {
                                                this.dataTicks = Environment.TickCount;

                                                readBytes = this.stream.Read(this.receivingBuffer, this.frameIndex, receivingBufferSize - this.frameIndex);

                                                this.dataTime = Environment.TickCount - this.dataTicks;

#if (DEBUG)
                                                Debug.Print("ReadDataBuffer > " + readBytes + "/" + this.dataTime);
                                                //Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.frameIndex, readBytes)));
#endif

                                                lock (this.waitingLock)
                                                {
                                                    //Verifico se sono in attesa di una risposta o se è scaduto il data timeout.
                                                    if (this.dataTime > defaultDataTimeout)
                                                    {
                                                        this.dataStream.Close();

                                                        this.readDataLength = 0;

                                                        break;
                                                    }
                                                }

                                                this.readDataLength = this.dataLength - this.dataCount;

                                                if (this.readDataLength > readBytes)
                                                {
                                                    this.readDataLength = readBytes;
                                                }

                                                this.dataCount += this.readDataLength;

#if (DEBUG)
                                                Debug.Print("ReadData > " + this.readDataLength + "/" + this.dataCount);
                                                //Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.frameIndex, this.readDataLength)));
#endif

                                                this.dataStream.WriteBuffer(this.receivingBuffer, this.frameIndex, this.readDataLength);
                                            }

                                            this.receivingBufferCount += (readBytes - this.frameLength);
                                            this.readDataLength       -= this.frameLength;
                                        }
                                    }
                                    else
                                    {
                                        this.readDataLength = 0;
                                    }


                                    //Cancello il contenuto del buffer relativo alla risposta e ai dati.
                                    movingBytes = this.receivingBufferIndex + this.receivingBufferCount -
                                                  this.frameIndex - this.frameLength - this.readDataLength;

                                    if (movingBytes > 0)
                                    {
                                        Array.Copy(this.receivingBuffer, this.receivingBufferIndex + this.receivingBufferCount -
                                                   movingBytes, this.receivingBuffer, this.frameIndex, movingBytes);
                                    }

                                    this.receivingBufferCount -= (this.frameLength + this.readDataLength);
                                }
                                else
                                {
#if (DEBUG)
                                    Debug.Print("ResponseBuffer > " + this.receivingBufferCount);
                                    Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.receivingBufferIndex, this.receivingBufferCount)));
#endif

                                    if (this.receivingBufferCount == receivingBufferSize)
                                    {
                                        //Cancello il contenuto del buffer.
                                        this.receivingBufferIndex = 0;
                                        this.receivingBufferCount = 0;
                                    }

                                    if (!this.waitingResponse)
                                    {
                                        //Cerco il primo delimitatore.
                                        firstDelimiterIndex = this.parser.IndexOfDelimitor(this.receivingBuffer,
                                                                                           this.receivingBufferIndex, this.receivingBufferCount, true);

                                        if (firstDelimiterIndex != -1)
                                        {
                                            secondDelimiterIndex = firstDelimiterIndex + this.parser.LengthOfDelimitor();

                                            //Cerco il secondo delimitatore.
                                            secondDelimiterIndex = this.parser.IndexOfDelimitor(this.receivingBuffer,
                                                                                                secondDelimiterIndex, this.receivingBufferCount +
                                                                                                this.receivingBufferIndex - secondDelimiterIndex, true);

                                            if (secondDelimiterIndex != -1)
                                            {
                                                if (firstDelimiterIndex == this.receivingBufferIndex)
                                                {
                                                    firstDelimiterIndex += this.parser.LengthOfDelimitor();
                                                }

                                                //Cancello il contenuto del buffer fino al primo delimitatore.
                                                this.receivingBufferCount -= (firstDelimiterIndex - this.receivingBufferIndex);
                                                this.receivingBufferIndex  = firstDelimiterIndex;

                                                //Continuo l'elaborazione del buffer.
                                                continue;
                                            }
                                        }
                                    }

                                    //Forzo il caricamento del buffer per evitare cicli infiniti.
                                    break;
                                }
                            }
                        }

                        //Verifico lo stato del buffer.
                        if (this.receivingBufferCount == 0)
                        {
                            this.receivingBufferIndex = 0;
                        }
                        else if (this.receivingBufferIndex + this.receivingBufferCount == receivingBufferSize)
                        {
                            if (this.receivingBufferIndex == 0)
                            {
                                throw new OutOfMemoryException();
                            }

                            Array.Copy(this.receivingBuffer, this.receivingBufferIndex,
                                       this.receivingBuffer, 0, this.receivingBufferCount);

                            this.receivingBufferIndex = 0;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.Print("ExceptionResponseBuffer > " + this.receivingBufferCount);
                Debug.Print(new string(ATParser.Bytes2Chars(this.receivingBuffer, this.receivingBufferIndex, this.receivingBufferCount)));

                exception.ToString();
            }
        }
Ejemplo n.º 24
0
        public ATFrame Process(ATFrame frame, bool waitResponse, int timeout, AsyncCallback callback)
        {
            lock (this.syncRoot)
            {
                if (waitResponse)
                {
                    lock (this.waitingLock)
                    {
                        this.waitingEcho        = this.echoEnabled;
                        this.waitingResponse    = true;
                        this.waitingTimeout     = Environment.TickCount + timeout;
                        this.waitingCommand     = frame.Command;
                        this.waitingCommandType = frame.CommandType;

                        this.waitingCallback = null;

                        this.waitingEchoEvent.Reset();
                        this.waitingResponseEvent.Reset();
                    }
                }

                try
                {
                    this.sendingLength = frame.GetBytes(this.sendingBuffer, 0);

                    this.stream.Write(this.sendingBuffer, 0, this.sendingLength);

#if (DEBUG)
                    Debug.Print("Sent frame > ");
                    Debug.Print(new string(ATParser.Bytes2Chars(this.sendingBuffer, 0, this.sendingLength)));
#endif


                    if (this.waitingEcho && !this.waitingEchoEvent.WaitOne(defaultEchoTimeout, true))
                    {
                        throw new ATModemException(ATModemError.Timeout);
                    }


                    if (!waitResponse)
                    {
                        return(null);
                    }

                    if (this.waitingResponseEvent.WaitOne(timeout, true))
                    {
                        return(this.waitingFrame);
                    }

                    throw new ATModemException(ATModemError.Timeout);
                }
                finally
                {
                    if (waitResponse)
                    {
                        lock (this.waitingLock)
                        {
                            this.waitingEcho     = false;
                            this.waitingResponse = false;
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
 public ATFrame Process(ATFrame frame, bool waitResponse, int timeout)
 {
     return(this.Process(frame, waitResponse, timeout, null));
 }
Ejemplo n.º 26
0
 public ATFrame Process(ATFrame frame, bool waitResponse)
 {
     return(this.Process(frame, waitResponse, defaultProcessTimeout));
 }
Ejemplo n.º 27
0
 public ATFrame Process(ATFrame frame)
 {
     return(this.Process(frame, true, defaultProcessTimeout));
 }
Ejemplo n.º 28
0
 public ATFrame CreateRequestFrame(string command, ATCommandType commandType, string inParameters)
 {
     return(ATFrame.GetInstance(command, commandType, ATRequestDataStream.GetInstance(this), inParameters));
 }
Ejemplo n.º 29
0
 public ATModemFrameEventArgs(ATFrame frame)
 {
     this.frame = frame;
 }
Ejemplo n.º 30
0
 public static ATModemFrameEventArgs GetInstance(ATFrame frame)
 {
     instance.frame = frame;
     return(instance);
 }