write-byte

xod/uart/write-byte

Writes a single byte in the UART. Possible errors: — No bytes written. Probably due to buffer overflow
write-byte
@/write-byte
Writes a single byte in the UART. Possible errors: — No bytes written. Probably due to buffer overflow
UART@/uart
An UART object
BYTEbyte
Byte to write
SENDpulse
Trigger writting of the byte
write-byte
UART
BYTE
SEND
DONE
DONEpulse
Pulses when byte was successfully written

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_SEND
#pragma XOD error_raise enable

node {
    void evaluate(Context ctx) {
        if (!isInputDirty<input_SEND>(ctx))
            return;

        auto uart = getValue<input_UART>(ctx);
        uint8_t byte = getValue<input_BYTE>(ctx);
        bool res = uart->writeByte(byte);
        if (res) {
            emitValue<output_DONE>(ctx, 1);
        } else {
            raiseError(ctx); // No bytes written
        }
    }
}