Page 1 of 1

XOn/XOff flow control

Posted: Wed Aug 17, 2022 6:47 am
by ag123
https://en.wikipedia.org/wiki/Software_flow_control

Code: Select all

#include <Arduino.h>

enum State {
	XOff = 0,
	XOn
};

State state;

void setup(){
	state = State::XOff;
	pinMode(PA0, INPUT_ANALOG);
};

void loop() {
	// this part is the command processor
	if(Serial.available()) {
		int c = Serial.read();
		switch(c) {
			case 17: // Ctrl Q
				state = State::XOn;
				break;
			case 19: // Ctrl S
				state = State::XOff;
				break;
		}

	}
	if (state == State::XOn) {
		Serial.println(analogRead(PA0));
	}
}
This is only on the device side, doesn't handle receive from host side
non ideal but simple to implement, requires "escaping" ctrl-Q, ctrl-S for some implementations.
for 'one way' implementations (e.g. only the device respond to commands), this probably 'just works'
the benefit is this can be tested out in most ordinary serial terminals apps, e.g. https://www.putty.org/