Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Overview

The "PlcHelperBC.lb6" library contains a number of functions which provide direct access to memory areas in the PLC runtime system of the PLC Controller (BCxxxx).

Comment

The fact that these functions allow direct access to the physical memory means that special care is called for in applying them! Incorrect parameter values can result in a system crash, or in access to forbidden memory areas.

Contents of the Library

Name | Description
MEMCMP | Compares the values of variables in two memory areas
MEMCPY | Copies the values of variables from one memory area to another
MEMSET | Sets the variables in a memory area to a particular value


MEMCMP

The function MEMCMP allows the values of PLC variables in two different memory areas to be compared.

FUNCTION MEMCMP : INT

VAR_INPUT

pBuf1 :DWORD;
pBuf2 :DWORD;
n :UINT;

pBuf1: start address of the first memory area (the first data buffer).

pBuf2: start address of the second memory area (the second data buffer).

n: number of bytes to be compared.

The function compares the first n bytes in the two data buffers and returns a value that corresponds to their relationship.

Return parameter | Relationship of the first byte that differs between the first and second data buffers
-1 | pBuf1 smaller than pBuf2
0 | pBuf1 identical to pBuf2
1 | pBuf1 greater than pBuf2
0xFF | Incorrect parameter values. pBuff1 = 0 or pBuff2 = 0 or n = 0

Example of a call in FBD

VAR
Buffer1 : ARRAY[0..3] OF BYTE;
Buffer2 : ARRAY[0..3] OF BYTE;
CmpResult : INT;
END_VAR

In this example, 4 bytes of data in Buffer2 are compared with those in Buffer1. The first differing byte is larger in Buffer1 than it is in Buffer2.


MEMCPY

The function MEMCPY can be used to copy the values of PLC variables from one memory area to another.

FUNCTION MEMCPY : UINT

VAR_INPUT

destAddr : DWORD;
srcAddr : DWORD;
n : UINT;

destAddr: start address of the target memory area.

srcAddr: start address of the source memory area.

n: number of bytes to be copied.

The function copies n bytes from the memory area that starts at srcAddr to the memory area that starts at destAddr.

Return parameter | Meaning
0 | Incorrect parameter values. destAddr == 0 or srcAddr==0 or n == 0
> 0 | If successful, the number of bytes copied (n).

Example of a call in FBD

VAR
Buffer1 : ARRAY[0..3] OF BYTE;
Buffer2 : ARRAY[0..3] OF BYTE;
CpyResult : UINT;
END_VAR

In the example, 4 bytes are copied from Buffer2 to Buffer1.


MEMSET

The function MEMSET allows PLC variables in a particular memory area to be set to a particular value.

FUNCTION MEMSET : UINT

VAR_INPUT

destAddr :DWORD;
fillByte :USINT;
n :UINT;

destAddr: start address of the memory area that is to be set.

fillByte: value of the filler byte.

n: number of bytes to be set.

The function fills n bytes in the memory area that starts at address destAddr with the value specified by fillByte.

Return parameter | Meaning
0 | Incorrect parameter values. destAddr == 0 or n == 0
> 0 | If successful, the number of bytes that have been set (n).

Example of a call in FBD

VAR
Buffer1 : ARRAY[0..3] OF BYTE;
SetResult : UINT;
END_VAR

In the example, 4 bytes in Buffer1 are set to the value 0xAF.