예제 #1
0
        private void EndReceiveInput(IAsyncResult ar)
        {
            ReceiveInputState state = (ReceiveInputState)ar.AsyncState;

            try
            {
                int bytesRead = state.Stream.EndRead(ar);

                if (bytesRead > 0)
                {
                    m_lastActivity = DateTime.UtcNow;
                    m_inboundData.Write(state.Buffer, 0, bytesRead);
                }

                BeginReceiveInput(state);
            }
            catch (ProcessExitException)
            {
                ProcessExit();

                ((IController)this).ClosePort();

                return;
            }
            catch (InvalidOperationException)
            {
                if (state.InvalidOperationRetry <= 0)
                {
                    ProcessExit();

                    ((IController)this).ClosePort();
                }
                else
                {
                    state.InvalidOperationRetry--;

                    ((IController)this).ClosePort();

                    Thread.Sleep(200);
                }
            }
            catch (IOException)
            {
                ((IController)this).ClosePort();

                Thread.Sleep(200);
            }
            catch
            {
                ((IController)this).ClosePort();

                Thread.Sleep(200);
            }
        }
예제 #2
0
        private void BeginReceiveInput(ReceiveInputState state)
        {
            try
            {
                state.Stream.BeginRead(state.Buffer, 0, state.Buffer.Length, EndReceiveInput, state);
            }
            catch (IOException)
            {
                ProcessExit();

                ((IController)this).ClosePort();
            }
        }
예제 #3
0
        private void ReceiveInput()
        {
            int invalidOperationRetry = 5;

            byte[] buf = new byte[128];

            try
            {
                if (m_state.IsRunning)
                {
                    Stream stream = ((IControllerLocal)this).OpenPort();

                    if (!m_asynchronousProcessing)
                    {
                        ReceiveSynchronous(buf, invalidOperationRetry);
                    }
                    else
                    {
                        ReceiveInputState state = new ReceiveInputState
                        {
                            Buffer = buf,
                            Stream = stream,
                            InvalidOperationRetry = invalidOperationRetry
                        };

                        BeginReceiveInput(state);
                    }
                }
            }
            catch (InvalidOperationException)
            {
                ProcessExit();

                ((IController)this).ClosePort();
            }
        }