Basic Principles of Serial Data Transmission
2.2.3 Data Transmission with the ASCII Driver
The ASCII driver controls data transmission via a point-to-point connection between the CP 340 and a communication partner. This driver contains the physical layer (layer 1 of the ISO reference model.)
The structure of the message frames is left open through the S7 user passing on the complete send message frame to the CP 340. For the receive direction, the end criterion of a message must be parameterized. The structure of the send message frames may differ from that of the receive message frames.
The ASCII driver allows data of any structure (all printable ASCII characters as well as all other characters from 00 through FFH (with 8 data bit character frames) or from 00 through 7FH (with 7 data bit character frames)) to be sent and received.
Introduction
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-22 CP 340 Point-to-Point Communication ASE00053578-05
When sending data, specify the number of bytes of user data to be transmitted for the parameter LEN when you call the function block P_SEND. The user data must contain any required start-of-text and end-of-text characters.
If you are working with the end criterion ”character delay time expired”
when receiving data, the ASCII driver pauses between two message frames, also when sending. You can call the P_SEND FB at any time, but the ASCII driver does not begin its output until a period longer than the parameterized character delay time has elapsed since the last message frame was sent.
Note
When the flow control XON/XOFF is parameterized, the user data must not contain any of the parameterized XON or XOFF codes. The default settings are DC1 = 11H for XON and DC3 = 13H for XOFF.
The figure below illustrates a send operation.
The amount of data to be sent is taken from the LEN parameter of the P_SEND FB.
Waiting for send request
Send request arrived
Sending user data
Request processed
Figure 2-10 Sequence of a Send Operation Sending Data with
the ASCII Driver
Sending Data
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-23
CP 340 Point-to-Point Communication ASE00053578-05
For data transmission using the ASCII driver you can choose between three different end criteria. The end criterion defines when a complete message frame is received. The possible end criteria are as follows:
• On Expiry of Character Delay Time
The message frame has neither a fixed length nor a defined end-of-text character; the end of the message is defined by a pause on the line (expiry of character delay time).
• On Receipt of End Character(s)
The end of the message frame is marked by one or two defined end-of-text characters.
• On Receipt of Fixed Number of Characters
The length of the receive message frames is always identical.
The code transparency of the procedure depends on the choice of parameterized end criterion and flow control:
• With one or two end-of-text characters – not code-transparent
• When end criterion is character delay time or fixed message frame length – code-transparent
• Code-transparent operation is not possible when the flow control XON/XOFF is used.
Code-transparent means that any character combinations can occur in the user data without the end criterion being recognized.
Receiving Data with the ASCII Driver
Code
Transparency
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-24 CP 340 Point-to-Point Communication ASE00053578-05
When data is received, the end of the message frame is recognized when the character delay time expires. The received data is taken over by the CPU with the function block P_RCV.
In this case the character delay time must be set such that it easily expires between two consecutive message frames. But it should be long enough so that the end of the message frame is not falsely identified whenever the partner in the link takes a send pause within a message frame.
The figure below illustrates a receive operation with the end criterion ”expiry of character delay time”.
Waiting for character
Character arrived
Error when receiving (not a character delay
time error)
Message frame buffered
End criterion for message frame identified, error entry follows
Character received with character delay
time monitoring
Message frame en-tered in receive
buffer
Error entered in receive buffer Waiting for character delay time. Received characters discarded Message frame
com-plete (character delay time expired)
Figure 2-11 Sequence of Receive Operation with End Criterion ”Expiry of Character Delay Time”
End Criterion
”Expiry of Character Delay Time”
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-25
CP 340 Point-to-Point Communication ASE00053578-05
When data is received, the end of the message frame is recognized when the parameterized end-of-text character(s) arrive. The received data, including the end-of-text character, is taken over by the CPU with the function block P_RCV.
If the character delay time expires while the message frame is being
received, the receive operation is terminated. An error message is issued and the message frame fragment is discarded.
If you are working with end-of-text characters, transmission is not
code-transparent, and you must make sure that the end code(s) do not appear in the user data of the user.
The figure below illustrates a receive operation with the end criterion
”end-of-text character”.
Error entered in re-ceive buffer
End criterion for message frame identified, error entry follows Character
delay time expired
Figure 2-12 Sequence of Receive Operation with End Criterion ”End-of-Text Character”
End Criterion
”End-of-Text Character”
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-26 CP 340 Point-to-Point Communication ASE00053578-05
When data is received, the end of the message frame is recognized when the parameterized number of characters has arrived. The received data is taken over by the CPU with the function block P_RCV.
If the character delay time expires before the parameterized number of characters has been reached, the receive operation is terminated. An error message is issued and the message frame fragment is discarded.
The figure below illustrates a receive operation with the end criterion ”fixed message frame length”.
Error when receiving Character received
with length control and character delay
time
Error entered in re-ceive buffer Waiting for
para-meterized num-ber of characters Message
frame complete
Waiting for character
Character arrived
Message frame buffered
Message frame en-tered in receive
buffer
End criterion for message frame identified, error entry follows
Character delay time expired
Figure 2-13 Sequence of Receive Operation with End Criterion ”Fixed Message Frame Length”
End Criterion
”Fixed Message Frame Length”
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-27
CP 340 Point-to-Point Communication ASE00053578-05
A BREAK evaluation only occurs if the BREAK monitoring is not deactivated with the parameter assignment user interface.
The CP 340 receive buffer accommodates 1024 bytes. On parameterization, you can specify whether the CP receive buffer is to be deleted at start-up and whether the overwriting of data in the receive buffer is to be prevented. You can also specify the value range (1 to 250) for the number of buffered receive message frames.
The receive buffer on the CP 340 is a ring buffer:
• If several message frames are entered in the receive buffer of the CP 340, it is always the oldest one that is sent from the CP 340 to the CPU.
• If you only ever want to send the most recent message frame to the CPU, you must parameterize the value ”1” for the number of buffered message frames and deactivate the overwrite protection.
Note
If the constant reading of the received data from the user program is inter-rupted for a while, you may find that when the received data is requested again, the CPU first receives an old message frame from the CP 340 before it receives the most recent one.
The old message frame is the one that was on its way when transmission between the CP 340 and the CPU was interrupted, or which had already been received by the FB.
For further information on receive buffers, see Section 7.3.
BREAK - Monito-ring on CP340
Receive Buffer on CP 340
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-28 CP 340 Point-to-Point Communication ASE00053578-05
The following RS 232C secondary signals exist on the CP 340-RS 232C (see also Appendix B):
• DCD (input) Data carrier detect;
Data carrier detected
• DTR (output) Data terminal ready;
CP 340 ready for operation
• DSR (input) Data set ready;
Communication partner ready for operation
• RTS (output) Request to send;
CP 340 ready to send
• CTS (input) Clear to send;
Communication partner can receive data from the CP 340 (response to RTS = ON of the CP 340)
• RI (input) Ring Indicator;
Indication of an incoming call
When the CP 340-RS 232C is switched on, the output signals are in the OFF state (inactive).
You can parameterize the use of the DTR/DSR and RTS/CTS control signals by means of the CP 340: Point-to-Point Communication, Parameter
Assignment parameterization interface or control them in the user program by means of functions (FCs).
The RS 232C secondary signals can be used as follows:
• When the automatic use of all RS 232C secondary signals is parameterized
• When data flow control (RTS/CTS) is parameterized
• By means of the V24_STAT and V24_SET functions (FCs)
Note
When automatic use of the RS 232C secondary signals is parameterized, neither RTS/CTS data flow control nor RTS and DTR control by means of the V24_SET FC are possible.
When RTS/CTS data flow control is parameterized, RTS control by means of the V24_SET FC is not possible.
On the other hand, it is always possible to read all RS 232C secondary si-gnals by means of the V24_STAT FC.
The sections that follow describe how the control and evaluation of the RS 232C secondary signals is handled.
RS 232C
Secondary Signals
Using the RS 232C Secondary Signals
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-29
CP 340 Point-to-Point Communication ASE00053578-05
The automatic use of the RS 232C secondary signals on the CP 340 is implemented as follows:
• As soon as the CP 340 is switched by means of parameterization to an operating mode with automatic use of the RS 232C secondary signals, it switches the RTS line to OFF and the DTR line to ON (CP 340 ready for use).
Message frames cannot be sent and received until the DTR line is set to ON. As long as DTR remains set to OFF, no data is received via the RS 232C interface. If a send request is made, it is aborted with an error message.
• When a send request is made, RTS is set to ON and the parameterized data output waiting time starts. When the data output time elapses and CTS = ON, the data is sent via the RS 232C interface.
• If the CTS line is not set to ON within the data output time so that data can be sent, or if CTS changes to OFF during transmission, the send request is aborted and an error message generated.
• After the data is sent, the RTS line is set to OFF after the parameterized time to RTS OFF has elapsed. The CP340 does not wait for CTS to change to OFF.
• Data can be received via the RS 232C interface as soon as the DSR line is set to ON. If the receive buffer of the CP 340 threatens to overflow, the CP 340 does not respond.
• A send request or data receipt is aborted with an error message if DSR changes from ON to OFF. The message ”DSR = OFF (automatic use of V24 signals)” is entered in the diagnostics buffer of the CP 340.
Note
When automatic use of the RS 232C secondary signals is parameterized, neither RTS/CTS data flow control nor RTS and DTR control by means of the V24_SET FC are possible.
Automatic Use of the Secondary Signals
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-30 CP 340 Point-to-Point Communication ASE00053578-05
Figure 2-14 illustrates the chronological sequence of a send request.
RTS OFF
0 ON
1
CTS ON
TXD
Send request:
RTS = ON Partner:
CTS = ON Data output waiting time elapsed: Send
Data output waiting time
Transmission terminated
Time to RTS OFF elapsed
Partner:
CTS = OFF
Time to RTS OFF OFF
t
Figure 2-14 Time Diagram for Automatic Use of the RS 232C Secondary Signals Time Diagram
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-31
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. 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:
• As soon as the CP 340 is switched by parameterization to an operating mode with flow control, it sends the XON character or sets the RTS line to ON.
• When the parameterized number of message frames is reached, or alternatively 50 characters before the receive buffer overflows (size of the receive buffer: 1024 bytes), the CP 340 sends the XOFF character or sets the RTS line to OFF. If the communication partner continues to send data regardless of this, the receive buffer overflows and an error message is generated. The data received in the last message frame is discarded.
• As soon as a message frame is fetched by the S7 CPU and the receive buffer is ready to receive, the CP 340 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 transmission. If neither an XON character is received nor CTS is set to ON before a parameterized time has elapsed, the transmission is aborted and an appropriate error message (0708H) is generated at the STATUS output of the function blocks.
Note
When RTS/CTS data flow control is parameterized, you must fully wire the interface signals in the plug connection (see Appendix B).
|When RTS/CTS data flow control is parameterized, RTS control by means of the V24_SET FC is not possible.
The V24_STAT function allows the status of each RS 232C secondary signal to be determined. The V24_SET function allows the DTR and RTS output signals to be controlled.
Data Flow Control/
Handshaking
Reading/Control with FC V24_STAT and FC V24_SET
Basic Principles of Serial Data Transmission 如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/
长沙工控帮教育科技有限公司整理
2-32 CP 340 Point-to-Point Communication ASE00053578-05