Communication between TwinCAT and Bus Terminal Controller







Communication between TwinCAT and Bus Terminal Controller

 
BECKHOFF Fieldbus Components: Programming

Communication between TwinCAT and Bus Terminal Controller

It makes sense to define a data structure for transferring data between TwinCAT and Bus Terminal Controller. Please note the following to account for the differences in data management on the two systems.

  • If two different data types are sent in sequence (e.g. byte and INT), the following variable is set to the next even address offset
  • Boolean variables should never be allocated individually within a structure, since they would invariably occupy 1 byte. Boolean expressions should always be masked in a byte or word.
Example 1: Structure on the BX and on the PC
VariableBX memory PC memory (TwinCAT)
Byte%..B0%..B0
INT (1)%..B2%..B1
INT (2)%..B4%..B3

Because the first byte is followed by a different variable type (INT), it was set to the next free even address in the BX/BCxx50. In order to achieve the same data structure on both systems, a dummy byte has to be inserted in the PC project (see example 2).

Example 2: Structure on the BX and on the PC with identical memory allocation
VariableBX memory PC memory (TwinCAT)
Byte%..B0%..B0
Byte
(Dummy)
%..B1 (not necessarily required, since the system deals with this itself if the variable does not exist)%..B1
INT (1)%..B2%..B2
INT (2)%..B4%..B4
Data structure

Type PB_Data
STRUCT
    wVar_1:WORD;
    iValue_1:INT;
    iValue_2:INT;
    iValue_3:INT;
END_STRUCT
END_TYPE

Creating a variable structure

VAR_Global
    strData_Out AT %QB1000:PB_Data; (*PLC Variables *)
    bInput_01 AT %IX0.0:BOOL; (* Input from a terminal *)
END_VAR

Small programming example

strData_Out.wVar_1.0:=bInput_01;

NoteA mixed data structure should not contain any Real values. If it does, the High and Low word must be swapped in the BX/BCxx50or in the TwinCAT master project. It is better to use an array of Real values or to transfer the Real values individually.
NoteIt is also possible to transfer larger fieldbus data blocks, in order to leave a reserve for your structure. Disadvantage: These reserves are then transferred with each fieldbus telegram, causing additional load for the fieldbus communication.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值