Command Echoing
For maximum compatibility with software expecting a Python interface, the Ferrum serial interface implements command echoing, as well as an input prompt.
This does not apply to the Legacy API. No command echoing occurs when directly connecting with the Ferrum board.
This means that when a command is sent to Ferrum, it will repeat the command back, followed by the \r\n
line terminator, then send the result of the command, and then send the input prompt (>>> ).
Note that the input prompt is exactly three right facing arrows, followed by a single space, and no line terminator.
Examples
Note these examples use raw data, meaning \r is not a backslash and an r, but instead the carriage return character.
If you don’t understand what this means, try asking ChatGPT, or Googling it.
Using \r\n
Input:
km.left()\r\n
Output:
km.left()\r\n
1\r\n
>>> # Note this line is `>>> ` with a single space.
Using \n
Input:
km.left()\n
Output:
km.left()\r\n # Even though \n was sent, \r\n is echoed back
1\r\n
>>> # Note this line is `>>> ` with a single space.
A Command with No Response
Input:
km.left(1)\r
Output:
km.left(1)\r\n
>>> # Note this line is `>>> ` with a single space.
Disabling Echoing
The km.echo command is used to enable and disable command echoing and the input prompt.
Sending the command with no arguments will return whether echoing is enabled (1) or disabled (0).
Sending the command with one argument will either enable (1) echoing, or disable (0) it.
When echoing is disabled, neither the command nor the input prompt is sent back. Only the result of the command
(followed by \r\n) is sent, and commands with no result send nothing at all. This makes responses easier to parse.
Echoing is enabled by default, and is re-enabled whenever the serial port is closed.
Note: callbacks such as the Key State Change Callback always end with the input prompt, even when echoing is disabled.
Disabling Echoing, then Reading a Button
Input:
km.echo(0)
km.left()
Output:
# km.echo(0) takes effect immediately, so nothing is sent back for it.
1 # Only the result of km.left() is sent.
Reading the Echo State
Input:
km.echo()
Output:
km.echo()
1 # Echoing is enabled.
>>>