예제 #1
0
        public ATFrame EndProcess(IAsyncResult asyncResult)
        {
            WaitingAsyncResult waitingAsyncResult = (WaitingAsyncResult)asyncResult;

            if (waitingAsyncResult.AsyncException != null)
            {
                throw waitingAsyncResult.AsyncException;
            }

            return((ATFrame)waitingAsyncResult.AsyncFrame);
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
파일: ATProtocol.cs 프로젝트: cins/ATModem
        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);
                }
            }
        }