The text of a manual · part 9 of 25
Bulletin 5370 CVIM Configurable Vision Input Module Communications Manual: 4 - Using the Remote I/O Link, pages 65 to 70
Pages 65 to 70 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 65
Chapter 4 Using the Remote I/O Link (Node Adapter)
Example Program For Accessing Configuration Data Cont’d.
31 December 1989 Page 4 Ladder Listing Processor File: CVIMCNFG.ACH Rung 2:7 Rung 2:7 Reset PB Requests, BTR BN Bit, Window 1 Data, Last Block Specifier. | Reset PB UP | | I:011 B3 | +––––] [––––––––––––––––––––––––––––––––––––– +–––––––(U)––––––––––––––––––––+ | | | 1 | | | | DOWN | | | | B3 | | | +–––––––(U)––––––––––––––––––––+ | | | 11 | | | | BTR DN | | | | N7:100 | | | +–––––––(U)––––––––––––––––––––+ | | | 15 | | | | Last Block | | | | O:023 | | | +–––––––(U)––––––––––––––––––––+ | | | 03 | | | | Window 1 | | | | Y Location | | | | +FLL––––––––––––––––––––+ | | | +–+FILL FILE +––––+–+ | | |Source 0| | | | | |Dest #N7:0| | | | | |Length 42| | | | | +–––––––––––––––––––––––+ | | | | N7:110 | | | +–––––––(L)––––––––––––––––––––+ | | | 13 | | Rung 2:8 | | +––––––––––––––––––––––––––––––––[END OF FILE]–––––––––––––––––––––––––––––––––+ | | NO MORE FILES
4–28
Page 66
Chapter 4 Using the Remote I/O Link (Node Adapter)
Example 6008–SI Program
The following program was written using Microsoft C Version 5.10 with an Allen–Bradley 6008–SI Series B card. The program will:
• Prompt the user for the 6008–SI card address. This address is determined by the DIP switch settings on the card.
• Prompt the user for the 6008–SI card interrupt control line. This is determined by the jumper setting on the board itself.
• Initialize the 6006SI card and prompts the user for the CVIM module rack address (0–7). The CVIM module address was configured on the CVIM module monitor using the light pen.
• Display a five item menu which allows the user to perform the following functions: 1. Trigger Toolset 1. This initiates an inspection cycle. 2. Read Results Toolset 1. Reads the 128 discrete input bits. 3. Read Configuration. Uploads the entire CVIM module configuration including template data. 4. Write Configuration. Downloads the entire CVIM module configuration including template data. 5. Quit.
4–29
Page 67
Chapter 4 Using the Remote I/O Link (Node Adapter)
Example 6008–SI Program (cont’d) /* CVIM to 6008–SI sample communications program /* Copyright Allen–Bradley
1–12–90 jrm,
*/ */
/* This program was compiled using MicrosoftrC Version 5.1 */ #include <stdio.h> #include <stdlib.h> /* Include the 6008–SI definitions */ #include <h_6008si.h> #define TRIGGER_1_BIT 0x0400 /* define storage for configuration data */ unsigned config[135][64], configlen[135], template[256][64], templen[256]; void main() { QMR mr_pkt; unsigned segment; /* segment of 6008–SI card unsigned status, err, CVIM_rack, block_num, numblocks, block1; unsigned block2, last_blk, x, t; int op_num, block_1; /* Prompt – enter address 6008–SI card */ printf (”\n\n\nCVIM to 6008–SI communications sample program\n\n”); printf (”Enter hex RAM address for 6008–SI card (e.g. 0x000): ”); scanf (”%x”, &segment) /* initialize the 6008–SI */ status = setup_6008(baud, 1, l, segment, &mr_pkt); if (status != OK) { printf (”Setup failed: command=%s, status=%s\n”, xlat_cmd(status), xlat_conf(mr_pkt.qmr_stat)); if (status != C_AUTOCONF && status != C_SETUP) printf (”Scanner fatal error %d\n”, fatal_6008()); abort(); } /* Place scanner in RUN mode */ mr_pkt.qmr_data[0] = CM_RUN; status = mr_wait (C_SETMODE, &mr_pkt); if (status != OK) { printf (”Setup failed: command=%s, status=%s\n”, xlat_cmd(status), xlat_conf(mr_pkt.qmr_stat)); if (status != C_AUTOCONF && status != C_SETUP) printf (”Scanner fatal error %d\n”, fatal_6008()); abort(); } /* Disable host watchdog. For sample program ONLY –– not recommended for any application programs. */ host_active(–1); 4–30
Page 68
Chapter 4 Using the Remote I/O Link (Node Adapter)
/* Get CVIM rack address from the user */ printf (”Enter CVIM remote–I/O rack number (0–7): scanf (”%d”, &CVIM_rack);
”);
g_oit[8*CVIM_rack + 2] |= 0x0001; /* post tool results */ /* Start of main loop */ do { printf (”\n\nOperations: \n\n”); printf (”1. Trigger Tool Set 1\n”); printf (”2. Read Results, Toolset 1\n”); printf (”3. Read Configuration\n”); printf (”4. Write Configuration\n”); printf (”\nEnter operation number (1–4) or –1 to quit: ”); scanf(”%d”, &op_num ); err = 0; switch (op_num) {
/* Convert user string input to a number */ case 1: /* trigger tool set 1 */ { g_oit[8*CVIM_rack] |= TRIGGER_1_BIT; /* set trigger bit to 1/* for (t=0; t<5000; t++); g_oit[8*CVIM_rack] &= ~TRIGGER_1_BIT; /* set trigger bit to 0 */ err = g_op_stat & SO_FAULT; } break; case 2: {
/* read discrete results toolset 1 */
/* display all 8 input words in hex */ for (x=0; x<8; x++) printf (”%04X ”, g_ipt[8*CVIM_rack + x]); printf (”\n”); err = g_op_stat & SO_FAULT; } break; case 3: {
/* read configuration */
/* read all config. blocks */ for (block_num = 0; (block_num < 135) && !err; block_num++) err = get_CVIM_block (CVIM_rack, 2, block_num+1, config[block_num], &configlen[block_num]); if (!err) { /*read first template block */ err = get_CVIM_block (CVIM)_rack, 4, 1, template[0], &templen[0]; /* determine total no. of template blocks */ numblocks = template[0][1] >> 8; /* read remaining template blocks */ for blocks_num = 1; (block_num < numblocks) && !err; 4–31
Page 69
Chapter 4 Using the Remote I/O Link (Node Adapter)
block_num++) err = get_CVIM_block (CVIM_rack, 4 block_num+1, template[block_num], &templen{block_num]) } } break; case 4: {
/* write configuration */
/* write all config. blocks */ for (block_num = 0; (block_num < 135) && !err; block_num++) err = send_CVIM_block (CVIM_rack, 2, block_num+1, config[block_num], &configlen[block_num]); } } break; /*send all template blocks */ numblocks = template[0][1] >> 8; for (block_num= 0; (block_num < numblocks) && !err block num++) { err = send_CVIM_block (CVIM_rack, 4 ! (block_num == numblocks–1 ? 8: 0),block_num); } }
}
/* wait until CVIM busy bit is low */ for (t=65535; t>0 && (g_ipt[8*CVIM_rack] & 8); t––) for (x=1; x<100; x++); if (t==0) { printf (”Time–out error: CVIM busy\n”); err = –1; } if (g_ipt[8*CVIM_rack] & 2) printf (”Configuration ERROR.\n”); else printf (”Configuration validation OK.\n”); } break; /* end switch (op_num) statement */ if (err) printf (”Error code: %4x\n”,err); } while (op_num >= 0); stop_6008(); }
/* shut down 6008 before quitting */ int get_CVIM_block (CVIM_rack, block_type, block_num, data, length) unsigned CVIM_rack, block_type, block_num, *data, *length; /* do a BTR (read) from the CVIM */ { static QBT block_pkt; unsigned err, status,x; 4–32
Page 70
Chapter 4 Using the Remote I/O Link (Node Adapter)
/* display msg for program monitoring */ printf (”get_CVIM_block %d(%d)\n”,block_type, block_num); /* Tell CVIM block number and type */ g_oit[8*CVIM_rack + 3] = block_type + block_num * 256; /* Initiate the block transfer read */ block_pkt.qbt_len = 0; /* request 0 words */ status = bt_read(16*CVIM_rack,&block_pkt); err = (status != OK); if (!err) { /* wait for completion of BTR */ while (!bt_done(&block_pkt)); err = (block_pkt.qbt_stat != SC_OK); if (!err) { /* store the block data and length */ *length = block_pkt.qbt_len; memcpy (data, block_pkt.qbt_data, *length * 2); } } return (err); } int send_CVIM_block (CVIM_rack, block_type, block_num, data, length) unsigned CVIM_rack, block_type, block_num, *data, *length; /* performs a BTW (write) to the CVIM */ { static QBT block_pkt; unsigned err, status,x; /* display msg for program monitoring */ printf (”send_CVIM_block %d(%d)\n”,block_type, block_num); /* Tell CVIM block number and type */ g_oit[8*CVIM_rack + 3] = block_type + block_num * 256; /* Initiate the block transfer write */ block_pkt.qbt_len = *length; memcpy (block_pkt.qbt_data, data, *length * 2); status = bt_write(16*CVIM_rack,&block_pkt); err = (status != OK); if (!err) { /* wait for completion of BTW */ while (!bt_done(&block_pkt)); err = (block_pkt.qbt_stat != SC_OK); } return (err); }
4–33