Application of Xinjie PLC XD/XL series C language function blocks

Application of C language function of Xinjie PLC XD/XL series

foreword

本篇文章主要提及信捷PLC在编写,调用C语言功能块时的一些问题:

Now I started to get in touch with domestic PLCs and found that compared with his "touch board" Mitsubishi PLC, Xinjie is more humane because he has added the support of C language function blocks. In fact, now PLCs start to support floating-point operations, and his floating-point operations Ability is not so easy to display (of course my lack of personal ability is a big reason). So it is really a good thing to come into contact with the function blocks of Xinjiejue this time, and it also uses a relatively basic C language.


1. Xinjie C language function block

XD/XL series support users to use C language to write function blocks in Xinjie PLC editing tool software, and call them where needed. Its biggest advantage is that it
supports almost all C language functions (compared to XC series, XD/XL series It also supports global variables ), which enhances the confidentiality of the program, and at the same time, the efficiency of programmers is greatly improved due to the ability to call multiple places and different files.

The part that makes the C language function block really simple is that the XD/XL series also supports global variables . The previous XC series did not support global variables. It is not very convenient to call data, especially the data call between HD and D registers. .

2. Create and write C language function blocks

1. Create a new C language function block

Find the function library in the project column on the left side of the Xinjie PLC programming tool software, you can directly create a new source file in the default library, or you can create a new library and then create a new source file;

Pay attention during the creation process: the user-defined function name is composed of numbers, English, and underscores. The first character cannot be a number, and the length of the name must be <=9 characters. Pay attention to the name with pinyin

insert image description here
insert image description here

The mapping parameters in Figure 2 correspond to the software components in the ladder diagram. Generally, I only map them into D and M, and the reason will be explained later.

2. Writing of C language functions


In this interface, we are writing formal function blocks. First, by default, only HD, D, HM, and M shown in the figure will be mapped. If you want to call registers such as X and Y, you can complete it by modifying the macro definition. For details, refer to XD/XL Series Programmable Controller User Manual [Basic Instructions] page 280.

Next, let's mainly mention how to call the data of the registers in the PLC.

Generally, we only use function blocks when doing calculations (anyway, I am, logic things are generally completed in ladder diagrams, and data is generally processed by function blocks). The mapped D or HD can be used directly with W in the formal parameter. You can see that the parameter type in Figure 2 is a signed 16-bit integer pointer, so we call it through an array.

W[0] = 1;
W[10] = W[11] + W[12];

DW[10] = DW[12] +DW[14];

It should be noted that directly adding D before W means calling a double word; adding F before W means floating-point operation; however, it is not recommended to use this way.

I remember we said at the beginning that the XD/XL series also supports global variables . Personally, I prefer to manually define pointers for each type of data. After the unification, the programming process is much smoother.

3. Definition of pointer

By defining the pointer before the function

INT8U; //8位无符号整数
INT8S; //8位有符号整数
INT16U //16位无符号整数
INT16S //16位有符号整数
INT32U //32位无符号整数
INT32S //32位有符号整数
FP32; //单精度浮点
FP64; //双精度浮点
 #define  FD_H*(FP32*)&HD		//将FD_H定义为HD的浮点指针
 #define  FD_D*(FP32*)&D		//将FD_D定义为D的浮点指针

Then call the corresponding data in the function block.

example:

WD[814] = DW[808] / 21.220677 - FD_D[810];      
 WD[816] = DW[806] / 100 - FD_D[812];        

Unify the pointer definition in each function block, and realize that the data call between different C language function blocks is almost insensitive.

3. C language function block call

insert image description here
insert image description here

insert image description here
In the ladder diagram, the call must be consistent with the type of the software original when creating a new source file.

After we customize the pointer, I suggest mapping it to D0 and M0, which is convenient to write.

The above is only for personal usage habits, if you have free time to write it down, if you have any ideas, welcome to put forward

Guess you like

Origin blog.csdn.net/canmianlaida/article/details/126238992