Basic Principles of Serial Data Transmission
2.2.4 Data Transmission with the Printer Driver
The printer driver allows you to output message texts with the date and time to a printer. This enables you to monitor simple processes, print error or fault messages or issue instructions to the operating personnel, for example.
The printer driver contains the physical layer (layer 1).
You use the CP 340: Point-to-Point Communication, Parameter Assignment parameterization interface to configure the message texts and set the parameters (page layout, character set, control characters) for printer output.
Message texts and printer output parameters are transmitted to the CP 340 together with the module parameters when it starts up.
Message texts:
You can configure message texts with variables and control statements (e.g.
for bold, condensed, expanded or italic type and underlining). Each message text is assigned a number during configuration. A message text is printed if its number is specified in a format string when the P_PRINT function block is called.
You must have stored the format string and variables in data blocks beforehand (see Chapter 6).
Page layout:
You can configure the margins, possible line breaks and headers and footers.
Character set:
The ANSI character set is converted to the printer character set by STEP 7 by means of a character conversion table. You can change a character
conversion table suggested for a printer type in order to include special characters required for a particular language, for example.
Control characters:
By means of a control character table you can change the control statements in the message text for the printer emulation for switching on and off bold, condensed, expanded or italic type and underlining and to add control characters.
Up to 4 variables (3 + a message text number) can be displayed in a message text. The values of variables can be transmitted from the CPU to the CP 340.
The following can be displayed as variables: values calculated by the application program (e.g. levels), date and time, strings (string variables) or other message texts.
A conversion statement must be specified in the configured message text or in the format string for each variable, and the meaning and output format of the variable value must be encoded in this statement.
Introduction
Message Texts and Parameters for Printer Output
Variables
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-33
CP 340 Point-to-Point Communication ASE00053578-05
The format string allows you to define the format and composition of a message text. The format string can consist of:
• Text (e.g. The level ... l was reached at ... hours.). All printable characters are permitted.
• Conversion statements for variables (e.g. %N = pointer to message text number x, where x is the value of a variable (see example 2 below)) For each variable there must be one conversion statement in the format string or in the configured message text. The conversion statements are applied to the variables in the sequence in which they occur.
• Control statements with control characters for bold, condensed or italic type and underlining (e.g. \B = bold type on) or with additional control characters you have defined.
You can use additional control characters if you enter them in the control character table of the CP 340: Point-to-Point Communication, Parameter Assignment parameterization interface and reparameterize the CP 340.
You will find all the conversion and control statements that are possible in the format string and in configured message texts in Section 2.3.5.
In addition to outputting message texts, you can use the following functions for printer output. If you want one of these functions to be executed, you specify it in the format string in the same way.
• Set page number (format string = %P)
• Begin new page (form string = \F)
• Print with/without line break (\x at the end of the format string) Please note that a line feed is carried out by default after each output.
Example 1: The level ”200” l was reached at ”17.30” hours.
Format string = The level %i l was reached at %Z hours.
Variable 1 = Time Variable 2 = Level
Example 2: The pressure in the chamber ”is falling”
Format string = %N %S
Variable 1 = 17 (message text no. 17: The pressure in the chamber ...)
Variable 2 = Reference to string (string variable: ... is falling) Example 3: (Set page number to 10)
Format string = %P
Variable 1 = 10 (page number: 10)
Format String
Additional Functions
Examples
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-34 CP 340 Point-to-Point Communication ASE00053578-05
To output n bytes of user data to a printer, you specify the block number of a pointer DB when calling theP_PRINT function block. The pointers to the data blocks are stored in the pointer DB together with the format string and the variables and in a specific order (see Section 6.3.2).
During output the data is edited for printing. The print editing is performed as parameterized by means of the CP 340: Point-to-Point Communication, Parameter Assignment parameterization interface (page layout, character set, control characters, etc.).
Characters are not received during printer output. The exception to this are any flow control characters that have been parameterized. Any characters received are not adopted.
Note
When XON/XOFF flow control is parameterized, the user data must not con-tain the parameterized XON or XOFF characters. The default settings are DC1 = 11H for XON and DC3 = 13H for XOFF.
The figure below illustrates the sequence of operations at printer output.
The message text to be output is specified by the pointers in the poin-ter DB.
Wait for a print job
Print job received
Print editing and output of the
mes-sage text
Job processed
Figure 2-15 Flow Chart of Printer Output Printer Output
Message Text Output
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-35
CP 340 Point-to-Point Communication ASE00053578-05
Handshaking controls the data flow between two communication
partners.Handshaking ensures that data is not lost in transmissions between devices that work at different speeds.
You can also send message texts with data flow control during printer output.
There are essentially two types of handshaking:
• Software handshaking (e.g. XON/XOFF)
• Hardware handshaking (e.g. RTS/CTS)
Data flow control is implemented as follows on the CP 340 during printer output:
• As soon as the CP 340 is switched by parameterization to the operating mode with flow control, it sends the XON character or sets the RTS line to ON.
• If the CP 340 receives the XOFF character, or the CTS control signal is set to OFF, the CP 340 interrupts the output of characters. If neither an XON character is received nor CTS is set to ON before a parameterized time has elapsed, printer output is aborted and an appropriate error message (0708H) is generated at the STATUS output of the PRINT SFB.
Note
When RTS/CTS flow control is parameterized, you must fully wire the inter-face signals in the plug connection (see Appendix B.1).
The CP 340 evaluates the printer’s ”BUSY” control signal. The printer indicates to the CP 340 that it is ready to receive:
• In the case of the CP 340-20mA TTY: by means of current on the RXD line
• In the case of the CP 340-RS 232C and CP 340-RS 422/485: by means of the signal CTS = ”ON”
Note
When you parameterize with RTS/CTS flow control, you must set the pola-rity of the BUSY signal on the printer as follows:
• BUSY signal: CTS = ”OFF”
Please note that some printers use the DTR signal to display the BUSY si-gnal. In such cases you must wire the connecting cable to the CP 340 appro-priately.
Data Flow Control/
Handshaking
BUSY Signal
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-36 CP 340 Point-to-Point Communication ASE00053578-05