proteus 串口资料compim serial port model.doc

Upload: telefonare

Post on 18-Oct-2015

141 views

Category:

Documents


3 download

TRANSCRIPT

COMPIM Serial Port Model

COMPIM Serial Port ModelIntroduction

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

The COMPIM model supports the following properties:

NamePropertyDefaultDescription

Physical portP_PORTCOM1Specifies which physical serial device the model is to connect to.

Physical Baud RateP_BAUDRATE9600Specified the baud rate the physical port should be set at. The bounds for this are 50 to 1000000 baud, though your hardware may place additional limits on the permitted values.

Physical Data BitsP_DATABITS8Specifies the number of data bits used on the physical port. 7 and 8 data bits are presently supported.

Physical ParityP_PARITYNONESpecifies the parity used on the physical port. This can be NONE, ODD, EVEN, MARK and SPACE.

Physical Stop BitsP_STOPBITS1Specifies the number of stop bits used on the physical port. 1 and 2 stop bits are presently supported.

Physical XON/XOFF flow controlP_SOFTFLOW0Specifies if XON/OFF flow control is to be used on the physical serial port.

Physical RTS/CTS flow controlP_HARDFLOW0Specifies if hardware RTS/CTS flow control handshaking is to be used on the physical serial port.

Physical XON characterP_XONCHAR17Specifies the XON character used on the physical interface.

Physical XOFF characterP_XOFFCHAR19Specifies the XOFF character used on the physical interface.

Virtual Baud RateV_BAUDRATE9600Specifies the baud rate of the virtual port. The bounds for this value are from 50 to 1000000 baud.

Virtual Data BitsV_DATABITS8Specifies the number of data bits on the virtual port. 7 and 8 data bits are presently supported.

Virtual ParityV_PARITYNONESpecifies the parity used on the virtual serial port. This value can be NONE, ODD, EVEN, MARK and SPACE.

Virtual Stop BitsV_STOPBITS1Specifies the number of stop bits on the virtual serial port. 1 and 2 stop bits are presently supported.

Virtual XON/XOFF flow controlV_SOFTSLOW0Specifies if XON/XOFF flow control is used on the virtual serial port.

Virtual RTS/CTS flow controlV_HARDFLOW0Specifies that hardware RTS/CTS handshaking is to be used on the virtual port.

Virtual XON characterV_XONCHAR17Specifies the XON character used the virtual interface.

Virtual XOFF characterV_XOFFCHAR19Specifies the XOFF character used on the virtual interface,

Size of data input bufferINPUT_BUFFER_SIZE65536Indicates the upper bound on the size of the serial input buffer, from physical interface to virtual interface, in bytes. The minimum being 1, the maximum 4194304.

Size of data output bufferOUTPUT_BUFFER_SIZE65536Indicates the upper bound on the size of the serial output buffer, from virtual interface to physical interface, in bytes. The minimum being 1, the maximum 4194304.

Additional notes

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.