Programming Manual Logix5000 Controllers ASCII Strings Catalog Numbers 1756-L1, 1756-L55, 1756-L61, 1756-L62, 1756-L63, 1769-L31, 1769-L32C, 1769-L32E, 1769-L35CR, 1769-L35E, 1789-L60, PowerFlex 700S/SE
Important user information Read this document and the documents listed in the additional resources section about installation, configuration, and operation of this equipment before you install, configure, operate, or maintain this product. Users are required to familiarize themselves with installation and wiring instructions in addition to requirements of all applicable codes, laws, and standards.
Summary of changes This manual contains new and updated information. Changes to this manual are documented in the following table. Change Topic Updated create string data types image. Configure the Serial Port on page 10 Updated Controller Properties - Ascii_examples Configure the User Protocol on page 13 Updated String: New String image.
Table of contents Preface Studio 5000 environment ..................................................................................... 7 Additional resources............................................................................................... 7 Chapter 1 Communicating with an ASCII device Introduction ............................................................................................................ 9 Connect the ASCII device ...........................................................
Preface This manual shows how to manipulate ASCII strings in Logix5000 controllers. This manual is one of a set of related manuals that show common procedures for programming and operating Logix5000 controllers. For a complete list of common procedures manuals, refer to the Logix5000 Controllers Common Procedures Programming Manual publication 1756-PM001. The term Logix5000 controller refers to any controller that is based on the Logix5000 operating system.
Preface Resource Description Product Certifications webpage, available at http://ab.rockwellautomation.com Provides declarations of conformity, certificates, and other certification details. You can view or download publications at http://www.rockwellautomation.com/literature. To order paper copies of technical documentation, contact your local Rockwell Automation distributor or sales representative.
Chapter 1 Communicating with an ASCII device Introduction You can exchange ASCII data with a device through the serial port of the controller. For example, you can use the serial port to: • Read ASCII characters from a weigh scale module or bar code reader. • Send and receive messages from an ASCII triggered device, such as a MessageView terminal. Firmware revision 3.
Chapter 1 Communicating with an ASCII device Connect the ASCII device To connect to the ASCII device, use these steps. 1. On the serial port of the ASCII device, determine which pins send signals and which pins receive signals. 2. Connect sending pins to corresponding receiving pins and attach jumpers. If the communications Then wire the connectors Handshake Do not handshake 3. Attach the cable shield to the connectors. 4. Connect the cable to the controller and the ASCII device.
Communicating with an ASCII device Chapter 1 3. On the Mode menu, choose User and type the configuration settings for the serial port. • Choose the baud rate, data bits, parity, and stop bits.
Chapter 1 Communicating with an ASCII device Configure the User Protocol To configure the user protocol, use these steps. 1. In the Controller Properties dialog box, click the User Protocol tab. • Enter a buffer size greater than or equal to the greatest number of characters in a transmission. Twice the number of characters is a good guideline. • For ABL or ARL instructions, enter termination characters to mark the end of the data. For ASCII codes, see ASCII Character Codes on page 29.
Communicating with an ASCII device Chapter 1 • If the ASCII device is configured for XON/XOFF flow control, select the XON/XOFF check box. • If the ASCII device is a CRT or pre-configured for half duplex transmission, select the Echo Mode check box. • Choose the Delete Mode using the following considerations: If the ASCII device is Select Tips CRT CRT • The DEL character ($7F) and the character that precedes the DEL character are not sent to the destination.
Chapter 1 Communicating with an ASCII device 1. In the Controller Organizer, right-click Strings and choose New String Type. 2. In the Name box, type the name for the data type. 3. In the Maximum Characters box, type the maximum number of characters that the string data type stores. 4. Click OK. Read characters from the device As a general rule, before you read the buffer, use an ACB or ABL instruction to verify that the buffer contains the required characters.
Communicating with an ASCII device Chapter 1 In the following example, the device sends a variable number of characters, such as a message or display terminal. Example: Continuously test the buffer for a message. • Because each message ends in a carriage return ($0D), the carriage return is configured as the termination character in the Controller Properties dialog box, User Protocol tab. • When the ABL finds a carriage return, its sets the FD bit.
Chapter 1 Communicating with an ASCII device Example: When the temperature reaches the low limit (temp_low is on), the AWT instruction sends nine characters from the string[2] tag to a MessageView terminal. (The $14 counts as one character. The hex code for the Ctrl-T character.
Communicating with an ASCII device Enter ASCII characters Chapter 1 To enter the ASCII characters, use these steps. Important: This String Browser window shows the characters up to the value of the LEN member of the string tag. The string tag may contain additional data, which the String Browser window does not show. 1. In the AWA instruction, double-click the value area of Source.
Chapter 2 Processing ASCII characters You can process ASCII characters to do many things, including: Introduction Extract a part of a Bar Code • Interpret a bar code and take action based on the bar code. • Use a weight from a weigh scale when the weight is sent as ASCII characters. • Decode a message from an ASCII triggered device, such as an operator terminal. • Build a string for an ASCII triggered device using variables from your application.
Chapter 2 Processing ASCII characters Look up a Bar Code For example, in a sorting operation, an array of a user-defined data type creates a table that shows the lane number for each type of product. To determine which lane to route a product, the controller searches the table for the product ID (characters of the bar code that identify the product). To look up a bar code, follow these procedures: • Create the PRODUCT_INFO Data Type on page 21. • Search for the characters on page 21.
Processing ASCII characters Chapter 2 Create the PRODUCT_INFO Data Type To create a Product_Info user-defined date type in the Controller Organizer, right-click User-Defined and click New Data Type. Configure the user-defined data type as follows.
Chapter 2 Processing ASCII characters • The sort_table_search tag controls the FSC instruction. • Although the previous instruction sets the Length of this instruction, you enter an initial value to verify the project. • The product_id tag contains the bar code characters that you want to find. Identify the Lane Number Add the following rung to the routine to identify the LANE member. When the FSC instruction finds the product ID within the sort_table array, the instruction sets the FD bit.
Processing ASCII characters Chapter 2 Enter the Product IDs and Lane Numbers In the sort_table array, enter the ASCII characters to identify each item and the corresponding lane number for the item. Check the Bar Code characters Use a compare instruction (EQU, GEQ, GRT, LEQ, LES, NEQ) to check for characters. • The hexadecimal values of the characters determine if one string is less than or greater than another string.
Chapter 2 Processing ASCII characters Example: Convert a value When bag_flt_and_dest is equal to gate[1], xfer[1] turns on. This routes the bag to the required gate. You can convert the ASCII representation of a value to an DINT or REAL value that you can use in your application. • The STOD and STOR instructions skip any initial control or non-numeric characters (except the minus sign in front of a number).
Processing ASCII characters Decode an ASCII message Chapter 2 You can extract and convert a value from an ASCII message that contains multiple values. A message may look like the following example: Rung A: Find and Convert a Floating-Point Value The FIND instruction locates characters within a string. • The Source contains the string tag to search. • The Result contains the location where the FIND instruction locates the search value you specify.
Chapter 2 Processing ASCII characters Build a string • The source is the same string tag as for the FIND instruction. • The quantity values tells the MID instruction how many characters to pull from the source. • The start value is the same as the Result value from the FIND instruction. This tells the MID instruction where to start pulling characters from the Source. • The Destination contains the characters you located. The following example builds a string that contains two variables.
Processing ASCII characters Rockwell Automation Publication 1756-PM013D-EN-P - October 2014 Chapter 2 27
Appendix A ASCII character codes ASCII charter codes Character Dec Hex Character Dec Hex Character Dec Hex Character Dec Hex [ctrl-@] NUL 0 $0 SPACE 32 $20 @ 64 $40 ‘ 96 $60 [ctrl-A] SOH 1 $1 ! 33 $21 A 65 $41 a 97 $61 [ctrl-B] STX 2 $2 “ 34 $22 B 66 $42 b 98 $62 [ctrl-C] ETX 3 $3 # 35 $23 C 67 $43 c 99 $63 [ctrl-D] EOT 4 $4 $ 36 $24 D 68 $44 d 100 $64 [ctrl-E] ENQ 5 $5 % 37 $25 E 69 $45 e 101 $65 [ctrl-F] ACK 6 $6 & 38
Index A ASCII configure serial port 12 configure user protocol 13 enter characters 19 manipulate characters 21 organize data 15 read characters 16 write characters 17 C configure serial port for ASCII 12 user protocol for ASCII 13 create string data type 15 D S send ASCII characters 17 serial configure port for ASCII 12 string data type 15 enter characters 19 manipulate 21 organize data 15 read characters 16 write characters 17 string data type create 15 T tag string 15 data ASCII 15 enter ASCII charac
Rockwell Automation support Rockwell Automation provides technical information on the web to assist you in using its products. At http://www.rockwellautomation.com/support you can find technical and application notes, sample code, and links to software service packs. You can also visit our Support Center at https://rockwellautomation.custhelp.com for software updates, support chats and forums, technical information, FAQs, and to sign up for product notification updates.