XOn/XOff flow control
Posted: Wed Aug 17, 2022 6:47 am
https://en.wikipedia.org/wiki/Software_flow_control
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/
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));
}
}
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/