F70_BCC

Block check code calculation

Calculates the Block Check Character (BCC), which is used to detect errors in message transmission, of s3_Number bytes of ASCII data starting from the 16-bit area specified by s2_Start according to the calculation method specified by s1_Control. The Block Check Code (BCC) is stored in the lower byte of the 16-bit area specified by d. (BCC is one byte. The higher byte of d does not change.)

Parameters

Input

s1_Control (INT)

Specifies BCC calculation method:

  • 0: Addition (SYS_BCC_CALCULATION_METHOD_ADD)

  • 1: Subtraction (SYS_BCC_CALCULATION_METHOD_SUB)

  • 2: Exclusive OR (SYS_BCC_CALCULATION_METHOD_XOR)

  • 16#A: CRC-16 (SYS_BCC_CALCULATION_METHOD_CRC16)

s2_Start (WORD, INT, UINT)

Starting 16-bit area to calculate BCC

s3_Number (INT)

Specifies number of bytes for BCC calculation

Output

d (WORD, INT, UINT)

16-bit area for storing BCC

Remarks

Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_CRC, FP_BCC

Specifying the control code s1_Control

  1.  (1) Calculation method

    0: Addition (SYS_BCC_CALCULATION_METHOD_ADD)

    1: Subtraction (SYS_BCC_CALCULATION_METHOD_SUB)

    2: Exclusive OR (SYS_BCC_CALCULATION_METHOD_XOR)

    16#A: CRC-16 (SYS_BCC_CALCULATION_METHOD_CRC16)

  2.  (2) Starting byte position for calculation (No. of bytes from s2)

    0–F

  3.  (3) Starting byte position for storing results (No. of bytes from d)
  4.  (4) Conversion data
    • 0: Binary data (CRC: 2 bytes/Not CRC: 1 byte)
    • 1: ASCII data (2 bytes)
NOTE

If CRC-16 is specified as the calculation method, ASCII code cannot be specified for the conversion data.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if the number of specified bytes for the target data exceeds the limit of the specified data area.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

if the number of specified bytes for the target data exceeds the limit of the specified data area.

Example

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		Start: BOOL:=FALSE;
			(*activates the function*)
		BCC_Calc_Method: INT:=2;
		ASCII_String: STRING[32]:='%01#RCSX0000';
			(*specifies the operation:
0: addition
1: subtraction
2:XOR*)
		BCC: WORD:=0;
			(*result after a 0->1 leading
edge from start: 10#172*)
	END_VAR

LD body

A block check character calculation is performed on ASCII_String when Start turns to TRUE. The calculation method is exclusive OR. (Use this method when large amounts of data are transmitted).

How the BCC is calculated using the exclusive OR operation:

bvar_1

bvar_2

bvar_3

0

0

0

0

1

1

1

0

1

1

1

0

  1.  (1) ASCII-HEX-code
  2.  (2) ASCII-BIN-code
  3.  (3) Exclusive ORing
  4.  (4) calculation
  5.  (5) Block Check Character (BCC)
  6.  (6) Calculation result (16#1D) is stored in d.

The ASCII BIN code bits of the first two characters are compared with each other to yield an 8-character exclusive OR operation result:

Sign for comparison

ASCII BIN code

%

00100101

0

00110000

Exclusive OR result

00010101

This result is then compared to the ASCII BIN code of the next character, i.e. "1".

Sign for comparison

ASCII BIN code

Exclusive OR result

00010101

1

00110001

Next exclusive OR

00100100

And so on until the final character is reached.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 11 ;
        NETWORK_BODY
B(B_F,F70_BCC!,Instance,26,1,34,7,,?DEN?Ds1_Control?Ds2_Start?Ds3_Number?AENO?Cd);
B(B_CONTACT,,Start,3,2,5,4,);
B(B_VARIN,,BCC_Calc_Method,24,3,26,5,);
B(B_F,Adr_Of_VarOffs_I!,Instance,16,5,25,9,,?D@'Var'?DOffs?CAdr);
B(B_VAROUT,,BCC,34,3,36,5,);
B(B_VARIN,,ASCII_String,11,4,13,6,);
B(B_VARIN,,2,14,7,16,9,);
B(B_F,LEN!,Instance,16,8,21,11,,?DIN?C);
L(16,5,16,7);
L(13,5,16,5);
L(13,5,13,10);
L(13,10,16,10);
L(25,5,25,7);
L(25,5,26,5);
L(26,6,26,10);
L(21,10,26,10);
L(5,3,26,3);
L(1,3,3,3);
L(1,0,1,11);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F70_BCC( s1_Control:= BCC_Calc_Methode,
         s2_Start:= Adr_Of_VarOffs( Var:= ASCII_String,
         Offs:= 2),
         s3_Number:= LEN( ASCII_String),
         d=> BCC);
END_IF;

Modified on: 2021-10-22Feedback on this pagePanasonic hotline