Serial Port Model
Serial Port Model
Introduction
Traditionally, simulation systems have had no direct connection to the physical world around
them. This meant that if you wanted to simulate part of a much bigger system of interconnected
units, one had to either create simulations of the other units, or create files containing test data.
The Virtual System Modelling capabilities of Proteus VSM allow the creation of models that can
actually interact with the physical world. We call such models Physical Interface Models or PIMs
for short.
The COMPIM model is a Physical Interface Model of a serial port. Incoming serial data is
buffered and presented to the circuit as a digital signal, whilst serial digital data generated by a
CPU or UART model appears at the PC's physical COM port. The COMPIM model also provides
for baud rate translation, and for optional hardware or software handshaking on both the physical
and virtual sides of the device.
This allows any real world hardware equipped with a serial port to interact with a VSM
simulation. For example, you could use it to develop a program for a microprocessor within
Proteus VSM that would operate a real physical modem, perhaps as part of a security or home
automation system. Alternatively, a monitor debugger running on one PC can be used to debug a
simulated design running within VSM.
The COMPIM model can also be used for some simple digital I/O: the CTS, DSR, DCD and RI
lines on the physical serial port can act as rudimentary digital inputs from external stimulus, such
as switches; the RTS and DTR lines on the physical serial port can act as rudimentary outputs.
Bear in mind that these signals may need addition physical signal conditioning, depending on
application and port type.
Device Layout
COMPIM has eight pins: TXD, RXD, CTS, RTS, DSR, DTR, DCD and RI.
TXD, RTS and DTR are inputs to the device and become outputs on the physical port.
RXD, CTS, DSR, DCD and RI are inputs from the physical port that become outputs on the
device.
This means that the COMPIM represents a DCE on the schematic. By contrast, the VTERM
model (being a terminal) is wired as a DTE. The physical COM port itself is wired as a DTE
(TXD is an output).
When a simulation is initiated, the terminals of the DB-9 connector inside the COMPIM device
symbol become indicators. The TXD and RXD terminalss indicate activity on the corresponding
physical port pins. The indicators for CTS, RTS, DSR, DTR, DCD and RI show the state of the
physical port pins.
Two further square indicators are present, either side of the word 'ERROR'. These indicators show
red whenever an error is detected on either the virtual port or the physical port. The indicator
nearest the pins flags an error on the virtual port. The indicator under the DB-9 terminals flags that
an error occurred on the physical port. The errors indicated include framing and parity errors. The
simulation log window may give more information as to the nature of the error.
Handshaking Modes
Flow control signals, if active, do not directly pass through from the physical to virtual port, or
vice versa, they instead interact with high and low thresholds on the data buffers that are in
COMPIM and the operating system. This means that although flow control may be accepting or
blocking data at one physical/virtual port, the other virtual/physical port may not necessarily
propagate this state, unless the buffers become close to overflowing or under flowing.
Put another way, if either Physical or Virtual hardware handshaking is enabled, the RTS input pin
of the COMPIM will cease to have any direct effect on the RTS line of the COM port. This
behaviour is correct and by design.
Buffering
The COMPIM model provides buffering for both incoming and outgoing data. As well as covering
the situation where the VSM simulation fails to keep up with real time, the input buffering works
even when the simulation is paused. This feature can be remarkably useful since the VSM
debugging tools may be used to single step the processing of the data long after the physical
hardware device attached to the COM port actually transmitted it.
The output buffering is most relevant where the baud rate in the virtual circuit exceeds that being
used to communicate with the physical device.
Properties
A known problem with Windows 95/98/ME serial port API behaviour causes incorrect ring
indicator operation. This appears to manifest itself as the ring indicator line correctly performing a
low to high transition but never performing the high to low transition, consequently the RI line
gets stuck high until the simulation is stopped.
No matter what the values of INPUT_BUFFER_SIZE and OUTPUT_BUFFER_SIZE the
operating system and hardware carries out some limited buffering.
Limitations in the way the Win32 serial port API reports a line break condition mean that
COMPIM has to infer the end of a line break by other activity occurring on the physical serial
port. This means that a line break condition may continue to be active on the virtual port after the
condition has been removed from the physical port.
The indicators on the COMPIM device try to reflect the state of the physical port, however, the
operating system and hardware perform some buffering before COMPIM.DLL has a chance to
examine the data, which means the indication may possibly lag the true state of the physical port.