modelEchoPy
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
First example where the microcontroller talks to a partner rather than to itself. Examples.Uart.Loopback sent the frame back to itself through a loopR/loopC network that only existed to work around an alias merge between two pins of the same component. Here the two ends are two distinct components: the link becomes a simple wire in each direction again, and the schematic looks like real wiring.
Both devices must share their ground — as on a real circuit, where connecting only TX and RX is not enough.
The behaviour of the device is described by a Python script (echo.behaviour = Script): Device/echo.py, a one-line function that sends back each received line. Plotting mcu.GP5.v (what the microcontroller transmits) and mcu.GP4.v (what the device sends back) shows that the reply only leaves once the complete line has been received, terminator included, and responseDelay has elapsed: a script only sees whole lines.
Switching echo.behaviour back to Table enables instead the parameterised echo of the component, byte by byte: each byte goes back as soon as it is decoded, with a delay of about one frame, without waiting for the end of the line. The microcontroller program works identically in both cases.
The program sets pin GP7 high if the line read back is identical to the one sent. It is connected to nothing: its voltage is what we observe, a display component would add nothing here.
Components
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Resources/Scripts/MCU/uart_echo.py | |
| MicroPythonMCU.Peripherals.UartEchoDevice | echo | Sends back each received line - behaviour described by Resources/Scripts/Device/echo.py | |
| Modelica.Electrical.Analog.Basic.Ground | ground |