Programming Example for Standard Function Blocks 
  9.6 Activation, Startup Program and Cyclic Program 
Point-to-point connection CP 440 Installation and Parameter Assignment 
Manual, 09/2007, A5E00057742-03 
135 
9.6.3 "CP440 ASCII BCC" Program Example 
Structure of the Program Example 
This program example only makes sense for the ASCII driver. 
This example is set up identically to the "CP440 SEND RECV" example but also contains the 
following: 
●  A block check sum is generated in the send section by calling FC 23 (GEN BCC) 
●  The block check sum is checked in the receive section with the call of FC 24 (CHK BCC) 
Description of the FC 23 (GEN BCC) 
The "DB_NO" input parameter specifies the DB in which the data to be sent is stored. The 
"LEN" input parameter specifies the length of the data to be sent. The last two bytes should 
be reserved for the block check (stored as an ASCII value). 
The block check is executed by means of an XOR logical operation of all the bytes to be sent 
(LEN -2). The XOR logical operation occurs in the "LOOP". The relevant byte is loaded with 
the L DBB [#d_loop_akt] command. The "#d_loop_akt" offset must be specified as a bit 
offset. After "LOOP" is executed, the block check is in the low byte of the "#w_bcc_value" 
variable. The block check is then encoded in two ASCII characters as described in the 
example below. 
 
Example 
Table 9-6  Generation of BCC HI ASCII characters "32" =2 
#w_bcc_value   0025   
UW w#16#F0   00F0  //Hide lower half-byte 
  = 0020   
  
SLW 4  0200  //Push a half-byte to the left 
OW w#16#3000  3000  //Request 3000 Hex 
  = 3200   
 
Table 9-7  Generation of BCC LO ASCII characters "35" =5 
#w_bcc_value   0025   
UW w#16#F  000F  //Hide upper half-byte 
  = 0005   
  
OW w#16#30  0030  //Request 30 Hex 
  = 0035   
The BCC is then written in word 20 of the data block (L DBW [#d_loop_akt] ) 
该文档是极速PDF编辑器生成,
如果想去掉该提示,请访问并下载:
http://www.jisupdfeditor.com/