public StdOutputPort()
        {
            _BackgroundOutputAction = () =>
            {
                bool locked        = false;
                bool __outBuffDone = false;
                Thread.CurrentThread.Name = $"  machine~{ParentIDE.Machine.Id}.outputPort~{this.Id} Buffer Thread";
                //Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
                while (!__outBuffDone)
                {
                    while (!(_OutputDevice != null && _OutputDevice.IsInitialized))
                    {
                        Thread.Yield();
                    }

                    lock (_OutputDevice.Locking)
                        if (_OutputDevice.IsReadyToOutput)
                        {
                            lock (_OutputBuffer)
                            {
                                _OutputDevice.Output(this, _OutputBuffer.ToArray());
                                _OutputBuffer.Clear();
                                _BackgroundOutputTask = null;
                                __outBuffDone         = true;
                            }
                        }
                }
            };
        }
Beispiel #2
0
        protected virtual void DirectInput(out byte[] inData, int length)
        {
            bool locked = false;

            try
            {
                if ((InputDeviceThreadSafe.Initialize & _InputDeviceIsThreadSafeFor) == 0)
                {
                    IOmonitor.IdleForLock(_InputDevice, out locked);
                    if (!_InputDevice.IsInitialized)
                    {
                        _InputDevice.Initialize(this);
                    }
                }
                else
                if (!_InputDevice.IsInitialized)
                {
                    _InputDevice.Initialize(this);
                }

                if (!locked && (InputDeviceThreadSafe.Input & _InputDeviceIsThreadSafeFor) == 0)
                {
                    IOmonitor.IdleForLock(_InputDevice, out locked);
                }
                {
                    IOmonitor.IdleWhile(() => !_InputDevice.IsReadyToInput);
                    IOutputDevice ioDevice = _InputDevice as IOutputDevice;
                    if (ioDevice != null)
                    {
                        if (ioDevice.IsReadyToOutput && _bInputForeword != null)
                        {
                            ioDevice.Output(this, _bInputForeword);
                        }

                        _InputDevice.Input(this, out inData, length);

                        if (ioDevice.IsReadyToOutput && _bInputAfterword != null)
                        {
                            ioDevice.Output(this, _bInputAfterword);
                        }
                    }
                    else
                    {
                        _InputDevice.Input(this, out inData, length);
                    }
                }
            }
            finally
            {
                if (locked)
                {
                    IOmonitor.Unlock(_InputDevice);
                }
            }
        }