@Override
	public NfcMessage write(NfcMessage input) throws IOException {
		if (!isEnabled()) {
			if (Config.DEBUG)
				Log.d(TAG, "could not write message, reader is not enabled");
			
			eventHandler.handleMessage(NfcEvent.FATAL_ERROR, NFCTRANSCEIVER_NOT_CONNECTED);
			return new NfcMessage(Type.ERROR).sequenceNumber(input);
		}

		if (!reader.isOpened()) {
			if (Config.DEBUG)
				Log.d(TAG, "could not write message, reader is not or no longe open");
			
			eventHandler.handleMessage(NfcEvent.FATAL_ERROR, NFCTRANSCEIVER_NOT_CONNECTED);
			return new NfcMessage(Type.ERROR).sequenceNumber(input);
		}

		final byte[] bytes = input.bytes();
		if (bytes.length > MAX_WRITE_LENGTH) {
			throw new IllegalArgumentException("The message length exceeds the maximum capacity of " + MAX_WRITE_LENGTH + " bytes.");
		}

		final byte[] recvBuffer = new byte[MAX_WRITE_LENGTH];
		final int length;
		try {
			length = reader.transmit(0, bytes, bytes.length, recvBuffer, recvBuffer.length);
		} catch (ReaderException e) {
			if (Config.DEBUG)
				Log.e(TAG, "could not write message - ReaderException", e);
			
			eventHandler.handleMessage(NfcEvent.FATAL_ERROR, UNEXPECTED_ERROR);
			return new NfcMessage(Type.ERROR).sequenceNumber(input);
		}

		if (length <= 0) {
			if (Config.DEBUG)
				Log.d(TAG, "could not write message - return value is 0");
			
			eventHandler.handleMessage(NfcEvent.FATAL_ERROR, UNEXPECTED_ERROR);
			return new NfcMessage(Type.ERROR).sequenceNumber(input);
		}

		byte[] result = new byte[length];
		System.arraycopy(recvBuffer, 0, result, 0, length);
		return new NfcMessage(result);
	}