modelPartialUartDevice

Base of the external serial devices: electrical link, decoding, two transmission modes, quantities exchanged with the model

Extends from PartialUartPins (Electrical side of a serial device: TX output and RX input on two pins, common ground, optional VCC pin - shared by the serial devices and the radio modems).

Information

Base class of the external serial devices. It cannot be instantiated directly: a concrete device extends it and sets its parameters — see Peripherals.UartEchoDevice, UartTemperatureSensor, UartGpsModule, UartLcd20x2, or Peripherals.UartGenericDevice for a device entirely described by its parameters.

The device is connected electrically to two GPx pins of an MCU: it receives real frames and transmits real ones, at its own baud rate and in its own format (dataBits, parity, stopBits: 8N1 by default, same choices as machine.UART). A baud rate or format mismatch with the microcontroller therefore produces wrong bytes, as on a real circuit; a received byte with a wrong parity bit or a low stop bit is kept, with a warning in the log (the first ten, then a total at the end of the simulation).

Two transmission modes, which can be combined, feeding the same queue:

  • Request / response: the received bytes accumulate up to terminator, the complete line is matched against commandTable, and the reply leaves after responseDelay.
  • Periodic: periodicTemplate is transmitted spontaneously every period seconds, without being asked.

Quantities exchanged with the rest of the model. {v1}…{vN} insert valueIn into a transmitted frame (with an optional precision, {v1:.1f}); {o1}…{oN}, placed in a command, capture a number of the received frame into valueOut. The same device can therefore be both sensor and actuator, which lets a control loop be closed inside the model.

The two dots of the icon light up during a transmitted frame (amber) or a received one (cyan) — visible while replaying a result with animation in OMEdit, not on a static rendering. Each received line and each transmitted payload also produce a line in the simulation log, prefixed with the component name.

Parameters

TypeNameDefaultDescription
Electrical › Supply
BooleanuseSupplyPin (from PartialSupplyPin)falseShow the VCC supply pin: the peripheral is supplied by the circuit (its high levels follow VCC, its consumption IQ is drawn from VCC) - unchecked: ideal internal supply VOH, nothing to wire
Modelica.Units.SI.VoltageVOH (from PartialSupplyPin)Interfaces.VOHLogic high voltage: ideal internal supply, high level of the outputs and of the pull-ups - with the VCC pin, the voltage of VCC is used instead
Modelica.Units.SI.CurrentIQ (from PartialSupplyPin)1e-3Current drawn from VCC by the peripheral (quiescent consumption, outputs excluded)
BooleanuseGroundPin (from PartialSupplyPin)trueShow the GND pin - unchecked: the peripheral is referenced to the simulation ground (0 V), nothing to wire
Electrical › Levels
Modelica.Units.SI.VoltageVOL (from PartialUartPins)Interfaces.VOLLogic low voltage
Modelica.Units.SI.VoltageVIH (from PartialUartPins)Interfaces.VIHThreshold above which an input reads high
Modelica.Units.SI.VoltageVIL (from PartialUartPins)Interfaces.VILThreshold below which an input reads low
Electrical › Impedances
Modelica.Units.SI.ResistanceROut (from PartialUartPins)Interfaces.ROutOutput series resistance
Modelica.Units.SI.ResistanceRPullUp (from PartialUartPins)1e6Pull-up of the RX input to the supply
Electrical › Pins
BooleanuseTxPin (from PartialUartPins)trueShow the TX pin - unchecked for a device that never transmits (its output stage then stays unconnected)
Behaviour
Interfaces.UartBehaviourbehaviourInterfaces.UartBehaviour.TableOrigin of the behaviour: command table or Python script
StringscriptPath""Script .py describing the behaviour of the device (Script mode)
Serial link
Integerbaudrate1200Link speed, in baud
IntegerdataBits8Number of data bits of a frame (5 to 8, as machine.UART bits=)
Interfaces.UartParityparityInterfaces.UartParity.NoneParity of a frame (as machine.UART parity=: None, 0 = even, 1 = odd)
IntegerstopBits1Number of stop bits (1 or 2, as machine.UART stop=)
Stringterminator"\n"Character marking the end of a received command (only the first character is kept)
Simulation
Modelica.Units.SI.TimetickPeriod0.1Period of the minimal sync point: a safety net, the actual pace comes from the engine's deadlines
Table › Request / response
BooleanrespondEnabledtrueReply to the recognised commands
StringcommandTable""Table "CMD=>REPLY|CMD=>REPLY"; "|" and "=>" are reserved. {vN} inserts valueIn[N] into the reply, {oN} captures a number of the command into valueOut[N]
Modelica.Units.SI.TimeresponseDelay0.002Delay between the recognition of a command and the start of the reply
BooleanechoEnabledfalseSend back every received byte unchanged
Table › Periodic transmission
BooleanperiodicEnabledfalseTransmit spontaneously, without being asked
Modelica.Units.SI.Timeperiod1Period of the spontaneous transmission (in Script mode: call period of on_tick)
StringperiodicTemplate""Template of the periodically transmitted frame ({vN} inserts valueIn[N])
Inputs / outputs › Inputs ({vN}, inserted into transmitted frames)
BooleanuseValueInputfalseTake the quantities from the valueIn connector rather than from a constant
IntegernIn1Number of quantities received from the model
RealfixedValue0Value used when valueIn is not connected
Inputs / outputs › Outputs ({oN}, captured from received frames)
BooleanuseValueOutputtrueShow the valueOut connector - unchecked for a device that returns nothing to the model
IntegernOut1Number of quantities returned to the model - leave the connector unconnected if unused
RealvalueOutStart0Value of valueOut before any capture

Connectors

TypeNameDefaultDescription
Modelica.Electrical.Analog.Interfaces.NegativePinGND (from PartialSupplyPin)Common reference (ground), to be connected to the microcontroller's one - shown when useGroundPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinVCC (from PartialSupplyPin)Supply of the peripheral (e.g. 3V3(OUT) of a Raspberry Pi Pico) - shown when useSupplyPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinTX (from PartialUartPins)Transmission of the device - to be connected to the receive pin of the microcontroller - shown when useTxPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinRX (from PartialUartPins)Reception of the device - to be connected to the transmit pin of the microcontroller
Modelica.Blocks.Interfaces.RealInput[nIn]valueInQuantities supplied by the model, inserted into the transmitted frames by {v1}..{vN}
Modelica.Blocks.Interfaces.RealOutput[nOut]valueOutQuantities extracted from the received frames by {o1}..{oN} - the device then becomes an actuator

Components

TypeNameDefaultDescription
BooleantxActiveA frame is being transmitted
BooleanrxBusyA frame is being received
StringlastRxLast complete line received
StringlastTxLast payload transmitted