public virtual void Input(object sender, out byte[] inData, int length) { if (!IsInitialized) { throw new Exception(); } IOmonitor.IdleWhile(() => !IsReadyToInput); string uniStrData = null; ConsoleForm?.Input(sender, out uniStrData, length); if (uniStrData == null) { inData = new byte[0]; return; } byte[] uniBytes = Encoding.Unicode.GetBytes(uniStrData); if (_CharSet == Encoding.Unicode) { inData = uniBytes; } else { inData = Encoding.Convert(Encoding.Unicode, _CharSet, uniBytes); } }
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); } } }
public virtual void Output(object sender, byte[] outData) { if (!IsInitialized) { throw new Exception(); } IOmonitor.IdleWhile(() => !IsReadyToOutput); byte[] uniBytes; if (_CharSet == Encoding.Unicode) { uniBytes = outData; } else { uniBytes = Encoding.Convert(_CharSet, Encoding.Unicode, outData); } ConsoleForm?.Output(sender, Encoding.Unicode.GetString(uniBytes)); }