Overview
In a serial interface, the data bits are sent in sequence through a communication channel or link. Several technologies use the serial communication for data transfer, including interfaces RS232.
Configuration
Some parameters need to be configured to perform the RS232 communication; to do so, check the item RS232.
There are three operating modes of the RS232 communication.
| • | Mode 0: Modbus Slave; |
| • | Mode 2: ASCII Protocol; |
| • | Mode 4: Generic telegrams. |
|
NOTE! Modes 1 and 3 are reserved. |
Mode 0: Modbus Slave
Refer to manual PLC300 - Modbus RTU Communication, available at http://www.weg.net/br.
Mode 2: ASCII Protocol
The ASCII protocol, via RS232, was developed for bar code reading.
Involved Variables:
| • | RS232_MODE: BYTE system marker which defines the operating mode of the RS232: |
| o | 2: ASCII protocol; |
| • | RS232_RX_CLEAR: BIT marker; clears the data buffer (RS232_ ASCII_ BYTEBUFFER) and the RS232_RX_FINISHED flag; |
| • | RS232_RX_FINISHED: BIT marker; indicates that a data package is available in the RS232_ASCII_BYTEBUFFER buffer; |
| • | RS232_ASCII_BYTEBUFFER: 256-byte buffer which stores the received characters; |
| • | RS232_ASCII_STRING: STRING buffer, which can be shown on the screen of the PLC300 by the ‘Text Output’ component. |
How to use the RS232 in the ASCII mode:
| 1. | Select the ASCII protocol by setting: RS232_MODE = 2 in the Ladder; |
| 2. | Give a pulse in the RS232_RX_CLEAR marker to clear the RS232_ASCII_ BYTEBUFFER buffer, and the RS232_RX_FINISHED flag; |
| 3. | When receiving a package, the flag: RS232_RX_FINISHED goes to TRUE; |
| 4. | The data are available for the Ladder by means of the array: RS232_ASCII_BYTEBUFFER, of 256 bytes; |
| 5. | To use with the ‘Text Output’ function of the HMI, use the RS232_ASCII_STRING STRING marker. |
|
NOTE! Even without turning on RS232_RX_CLEAR, the system can receive another reading, placing the data over the previous reading. |
|
NOTE! The end of the package is executed when the CR/LF characters (0x0d/0x0a) are received. |
|
NOTE! The CR/LF characters are not stored in the buffer. |
|
NOTE! The buffer is terminated with NULL character (0x00). |
The configuration of the RS232 must be done according to the default configuration of the PLC300;
On the screens, the 'Text Output' component, which only accepts the STRING type, was added to show RS232_ASCII_STRING, which is the string that shows the value read by the protocol, limited to 20 characters (limit of the output function = 1 line).
Mode 4: Generic telegrams
Functionality developed to send and receive telegrams by means of serial communication RS232.
Involved command variables:
| • | RS232_MODE: BYTE marker; defines the operating mode of the RS232: |
| o | 4: telegrams via RS232. |
| • | RS232_TIMEOUT: WORD marker; indicates the maximum waiting time (in ms) for a response, preventing new telegrams to be sent before this time has elapsed. |
| • | RS232_END_CHARACTER: defines a character that can end a telegram, for example, ETX (03H). Upon the receipt of this character, the PLC300 considers that the bytes received up to it are the ones necessary; the others are ignored. |
| • | RS232_ENABLE_END_CHARACTER: BIT marker; system marker that enables the use of telegram end character specified in RS232_END_CHARACTER; |
| o | 0: disabled; |
| o | 1: enabled. |
| • | RS232_START_TX: BIT marker; the telegram is sent on the leading edge of this marker; |
| • | RS232_TX_ADDRESS: WORD marker; indicates the initial address of the data to be transferred; |
| • | RS232_TX_LENGTH: BYTE marker; indicates the number of bytes of the information to be sent; |
| • | RS232_RX_ADDRESS: WORD marker; indicates the initial address of the received data; |
| • | RS232_MAX_RX_BUFFER_LENGTH: BYTE marker; indicates the maximum number of bytes that can be received; |
Involved status variables:
| • | RS232_TX_TELEGRAM_COUNTER: WORD marker; counts the number of sent telegrams; |
| • | RS232_RX_TELEGRAM_FINISHED: BIT marker; indicates that a data package is available in the memory from the address indicated in RS232_RX_ADDRESS. |
| • | RS232_TX_FINISHED: BIT marker; indicates that a data package was completely sent. |
| • | RS232_TIMEOUT_INDICATOR: BIT marker; indicates if the time specified in RS232_TIMEOUT has elapsed. |
| o | 0: there was no overflow; |
| o | 1: there was time overflow. |
| • | RS232_RX_TELEGRAM_COUNTER (status): WORD marker; counts the number of received telegrams; |
| • | RS232_RX_BYTE_COUNTER (status): WORD marker; counts the number of received bytes; |
How to use the RS232 to send and receive telegrams:
| 1. | Select Send and receive telegrams via RS232 by setting RS232_MODE = 4 in the Ladder; |
| 2. | Configure the initial address of the telegrams to be sent and received in, respectively, RS232_TX_ADDRESS and RS232_RX_ADDRESS; |
| 3. | Specify the size (in bytes) of the telegram to be sent by means of marker RS232_TX_LENGTH; |
| 4. | Specify the maximum size (in bytes) of the telegram that can be received by means of RS232_RX_LENGTH marker; |
| 5. | Specify the timeout in RS232_TIMEOUT; |
| 6. | If applicable, configure the telegram end characters of the markers respectively in: RS232_ENABLE END_CHARACTER and RS232_END_CHARACTER; |
| 7. | Reset the RS232_RX_TELEGRAM_FINISHED flag to be ready to receive a telegram; |
| 8. | Give a pulse in RS232_START_TX to send a telegram. |
|
NOTE! It will be considered the end of receipt of telegram, the receipt of the special character when configured in RS232_END_CHARACTER with the RS232_ENABLE_END_CHARACTER flag enabled or, also, when the timeout is equal to twice the transmission time of a byte. |
Compatibility
Device |
Version |
PLC300 |
Mode 0: 1.00 or higher |
Mode 2: 1.11 or higher |
|
Mode 4: 1.50 or higher |