The text of a manual · part 12 of 25
Bulletin 5370 CVIM Configurable Vision Input Module Communications Manual: 5 - Using the RS-232 Ports, pages 89 to 97
Pages 89 to 97 of 202, from Bulletin 5370 CVIM Configurable Vision Input Module Communications Manual
The original document is the PDF (723 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 5370-CVIM
Page 89
Chapter 5 Using the RS-232 Ports
Trigger Operation
Use the trigger operation command to initiate an inspection by the CVIM module. Use the following commands:
>T, TS1[CR] >T, TS2[CR]
Triggers an inspection with toolset 1. Triggers an inspection with toolset 2.
This function can only be executed once per command. Note: When using this command you should make sure that the CVIM module is configured for a “hosted trigger source”. After executing a command, the CVIM module will return: [CR][LF]. No data is returned. If you do not have the proper command structure, the CVIM module will return: ?[CR][LF].
Unlock Command
Use the unlock command to enable the setup menu box so that a user can access the SETUP mode using the light pen. Use the following command:
>U[CR] This function can only be executed once per command. There is no object associated with this command. After executing a command the CVIM module will return: [CR][LF]. No data is returned. If you do not have the proper command structure, the CVIM module will return: ?[CR][LF].
Write Configuration (W) Write Configuration (WC)
Use the write command to write data to configuration memory (download configuration). Use the following commands:
>W,CBn[CR] d or
>WC,CBn[CR] d Where n =
1 to 136 X–Y *
(individual blocks) (range of blocks X through Y) (all of the blocks)
d = the data that is being written. The format of the data is in an ASCII representation of the specified block(s) in bytes. Each byte is represented by two hexadecimal characters (00 through FF) followed by a space. Note: The WC write command functions like the W write command but allows listing of configuration blocks.
5–19
Page 90
Chapter 5 Using the RS–232 Ports
Write Configuration (W) Write Configuration (WC) (cont’d)
This function can only be executed once per command. Refer to Appendix D for a description of the configuration blocks. You cannot use this command when the CVIM module is in the setup mode. When the CVIM module is receiving configuration blocks from a Host, the CVIM module will leave the active run mode and ignore any input triggers (setup menu option is also disabled). After receiving one or more new configuration blocks, the CVIM module will validate the entire configuration since many of the operating parameters are interrelated. Example:
>W,CB1 [CR] 00__F1__etc.
This example writes the data 00, F1, etc. into configuration block #1. “_” = space character.
Example:
>WC,CB1,CB30–35,CB21[CR](data)
This example writes the data into the specified blocks.
After executing the command, the CVIM module will return: [CR][LF]. No data is returned. If you do not have the proper command structure, the CVIM module will return: ?[CR][LF]. Note: We recommend that you check the discrete bit ‘‘configuration fault’’ after loading a configuration. Refer to Appendix B. You can check this bit by using the read inspection results command for toolset #1, (>RR,S [CR]).
5–20
Page 91
Chapter 5 Using the RS-232 Ports
Command Summary
After you have become familiar with the ASCII commands, you can use the following command summary as a quick reference guide. Table 5.A ASCII Command Summary Command
Command Structure
Field Descriptions
Deactivate Forces
>DF [CR]
Disable Outputs
>DO [CR]
Enable Outputs
> EO [CR]
Echo Data
>E, data [CR]
Data = ASCII string
Force Outputs
>F, On, d [CR] n= d=
1 to 14 0 or 1 d=
1 to 16*
Load Configuration From EEPROM to RAM Load Configuration From RAM Card to RAM
>LO [CR] >LO, CC, d[CR]
Lock
>L [CR]
Unlock
>U [CR]
Read Output Condition
>R, On [CR] n=
1 to 14
Read Configurable Statistics
>RSn [CR] n= number of times read
Read Configuration
>RC, CBn [CR] n=
1 to 136
Read Discrete Bit Results
>RR, TSn [CR] n=
1 or 2
>RR, TSnRB, d [CR] n= d=
1 or 2 1, 2, 3 or 4 n= o= d=
1 or 2 RL,RW,G,W,LP gage or window number
S=
Status
>RR,TSno,d[CR] Read Results Block
>RR,S** Save to EEPROM from RAM
>S [CR]
Save to RAM Card from RAM
>S, CC, d [CR]
Set Configurable Results * **
>SR,TSxd,TSxd,etc. [CR] d = 1 to 16* x= d=
1 or 2 G1,G2,W1,W2, RW1, RL3, LP, etc.
The number of configurations that can be stored on a RAM card depends upon the card size (512K card can hold 16 configurations). Refer to Appendix B, Table B.1, RS–232 word 0 for a definition of CVIM status.
5–21
Page 92
Chapter 5 Using the RS–232 Ports
Command Summary (cont’d)
Table 5.A ASCII Command Summary (Cont’d) Command Set Configurable Statistics
Trigger Inspection
Command Structure >SSn,TSxd,TSxd,etc. [CR]
>T,TSn[CR] >W, D, data [CR]
Field Descriptions n= x= d= number of samples. 1 or 2 G1, G2, W1, W2, RW1, LP, etc.
n=
1 or 2
Data = XY X= 1 (TS1)2 2 (TS2) Y= 1 to 9 1 = Image only 2 = Failed Tools 3 = All Tools 4 = I/O Page 5 = Results Page 6 = Stats 1 Page 7 = Stats 2 Page 8 = Page Up 9 = Page Down
Write Display
>W, F, data [CR]
Data = XY X= 1 (TS1)2 2 (TS2) Y= 1 to 9 1 = Go On Reject 2 = Freeze On First Reject 3 = Freeze On All Rejects 4 = Freeze On Next Inspection 5 = Halt On Reject
>W, DC, data (CRI
Data = XY X= 1 (TS1)2 2 (TS2) Y= 1 to 9 1 = Resume 2 = Reset Statistics 3 = Reset Counters 8 = Page Up 9 = Page Down
5–22
Write Configuration Block(W)
>W, CBn [CR] data n = 1 to 136 Data = ASCII configuration data
Write Configuration Block(WC)
>WC,CBn,CBn,etc. [CR] data n = 1 to 136 Data = ASCII configuration data
Page 93
Chapter 5 Using the RS-232 Ports
Explanation of ASCII Programming Example
The following sample program was written on an Allen-Bradley 1784-T50B terminal (IBM AT compatible) using GW basic. This program obtains discrete results from the CVIM module. A program user is prompted to select either toolset 1 or toolset 2. The program will then:
• Trigger an inspection. • Detect when new data is available. • Read all pass/fail/warning data for the selected toolset. • Display a screen message if any of the first four windows fail. • Prompt the user once again for a toolset number. A basic outline of the program is as follows: Lines 10 to 99
Initialize program variables, configure the RS–232 port for 8 bit transmissions, select no parity, select 9600 Baud, and initialize the display monitor.
Lines 100 to 130
Prompt the operator to select a trigger for toolset 1 or toolset 2.
Subroutine 2000
Reads results to find the current number of total triggers.
Subroutine 1000
Triggers the CVIM module inspection of the selected toolset.
Line 200
Causes a continuous read of CVIM module results until new results are detected. New results are detected by an incrementing of the “total trigger” data.
Subroutine 2500
Converts the CVIM module results from hexadecimal to integer.
Lines 240 to 270
Analyze the discrete fail bits for windows 1 through 4 and display a message if a failure is detected.
Line 400
Sends the program to input line 100.
The program manipulates the returned data as follows:
5–23
Page 94
Chapter 5 Using the RS–232 Ports
Explanation of ASCII Programming Example (cont’d)
Assume the ASCII string from the CVIM module is: CR LF 2114 __ __ __ __ __ __389 __ __ __ __ __ B0__80__ A2__ 00__00__(etc.)CR LF
Note: ( __ = space, LF = Line Feed, CR = Carriage Return) The 18 element hexadecimal array after the program receives the data: R1(0) = 2114 = Decimal representation of total triggers processed. R1(1) = 389 = Decimal representation of total master faults (failed inspections). R1(2) = B0 = Hexadecimal representation of discrete input word 0 low byte. R1(3) = 80 = Hexadecimal representation of discrete input word 0 high byte. R1(4) = A2 = Hexadecimal representation of discrete input word 1 low byte (Window 1 Fault/Warning, Window 2 Fault/Warning, etc.). ••• R1(17) = 00 = Hexadecimal representation of discrete input word 7 high byte (Gage 32 Fault/Warning, Gage 31 Fault/Warning, etc.).
The decimal display on the monitor will appear as follows after the program manipulates the array: 2114
389
176
135
162
0 0 0
0 0 0
0 0 0
0 0
0 0
Analysis of R1(4) for window failure: R1(4) = 162 (decimal). The binary representation is: 10100010 The three ones in this representation indicate fail discrete input conditions in windows 1, 3, and 4 (bits 1, 5, and 7 of word 1, see Table 4.A.).
5–24
Page 95
Chapter 5 Using the RS-232 Ports
ASCII Programming Example
The following is a sample ASCII program written in BASIC:
1 REM RS–232 to CVIM COMMUNICATIONS SAMPLE PROGRAM 2 REM COPYRIGHT ALLEN–BRADLEY COMPANY, INC. 10-17-89 jrm 3 : 4 : 10 OPEN”com1:9600,n,8,1,DS”AS#1: REM Open communications channel 20 DIM R1(17): REM Allocate storage for tool set results 30 HE$=”0123456789ABCDEF”: REM Used for hex to decimal conversion 50 CLS 60 PRINT ”RS–232 TO ALLEN–BRADLEY CVIM COMMUNICATIONS PROGRAM” 70 PRINT:PRINT 99 : 100 PRINT ‘‘Press 1 or 2 to trigger tool set 1 or 2:’’; 110 K$=INKEY$: IF K$,.‘‘1’’ AND K$,.‘‘2’’ THEN 110 120 PRINT K$: TS = ASC (K$) – 48: REM Convert key ‘‘1’’ or‘‘2’’ to number 1 or 2 130 GOSUB 2000: REM Read tool set results to get # of triggers processed 140 IF R1(0)<0 THEN 100 ELSE NT = R1(0) 150 GOSUB 1000: REM Trigger an inspection 200 GOSUB 2000: IF R1(0)=NT THEN 200: REM Read until the trigger is processed 210 GOSUB 2500: REM Convert hex result string RE$ to integers 220 IF R1(0) <0 THEN 100: REM Quit on input error 230 PRINT: FOR X=0 TO 17: PRINT R1(X),: NEXT: PRINT: REM Print results 240 IF R1(4) AND 2 THEN PRINT ”Window 1 FAIL” 250 IF R1(4) AND 8 THEN PRINT ”Window 2 FAIL” 260 IF R1(4) AND 32 THEN PRINT ”Window 3 FAIL” 270 IF R1(4) AND 128 THEN PRINT ”Window 4 FAIL” 400 GOTO 100 999 : 1000 REM Subroutine to trigger an inspection on tool set TS 1050 PRINT#1,”>t,ts”; CHR$(TS+48);CHR$ (13);: REM Send the command 1080 RETURN 1999 : 2000 REM Subroutine to read discrete results from tool set TS 2040 IF LOC(1) THEN R$=INPUT$(LOC(1),#1): REM clear out any garbage characters 2050 PRINT#1,”>rr,p1”; CHR$ (TS+48); CHR$(13);: REM Send the command 2060 CR$=INPUT$(2,#1): REM get CR/LF or ?/CR 2070 IF CR$=CHR$(13)+CHR$(10) THEN 2090 2080 PRINT”Input error”: R$=INPUT$(LOC(1),#1): R1(0)=–1: RETURN 2090 R$=INPUT$(1,#1): IF ASC(R$)<32 THEN 2090: REM ignore junk 2100 LINE INPUT#1,RE$: RE$=R$+RE$: REM get entire response 2120 R1(0) = VAL(MID$(RE$,1,9)): R1(1) = VAL(MID$(RE$,10,9)) 2130 R$=INPUT$(LOC(1),#1): RETURN: REM Clear out any remaining characters 2499 : 2500 REM Subroutine to convert hex values in discrete result string RE$ 2501 REM to integer values 2510 FOR RN=0 TO 15 2515 REM The following line converts each pair of hex digits to an integer 2520 D1=INSTR(HE$,MID$(RE$,25+RN*3,1))–1: D2=INSTR(HE$,MID$(RE$,26+RN*3,1))–1 2530 R1(RN+2) = 16*D1+D2: NEXT RN: RETURN
5–25
Page 96
Chapter 5 Using the RS–232 Ports
DF1 Protocol
The remainder of this chapter describes DF1 protocol. After you have made the equipment connections and configured the CVIM module for RS–232 communications, DF1 packets of data can be sent to the CVIM module.
What is DF1?
DF1 is an Allen–Bradley developed software convention used for RS–232 communications. DF1 provides some handshaking and data–packing formats which allow for fast communications with integrity of the data. This chapter describes a simple application level of DF1 for communications between a CVIM module and a computer host. This application level requires that all transmitted data be preceded by a header and terminated by a trailer and a Block Check Character (BCC). In addition, ACK / NAK characters and simple time out conventions are used to ensure the integrity of the data. A more complete implementation of DF1 can include layered software for point-to-point and multidrop links using several layers: Data Link Layer Transport Network Layer(s) Application Layer We do not provide a complete description of DF1 in this manual. We have only provided information necessary to transmit data between a host computer and the CVIM module. If you want to learn more about DF1, we suggest reading Publication 2802-800 (Line Scan Camera User’s Manual). Appendix A of this publication provides a thorough description of DF1.
DF1 Character Set
5–26
In the DF1 protocol mode, all data is transferred between the CVIM module and a host as bytes with a value between 00(hex) and FF(hex). Refer to Appendix E to convert control codes like ACK and NAK to/from hexadecimal values.
Page 97
Chapter 5 Using the RS-232 Ports
Command Structure
Each command the host device sends to the CVIM module is represented by a block of data beginning with DLE STX (Data Link Escape, Start of Transmission) and terminated with DLE ETX BCC (Data Link Escape, End Transmission, Block Check Character). The data between the header and trailer characters is the command data. The following shows the structure of a typical command:
Note: To avoid any confusion between DLE (10 hex) and data equal to 10 (hex), a value of 10(hex) is transmitted as 10(hex) 10(hex). The DLE code is transmitted simply as 10 (hex). This is referred to as “DLE Stuffing”. The following shows the typical structure of the command data. OPERATION n times (H)
n times (L)
Object
Flags
Data
There are up to five fields in a command: Operation Field, This field contains the command directed to the CVIM module. There can only be one operation per command line. Some commands don’t require any additional fields while others may require an object field,a data field, or both. Some commands cannot be used while the CVIM module is in the SETUP mode. If an operation cannot be performed because either the wrong host is selected or the CVIM module is in the SETUP mode, the CVIM module will not send a response. n times (H) and n times (L), These two fields indicate the High and Low bytes of the n times modifier. The n times modifier is used with certain commands to indicate the number of times the command is to be performed. The range for this value is 0000 to 00FF (255). A value of 0000 indicates infinity. The default value for this field is 0001. Object Field, The Object field specifies data that configures the operation of the CVIM module. In the description of each command we specify the objects that can entered into a command. Flags, This optional field specifies outputs on the local I/O board or specific blocks of data. Data Field, Contains data. 5–27