BC9050, BC9020, BC9120 - Bus Terminal Controller for Ethernet

BECKHOFF Fieldbus Components

Documentation for

BC9050, BC9020 and BC9120

Bus Terminal Controller for Ethernet

Version: 1.0.0
Date: 2008-05-14

First steps - fast entry


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.
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.


Safety Instructions

Safety Rules

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.

State at Delivery

All the components are supplied in particular hardware and software configurations appropriate for the application. Modifications to hardware or software configurations other than those described in the documentation are not permitted, and nullify the liability of Beckhoff Automation GmbH.

Personnel Qualification

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.

Description of safety symbols

The following safety symbols are used in this operating manual. They are intended to alert the reader to the associated safety instructions.

Danger This symbol is intended to highlight risks for the life or health of personnel.

Warning This symbol is intended to highlight risks for equipment, materials or the environment.

Note This symbol indicates information that contributes to better understanding.


BC9xx0 - Documentation issue status

BECKHOFF BC9xx0: Foreword

Documentation issue status

Version | Comment
1.0.0 | First version

Firmware BC9050

Firmware | Comment
B0 | First version

Firmware BC9020

Firmware | Comment
B0 | First version

Firmware BC9120

Firmware | Comment
B1 | First version


BC9050 - Principle of the Bus Terminal

BECKHOFF BC9050: 产品概述

总线端子原理

BC9050


BC9020, BC9120 - Principle of the Bus Terminal

BECKHOFF BC9020, BC9120: 产品概述

总线端子原理

BC9020, BC9120


BC9xx0 - Technical data - Bus Terminal Controller

BECKHOFF 现场总线控制器: 产品概述

技术数据 - 总线端子控制器

技术数据 | BC9050 | BC9020 | BC9120
处理器 | 16 bit micro-controller
诊断LED | 2 x power supply, 2 x K-bus, 4 x bus and status LEDs
组态和编程软件 | TwinCAT 2.10 starting with build 1322 or higher
现场总线接口 | BC9050 | BC9020 | BC9120
现场总线 | Ethernet
接口 | BC9050 | BC9020 | BC9120
Terminal Bus (K-Bus) | 64 (255 with K-bus extension)
技术数据 | BC9050 | BC9020 | BC9120
数字量外围信号 | 2040 输入/输出
模拟量外围信号 | 512 输入/输出
配置 | 通过 TwinCAT 或 控制器内部
最大字节数, fieldbus | 由现场总线决定
最大字节数, PLC | 2048 字节输入， 2048 字节输出
现场总线连接 | RJ45 | RJ45 | 2 x RS45 switch
电源 (Us) | 24 VDC (-15%/+20%)
输入电流 (Us) | 65 mA + (total K-Bus current)/4 | 85 mA + (total K-Bus current)/4 | 90 mA + (total K-Bus current)/4
启动电流 (Us) | approx. 2.5 x continuous current
K-bus 电流 (5 V) | maximum 1000 mA | maximum 1750 mA | maximum 1750 mA
电源触点电压 (上限) | max. 24 VDC (-15%/+20%)
电源触点电流负载 (上限) | max. 10 A
电介质强度 | 500 Veff (power contact / supply voltage / fieldbus)
重量 |
尺寸 (W x H x D) |
工作温度e | 0°C... +55°C
储存温度 | -25°C... +85°C
相对湿度 | 95％无冷凝
抗振/抗冲击性能 | 符合 EN 60068-2-6 / EN 60068-2-27, EN 60068-2-29
EMC的抗爆裂/静电放电 | 符合 EN 61000-6-2 / EN 61000-6-4
安装位置 | 任意
防护等级 | IP20
机械数据 | BC9050 | BC9020 | BC9120
安装 | on TS35 with lock
安装位置 | any
连接截面 | 0.08 mm² .. 2.5 mm² AWG 28-14 8-9 mm strip length


BC9xx0 - Technical data - PLC

BECKHOFF 总线端子控制器: 产品概述

技术数据 - PLC

PLC data | BC9050 | BC9020 | BC9120
编程 | 通过编程口或现场总线接口
程序内存 | 48 kbyte | 128 kbyte | 128 kbyte
源代码内存 | 128 kbyte | 256 kbyte | 256 kbyte
数据内存 | 32 kbyte | 128 kbyte | 128 kbyte
Remanent 数据 | 2 kbyte
Persistent 数据 | 1000 byte
PLC的周期时间 | approx. 0,85 ms for 1000 IL commands (without I/O cycle)
编程语言 | IEC 6-3 (IL, LD, FBD, ST, SFC)
Run time | 1 PLC task
在线调试 | Yes
上传/下载代码 | Yes/Yes


BC9xx0 - DIP switch

BECKHOFF总线端子控制器: 编程

DIP 开关

BC9050 和 BC9120/BC9020 有一个DIP开关. 该DIP 开关有两个功能。
1. 设置IP地址或编址模式。
2. 设置模式。

如果总线端子模块连到K-bus上并且总线端子控制器工作，模式1被激活。如果只接入终端端子模块并且总线端子控制器工作时模式2被激活。

模式1 编址模式

BC9050 DIP开关设置

开关打在右边是On，打在左边是Off。
DIP开关1-8修改IP地址的最后一个字节（下图中红色DIP开关）。 DIP开关1-2选择IP地址模式 （下图中蓝色DIP开关）。

DIP 1 | DIP 2 | Meaning
off | off | 172.16.21.xxx (xxx 对应 DIP开关 1-8), 子网掩码 255.255.0.0, 缺省网关 0.0.0.0
on | off | BootP (DIP 1-8 全Off), BootP & Safe (DIP 1-8 全On)
off | on | DHCP
on | on | 通过System Manager配置

BC9020 and BC9120 DIP switches

开关打在右边是On，打在左边是Off。
DIP开关1-8修改IP地址的最后一个字节 （下图中红色DIP开关）。 DIP开关9-10选择IP地址模式 （下图中蓝色DIP开关）。

DIP 9 | DIP 10 | Meaning
off | off | BC9020 172.16.22.xxx (xxx 对应 DIP 开关 1-8), 子网掩码 255.255.0.0, 缺省网关 0.0.0.0 BC9120 172.16.23.xxx (xxx 对应 DIP 开关 1-8), 子网掩码255.255.0.0, 缺省网关 0.0.0.0
on | off | BootP (DIP 1-8 全 Off), BootP & Safe (DIP 1-8 全 On)
off | on | DHCP
on | on | 通过System Manager配置

模式2 配置模式

断电状态下总线端子控制器只连接KL9010终端模块。将DIP开关设置到所需功能，然后接通总线端子控制器。一旦控制器启动设置的功能将会激活。之后将如常工作。 在 BC9020 和 BC9120中DIP开关9和10必须设为off，在 BC9050中 DIP开关 1和2 (2-pin DIP 开关) 也必须设为off。

Setting |  | Meaning
BC9050 | BC9020 BC9120
99 | 99 | 出厂设置
98 | 98 | 删除启动项目
97 | 97 | 删除 TwinCAT 配置
99 DIP switches
DIP 1
ON 		DIP 2
ON 		DIP 3
OFF 		DIP 4
OFF 		DIP 5
OFF 		DIP 6
ON 		DIP 7
ON 		DIP 8
OFF
98 DIP switches
DIP 1
OFF 		DIP 2
ON 		DIP 3
OFF 		DIP 4
OFF 		DIP 5
OFF 		DIP 6
ON 		DIP 7
ON 		DIP 8
OFF
97 DIP switches
DIP 1
ON 		DIP 2
OFF 		DIP 3
OFF 		DIP 4
OFF 		DIP 5
OFF 		DIP 6
ON 		DIP 7
ON 		DIP 8
OFF


Bus Terminal Controller - IP address - overview

BECKHOFF 总线端子控制器:参数化和调试

IP 地址 - 概述

IP地址可以通过四种不同的方法进行设置，这些将在下面详细描述 。

BX9000: 常用的地址设置方法是使用导航开关和显示,或者使用TwinCATConfig来配置的。

方法 | 说明 | 必要的组件
Manual | Addressing via the navigation switch (only BX9000) | none
TwinCAT | Addressing via TwinCAT system manager | PC with network and TwinCAT
BootP* | Addressing via BootP server | BootP server
DHCP* | Addressing via DHCP server | DHCP server
Local IP address* | Locale IP address | if no BootP or DHCP server answers or is available

*) BX9000 from firmware version 1.20


Overview

BECKHOFF 现场总线组件:参数化和调试

概述

组态类型

在总线端子控制器 BCxx50, BCxx20 和 BXxx00中有两种不同的组态： DEFAULT CONFIG 和TWINCAT CONFIG.

DEFAULT-CONFIG

总线端子按它们插入的顺序进行映射，例如： 先排复杂性端子模块，后跟数字量端子模块。

复杂的总线端子映射如下：

  • 按字排列
  • 复杂型表示
Attention 如果添加或移除端子，过程映像将改变！

现场总线从站接口的数据被称为PLC variables。PLC variables地址从 %QB1000 和 %IB1000处开始。

此外，DEFAULT-CONFIG 可以在没有PLC程序的情况下用于写入或测试总线端子。为此在 System Manager中必须扫描总线端子控制器并且必须激活FreeRun操作模式。 (使用此功能总线端子控制器中不能有任何PLC程序)。

TWINCAT-CONFIG

在TWINCAT-CONFIG(TC-file required)中，总线端子和PLC变量可以被自由连接。该配置通过System Manager 和 ADS传输到耦合器。

TwinCAT Config的要求如下：

  • Via the fieldbus (PROFIBUS, CANopen, Ethernet)
    PROFIBUS: (BC3150, BX3100)
    - PC with FC310x from version 2.0 and TwinCAT 2.9 build 1000
    - BX3100 with firmware from 0.28 with CIF60 or CP5412
    - TwinCAT 2.9 build 946
    (WARNING: only one ADS communication is permitted with the Hilscher PROFIBUS cards, i.e. either System Manager or PLC Control)
    CANopen: (BC5150, BX5100)
    - PC with FC510x from version 1.76 or higher and TwinCAT 2.9 build 1030
    DeviceNet: (BC5250, BX5200)
    - on request
    Ethernet: (BC9050, BC9020, BC9120, BX9000):
    - TwinCAT 2.10 Build xxxx
  • Via serial ADS TwinCAT 2.9 build 1010 for NT4.0, 2000 or XP
    - BX3100 version 1.00
    - BX5100 version 1.00
    - BX5200 version 1.10
    - BX8000 version 1.00
    - BC3150, BC5150, BC5250, BC9050, BC9020, BC9120 from Firmware B0
    - BC8150 TwinCAT 2.10 Build 1244

BCxx50 和 BXxx00 可以通过TwinCAT System Manager来设置参数。

  • Variable I/O mapping
  • Type-specific PROFIBUS data (only BC3150 or BX3100)
  • RTC (Real Time Clock) (only BX-controller)
  • SSB bus (Smart System Bus) (only BX-controller)
  • PLC settings
  • K-Bus settings

该配置可以通过现场总线ADS协议或串口ADS协议传输到BCxx50 或BXxx00 中。

TwinCAT 配置可用于连接变量, I/O和数据。以下是可能的：

  • PLC - K-BUS
  • PLC - fieldbus (e.g. PROFIBUS slave interface)
  • K-Bus - fieldbus (only the BX-Controller)
  • Support of TwinSAFE terminals (only BX-Controller from Firmware 1.17)

此外，TwinCAT配置可以对特殊事件设置参数， 例如在现场总线发生错误时数据是被保留还是被设为 "0" 。
实时时钟可以通过system manager中选项卡来设置。

Individual steps
  1. Setting the fieldbus address
  2. Opening the system manager and creating a TC-file
  3. Configuring fieldbus data in the TC-file
  4. Saving the TC-file
  5. Opening a new system manager, creating a PC file and reading in saved TC-file
  6. Creating a link to a PLC task
  7. Saving the configuration
  8. Starting the TwinCAT system
  9. Opening the system manager for the TC-file, completing the configuration and transferring it to the BCxx50, BCxx20 or BXxx00
  10. Transferring the program to the BCxx50, BCxx20 or BXxx00
  11. Creating a boot project


Bus Terminal Controller - Creating a TwinCAT configuration

BECKHOFF 现场总线组件: 参数化和调试

创建一个TwinCAT 配置

为了配置一台BCxx50, BCxx20 或 BXxx00系列的总线端子控制器，必须在System Manager中创建一个 BX 文件。为了简化，基本的单位的文件已经准备就绪。通过 New from Template打开各自的Bx的控制器。

选择相关Bx的控制器。

现在所有的BX控制器组件都已可用。

  • Fieldbus interface
  • K-Bus Interface
  • PLC Program
  • SSB (only BX-Controller)

请参阅设备配置的有关章节。


Bus Terminal Controller - Uploading a TwinCAT Configuration

BECKHOFF 现场总线组件: 参数化和调试

上传TwinCAT配置

通过ADS协议将 TwinCAT组态从总线端子控制器中读出。

串口 ADS 协议

(BCxx50, BCxx20 和 BXxx00 系列所有的总线端子控制器)

输入串口ADS 连接, 如 Serial ADS章节所述。

ADS 协议 通过 fieldbus

(仅BC3150, BC5150, BC9x20, BC9050, BX3100, BX5100, BX9000)

前提是，作为主站和用于数据交换的操作是激活的 i.e. 物理和PROFIBUS, CANopen 配置必须被完成, 并且数据必须是从主站(e.g. Fieldbus card)发送到总线端子控制器。

选择目标系统

选择你想上传配置的总线端子控制器。 F8 打开相关设备对话框用于下载。

选择相关的总线端子控制器。

该设备状态 (Bus Terminal Controller) 显示在 System Manager右下角。

单击红色的文件夹。 现在TwinCAT配置将被上传。


Measuring the PLC Cycle Time

BECKHOFF 总线端子控制器:参数化和调试

测量 PLC 的周期时间

任务时间在PLC Control中设置。 默认设置是20 ms。

默认设置下，PLC程序每20ms执行一次，一般程序实际执行的时间总是小于20ms的。可以在System Manager 中测量周期时间，从而确定您的系统负载。为了确保可靠运行，可以将任务时间设置的比测定的周期时间长 20 到30 % 。 精确的周期时间故障在 K-Bus tab 有所描述。


BC9xx0 - PLC features

BECKHOFF 总线端子控制器: 编程

PLC 特性

BC9050

说明 | 数值
数据内存 | 32 kbyte
程序内存 | 48 kbyte minus task-configuration minus POUs during online change
源代码内存 | 128 kbyte
RETAIN | 2 kbyte
持久性数据 | 1000 byte
INPUT | 2 kbyte
OUTPUT | 2 kbyte
FLAG | 4 kbyte
最大变量数 | 16 kbyte
Max. POUs | 由内存大小决定

BC9020

说明 | 数值
数据内存 | 128 kbyte
程序内存 | 128 kbyte minus task-configuration minus POUs during online change
源代码内存 | 256 kbyte
RETAIN | 2 kbyte
持久性数据 | 1000 byte
INPUT | 2 kbyte
OUTPUT | 2 kbyte
FLAG | 4 kbyte
最大变量数 | 16 kbyte
Max. POUs | 由内存大小决定

BC9120

说明 | 数值
数据内存 | 128 kbyte
程序内存 | 128 kbyte minus task-configuration minus POUs during online change
源代码内存 | 256 kbyte
RETAIN | 2 kbyte
持久性数据 | 1000 byte
INPUT | 2 kbyte
OUTPUT | 2 kbyte
FLAG | 4 kbyte
最大变量数 | 16 kbyte
Max. POUs | 由内存大小决定


TwinCAT PLC error codes

BECKHOFF 总线端子控制器: 编程

TwinCAT PLC 错误代码

错误类型 | 说明
PLC 编译错误 | Maximum number of POUs (...) exceeded
PLC 编译错误 | Out of global data memory ...

POUs 错误

对于每个块均创建一个 POU (过程对象单元) 。默认可用256个块。

如果库被整合，该值可能就不再足够。 在这种情况下，POUs的数量应该增加。

为此，请在PLC Control下Projects/Options中打开控制器设置。

这些设置不能在线更改。

全局内存错误

默认2 × 16 KB的数据可用。如果要使用大量的数据，这个范围内应该增加。对于BX，最大可有14个数据段。


Bus Terminal Controller - Remanent data

BECKHOFF Bus Terminal Controller: Programming

Remanent 数据

BX控制器有2000 Byte 的 remanent 数据可用。在PLC Control中这样声明：VAR RETAIN 。

例

VAR RETAIN
Test :BOOL;
Count :INT;
END_VAR

Retain 数据定义位置在 VAR RETAIN 和 END_VAR 之间。 这些数据会保存到 2kB大小的NOVRAM 中。RETAIN 在每次PLC循环后即存入NOVROM 中，对于2KB的数据需要任务时间为2ms（1KB为11ms）。这些变量可以定义为局部或全局变量，但指定为IO型的变量（%I...,%Q...,%M...）不能用作Retain数据。

Note VAR_RETAIN 不能用做功能块。否则所有功能块数据会复制到retain 内存中，这样会增加很多不必要的PLC循环时间以及Retain内存占用。
Note 指定为IO地址(%I...,%Q.., %M...)的变量不能声明为 retain 型变量。

功能块中使用 remanent 数据的例子

由于在功能块中即使只使用一个 remanent 数据也会将功能块中所有数据做保存，所以应该避免这种情况。下面是这样的一个例子程序。

Function block Test (no program code required - in ST a semicolon is sufficient)

FUNCTION_BLOCK Test

VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
VAR_IN_OUT
Counter :INT;
END_VAR

MAIN program

PROGRAM MAIN

VAR
fb_Test:Test;
END_VAR
VAR RETAIN
iCounter1:INT;
END_VAR

fb_Test(Counter:=iCounter1);


Bus Terminal Controller - Persistent data

BECKHOFF Bus Terminal Controller: Programming

Persistent 数据

总线端子控制器中可以使用 1000 Byte 的Persistent数据。
与Retain数据不同处在于，建立一个新的Project，Reset PLC或下载一个新程序都不会删除persistent数据。

若要使用 persistent 数据，首先要执行一个功能块将它激活。

然后，要将变量写到分配的标记内存区。
总共有 4 kByte 的标记内存区可用，你可以声明其中的 1 kByte为persistent 。

例子

VAR
Test AT %MX1000 :BOOL;
Count AT %MB1002 :INT;
END_VAR

Persitent_Data 功能块中可以指定 persistent 数据的起始地址和字节长度。

WriteOffset 变量指定了地址偏移，WriteSize 变量指定了字节长度。

该功能块包含在 TcSystemBX 库中。如果没有的话，请查看相应文档 (see libraries).

例子

WriteOffset 1000
WriteSize 10

说明在标记区%MB1000 - %MB1009 都是 persistent 变量。

与 retain 变量一样，persistent 变量也会复制到 NOVRAM 中。每个PLC循环写一次。

Note 每次必须写一次数据。数据会永久保存。
如果重新激活工厂设定值，则所有persistent 数据都会被删除。
Example program

点击符号 [image] 下载相关程序示例。


Allocated flags

BECKHOFF Bus Terminal Controller: Programming

标记地址分配

有4k byte 的标记地址可以分配。它们可以对一个地址分配不同的变量类型，例如，可用作字符串转换为Byte型。这些数据也可以通过ADS功能进行读写。

Note BX 控制器不能将分配了地址的变量再定义为 remanent 数据。

通过ADS读写分配了地址的标记变量

在PROFIBUS中可以通过ADS读写标记变量，我们可以使用DPV1的服务来实现。在CANopen中可以通过SDO通讯来实现。
AmsNetId 可以在System Manager中找到，或在BX控制器的液晶显示菜单里找到。
PLC port 号是 800.

Index group | Meaning | Index offset (value range)
0x4020 | Flag (only BXxxx0) | 0..4096
例子

BX program

VAR
Flag_01 AT %MB0: WORD;
END_VAR

TwinCAT PC/CX Master Programm

VAR
fbADRSREAD: ADSREAD;
Flag_M: WORD;
END_VAR

fbADRSREAD(
NETID:='172.16.3.0.2.3' ,  (* AMSNetId BX *)
PORT:=800 ,                (* 800 - PLC *)
IDXGRP:=16#4020 ,          (* 0x4020hex
flags *)
IDXOFFS:=0 ,               (* byte offset *)
LEN:=2 ,                   (* Lenght byte *)
DESTADDR:=ADR(Merker) ,
READ:=TRUE ,
TMOUT:=t#1s  );
IF NOT fbADRSREAD.BUSY THEN
fbADRSREAD(READ:=FALSE);
END_IF


Mapping of the Bus Terminals

BECKHOFF 现场总线组件: 组态

总线端子映射

对面向字节的总线端子进行映射的详细分配，可以在总线端子组态指南中找到。该文档也可在产品的 CD 上或下列的因特网上找到： http://www.beckhoff.com。

面向字节的总线端子 | 面向位的总线端子
KL15x1 | KL10xx, KL11xx, KL12xx, KL17xx, KM1xxx
KL25xx | KL20xx, KL21xx, KL22xx, KL26xx, KL27xx, KM2xxx
KL3xxx |
KL4xxx |
KL5xxx |
KL6xxx |
KL7xxx |
KL8xxx |
 | KL9110, KL9160, KL9210, KL9260


Local process image in the TwinCAT configuration

BECKHOFF 总线端子控制器:编程

TwinCAT配置中的本地进程映像

TwinCAT配置(TwinCAT CONFIG) 使得PROFIBUS / K-Bus / PLC变量之间可以自由映射。通过System Manager ，变量可以独立于它们的地址连接。

I在TwinCAT 配置中， 所有的总线端子均有固定地址。如果插入一个总线端子，整个地址范围可能会改变。 许多数据是不必要的，占据了宝贵的地址内存空间。 TwinCAT 配置纠正了该缺点。 已分配的变量可以与一个总线端子自由连接。参数化在System Manager中执行，然后配置被传输到BX(see TwinCAT configuration)中。


Communication between TwinCAT and Bus Terminal Controller

BECKHOFF 现场总线组件: 编程

TwinCAT和总线端子控制器之间通讯

为了在 TwinCAT和总线端子控制器之间传输数据，定义一个数据结构很有意义。请注意以下内容以确定两个系统上数据管理的差异。

  • 如果依次发送两个不同类型的数据（如 byte 和 INT），跟在后面的变量设置为偶数的地址偏移
  • 布尔变量永远不应单独地分配到一个结构中，因为他们总是会占用1个字节。布尔表达式应始终隐藏在一个字节或字中。
Example 1: Structure on the BX and on the PC
Variable | BX memory | PC memory (TwinCAT)
Byte | %..B0 | %..B0
INT (1) | %..B2 | %..B1
INT (2) | %..B4 | %..B3

由于第一个Byte后面跟了一个不同类型（INT），这样它的地址自动被设为下一个偶数地址。 为了在两个系统上实现同样的数据结构，需要将一个虚拟字节插入PC项目中 (详见 example 2)。

Example 2: Structure on the BX and on the PC with identical memory allocation
Variable | BX 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

数据结构

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

创建一个变量结构

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

小的编程示例

strData_Out.wVar_1.0:=bInput_01;

Note 一种混合型数据结构不应包含任何实值。如果包含，在 BX/BCxx50中或在 TwinCAT 主站中高字和低字必须交换。 最好是使用一个实型的数组或单独传输实数。
Note 为了给你的结构留出储备，传输大的现场总线数据功能块也是可以的。 缺点： 这些储备与各现场总线报文随后被传输，导致现场总线通讯负荷增加。


BC9xx0 - Libraries overview

BECKHOFF Bus Terminal Controller: Programming

Libraries overview

The TwinCAT Automation Software offers various libraries for the BC9xx0 series Bus Terminal Controllers (Bus Coupler with PLC functionality) (see Beckhoff information system).

Download

The libraries are also included in this documentation. For extracting the libraries, click on the disk icon with the left mouse button and copy the libraries into the directory TwinCAT\PLC\LIB.

  • Standard
  • TcSystemBCxx50 [image] TcSystemBCxx50 requires the TcBaseBCxx50 library.
  • TcBaseBCxx50
  • ChrAscBX.lbx
Note Always use the latest libraries in conjunction with the latest BC firmware. If you update the firmware of your Bus Terminal Controller, please also update the libraries. Copy the new libraries into the LIB folder, remove them from your project and re-insert them.

TcSystemBCxx50

ADS | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
ADSREAD |  | B0 | B0 | B1 | - | -
ADSWRITE |  | B0 | B0 | B1 | - | -
ADSRDWRT |  | B0 | B0 | B1 | - | -
ADSWRTCTL |  | B0 | B0 | B1 | - | -
ADSRDSTATE |  | B0 | B0 | B1 | - | -
ADSRDDEVINFO |  | B0 | B0 | B1 | - | -
Bit Functions | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
CLEARBIT32 |  | B0 | B0 | B1 | - | -
CSETBIT32 |  | B0 | B0 | B1 | - | -
GETBIT32 |  | B0 | B0 | B1 | - | -
SETBIT32 |  | B0 | B0 | B1 | - | -
Controller | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
FB_BasicPID | - | B0 | B0 | B1 | - | -
- | - | - | - | - | - | -
File Access | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
FB_ReadFromFile |  | - | - | - | - | -
FB_WriteToFile |  | - | - | - | - | -
FB_ReadWriteFile |  | - | - | - | - | -
Memory Functions | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
MEMCMP |  | B0 | B0 | B1 | - | -
MEMCYP |  | B0 | B0 | B1 | - | -
MEMMOVE |  | B0 | B0 | B1 | - | -
MEMSET |  | B0 | B0 | B1 | - | -
NOVRAM Functions | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
- | - | - | - | - | - | -
SFC | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
AnalyzeExpression |  | - | - | - | - | -
AppendErrorString |  | - | - | - | - | -
SFCActionControl |  | - | - | - | - | -
System / Time / TBus | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
DRAND |  | B0 | B0 | B1 | - | -
SYSTEMTIME_TO_DT |  | B0 | B0 | B1 | - | -
DT_TO_SYSTEMTIME |  | B0 | B0 | B1 | - | -
GetSysTick |  | B0 | B0 | B1 | - | -
PresetSysTick |  | B0 | B0 | B1 | - | -
Reboot |  | B0 | B0 | B1 | - | -
Debug | Version | Firmware
 |  | BC9050 | BC9020 | BC9120 | - | -
F_ReadDebugTimer |  | B0 | B0 | B1 | - | -
F_StartDebugTimer |  | B0 | B0 | B1 | - | -


Libraries for BX9000, BC9050, BC9120, BC9020 - Overview

Special Function Blocks for the BX9000, BC9020, BC9050 and BC9120 Bus Terminal Controller.

Download

For downloading libraries please left-click on the disk icon. Please copy the libraries to folder TwinCAT\PLC\LIB.

  • TcBaseBX9000
Note The latest firmware requires the latest library. If you update your BX Controller, please also change the libraries.
Copy copy the libraries to folder TwinCAT\PLC\LIB. Then remove these libraries from your project and reinsert them again.

TcBaseBX9000

Services | Version | Firmware
 |  | BX9000 | BC9020 | BC9050 | BC9120
FB_AddDnsServer | 30.05.06 | 1.12 | B0 | B0 | B1
FB_GetHostByAddr | 30.05.06 | 1.12 | B0 | B0 | B1
FB_GetHostByName | 30.05.06 | 1.12 | B0 | B0 | B1
FB_GetNetworkConfig | 30.05.06 | 1.12 | B0 | B0 | B1
FB_SetTargetName | 30.05.06 | 1.12 | B0 | B0 | B1
SMTP | Version | Firmware
 |  | BX9000 | BC9020 | BC9050 | BC9120
FB_SMTP | 30.05.06 | 1.12 | B0 | B0 | B1
SNTP | Version | Firmware
 |  | BX9000 | BC9020 | BC9050 | BC9120
FB_SNTP | 30.05.06 | 1.12 | B0 | B0 | B1
IP-TCP/IP-UDP | Version | Firmware
 |  | BX9000 | BC9020 | BC9050 | BC9120
FB_AddMultiRoute | 26.09.06 | 1.14 | B0 | B0 | B1
FB_DelMultiRoute | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpClose | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpEndSession | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpOpen | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpReceive | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpSend | 26.09.06 | 1.14 | B0 | B0 | B1
FB_IpStartSession | 26.09.06 | 1.14 | B0 | B0 | B1
ModbusTCP | Version | Firmware
 |  | BX9000 | BC9020 | BC9050 | BC9120
FB_MBClose | 26.09.06 | 1.14 | B0 | B0 | B1
FB_MBConnect | 26.09.06 | 1.14 | B0 | B0 | B1
FB_MBGenericReq | 26.09.06 | 1.14 | B0 | B0 | B1


Libraries - System Task Info

BECKHOFF Bus Terminal Controller: Programming

System Task Info

VAR_GLOBAL
    SystemTaskInfo 	:  SYSTEMTASKINFOTYPE;
END_VAR

System flags are implicitly declared variables. Using the Input Assistant, a variable SystemTaskInfoArr can be found under system variables. This variable is a field with four structures of type SYTEMTASKINFOTYPE. The structure definition can be found in the system library. The index in this field is the task ID.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.9.0 | BCxx50 Controller | TcBaseBCxx50.lbx


Libraries - System Task Info Type

BECKHOFF Bus Terminal Controller: Programming

System task info type

TYPE SYSTEMTASKINFOTYPE
STRUCT
    active			:	BOOL;
    taskName			:	STRING(16);
    firstCycle		:	BOOL;
    cycleTimeExceeded		:	BOOL;
    cycleTime			:	UDINT;
    lastExecTime		:	UDINT;
    priority			:	BYTE;
    cycleCount		: 	UDINT;
END_STRUCT
END_TYPE
Key

active: This variable indicates whether the task is active.
taskName: the task name.
firstCycle: during the first PLC task cycle, this variable has the value TRUE.
cycleTimeExceeded: this variable indicates whether the set task cycle time was exceeded.
cycleTime : set task cycle time in multiples of 100 ns.
lastExecTime: cycle time required for the last cycle in multiples of 100 ns.
priority: set task priority.
cycleCount: cycle counter.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.9.0 | BCxx50 Controller | TcBaseBCxx50.lbx


Libraries - System Info

BECKHOFF Bus Terminal Controller: Programming

System Info

VAR_GLOBAL
    SystemInfo     : SYSTEMINFOTYPE;
END_VAR

System flags are implicitly declared variables. Using the Input Assistant, a variable System Info can be found under system variables. The type SYSTEMINFOTYPE is declared in the system library. For accessing the variable, the system library has to be integrated in the project.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.9.0 | BCxx50 Controller | TcBaseBCxx50.lbx


Libraries - System Info Type

BECKHOFF Bus Terminal Controller: Programming

System Info Type

TYPE SYSTEMINFOTYPE
STRUCT
    runTimeNo		:	BYTE;
    projectName		:	STRING(32);
    numberOfTasks		:	BYTE;
    onlineChangeCount		:	UINT;
    bootDataFlags		:	BYTE;
    systemStateFlags		:	WORD;
END_STRUCT
END_TYPE
Key

runTimeNo: specifies the number of the runtime system (1).
projectName: project name as STRING.
numberOfTasks: number of tasks contained in the runtime system (max. 1).
onlineChangeCount: number of online changes since the last complete download.
bootDataFlags: Reserved
systemStateFlags: Reserved

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.9.0 | BCxx50 Controller | TcBaseBCxx50.lbx


BX Controller - Local ADS port numbers - Overview

BECKHOFF BX Controller: Programming

Local ADS port numbers - Overview

Port number | Description
100 dec | Reading and writing of registers and tables from the coupler and the complex Bus Terminals
150 dec | Reading and writing of RTC (real-time clock)
153 dec | SSB - reading of the emergency message
800 dec | Local PLC process image, see Port 801
801 dec | Local PLC process image, see Port 800
0x1000 + Node ID | SSB - SDO communication with CANopen node (slave number)


ADS services

BECKHOFF 总线端子控制器: 编程

ADS 服务

本地进程映像PLC 任务1 端口800/801

数据可以从本地进程映像中读取，也可以写入本地进程映像。如果有必要将输出写入，确保它们没有被本地PLC使用是非常重要的，因为本地控制器将覆盖这些值。该数据与看门狗无关，因此不能做为在有故障事件中必须被关闭的输出量。

Index group | Meaning | Index offset (value range)
0xF020 | Inputs | 0...2047
0xF021 | Bit inputs | 0...16376
0xF030 | Outputs | 0...2047
0xF031 | Bit outputs | 0...16376
0x4020 | Flags | 0...4095
0x4021 | Flag bit | 0...32760

ADS 服务

AdsServerAdsState
Data type (read only) | Meaning
String | Start - the local PLC is running Stop - the local PLC is stopped
AdsServerDeviceState
Data type (read only) | Meaning
INT | 0 – Start - the local PLC is running 1 – Stop - the local PLC is stopped
AdsServerType
Data type (read only) | Meaning
String | BX PLC Server
ADSWriteControl
Data type (write only) | Meaning
NetID | Net ID of the BX9000
Port | 800
ADSSTATE | 5 - RUN / 6 - STOP
DEVSTATE | 0
LEN | 0
SRCADDR | 0
WRITE | rising edge starts the block
TMOUT | for example: t#1000ms

寄存器访问端口 100

在BX系列的总线端子控制器上和BCxx50上，用于与寄存器通讯的ADS端口号是固定的，为100。

Index group | Index offset (value range) |  | Meaning
 | Hi-Word | Low Word
0 [READ ONLY] | 0...127 | 0...255 | Registers in the Bus Coupler High word, table number of the Bus Coupler Low word, register number of the table
1...255 | 0...3 | 1...255 | Register of the Bus Terminal High word, channel number Low word, register number of the Bus Terminal
Note 但读取寄存器时，ADS功能块的超时设置必须要长于一秒。
Note 当写入寄存器时，必须要设置密码 (详见特定总线端子文档)。


BX Debug Function - Overview

These functions can be used for measuring command execution times in a PLC project. The unit is a tick. One tick corresponds to 5.12 µs.

Start Debug Timer function

Calling this function starts the timer. The return value is "0".

Read Debug Timer function

This function reads the timer value. The return value has to be multiplied with 5.12 µs.

Example

VAR
Timer_BX :WORD;
i :INT;
END_VAR

Program

F_STARTDEBUGTIMER();
For i:=0 to 1000 do
;
END_FOR
Timer_BX:=F_READDEBUGTIMER();


Overview: Socket Interface

The socket interface can be used for receiving any Ethernet telegrams or for sending telegrams from the controller. In this way any PLC layer protocols can be programmed in IEC 61131-3.

Supported Ethernet protocols

Type | STREAM | DGRAM | RAW
IP | n.i. | n.i. | n.i.
ICMP | n.i. | n.i. | n.i.
IGMP | n.i. | n.i. | n.i.
TCP | from V1.14 | n.i. | n.i.
UDP | n.i. | from 1.14 | n.i.
RAW | n.i. | n.i. | n.i.

Table 1
n.i. not implemented

Operating principle of a socket-connection

Before a socket can be opened resources for this type of connection must be made available to the controller. This is done by starting a session for specifying the scope. The session can then be used for sending or receiving Ethernet telegrams. The implemented protocols are listed in Table 1.

Client-server relationship

A client is defined as a device that intends to establish a connection and initializes the active part of a connection setup. The server is initially passive and awaits a client query. The server becomes active once a client establishes a connection. Once a connection between client and server has been established, both devices can sending or receive data.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9000 (165) firmware version >=1.14 | TcBaseBX9000.lbx


IP block overview

IP-TCP/IP-UDP | Firmware | Description
FB_IpStartSession | 1.14 | Opening a session
FB_IpEndSession | 1.14 | Closing a session
FB_IpOpen | 1.14 | Opening a TCP/IP connection (not required for UDP communication)
FB_IpClose | 1.14 | Closing a TCP/IP connection (not required for UDP communication)
FB_IpReceive | 1.14 | Receiving TCP or UDP telegrams
FB_IpSend | 1.14 | Sending TCP or UDP telegrams
Multicast blocks | Firmware | Description
FB_AddMultiRoute | 1.14 | Creating a muticast address
FB_DelMultiRoute | 1.14 | Deleting a muticast address


FB_IpStartSession

The block allocates resources on the controller for the Ethernet communication. The block becomes active with bStart. As long as the block is busy bBusy is set. iDevice should always be zero. iPort is used for the local TCP or UDP port number. iMaxConnection indicates the maximum number of connections. The maximum value is 3.

INPUT

VAR_INPUT
   bStart		: BOOL;
   iDevice    	: WORD;
   eSocketType	: E_SocketType;
   eSocketProtocol	: E_SocketProtocol;
   iPort		: WORD;
   iMayConnection	: WORD;
   tTimeout	: TIME;
END_VAR

bStart: A rising edge activates the block.

iDevice: always "0"

eSocketType: For TCP/IP "SOCK_STREAM" should be used. Please note that the data are stored as a byte stream. The length of the data to be received should be known or a protocol with a start/end ID should be used so that the start and end can be identified from the data stream. For UDP/IP "SOCK_DGRAM" should be set. A UDP frame always stored in the memory as a complete entity. 4 memories are available. If the data are not read fast enough from the memory of the PLC by the user program further UDP frames are lost.

eSocketProtocol: For TCP/IP "IPPROTO_TCP" should be used, for UDP/IP "IPPROTO_UDP".

iPort: Sender port number

iMaxConnection: Number of possible connections (max. 3)

tTimeout: Time after which the attempt is aborted.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
   iSession	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iSession: Forwards the session number to all IP blocks for which this connection was created.


FB_IpEndSession

The block closes an open session. A positive edge of bStart closes the session and releases resources.

INPUT

VAR_INPUT
   bStart		: BOOL;
   iSession    	: WORD;
END_VAR

bStart: A rising edge activates the block.

iSession: Is linked with the session number from block FB_IpStartSession.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).


FB_IpOpen

The block is required for opening a TCP/IP connection from the PLC controller. In this case is the controller is the client that actively establishes a connection to a TCP/IP server. With a positive edge of bStart a connection to a server with the IP address from sRemoteIpAddr is established. The recipient port number was specified when the session was started (see FB_IpStartSession). The sender port number is issued by the controller and can be read from iPortNo. The sender port number is required for sending (see FB_IpSend). bBusy is set as long set as the block is active. If bBusy is reset and bError is FALSE the TCP/IP connection was terminated successfully and data can be sent or received.

INPUT

VAR_INPUT
   bStart		: BOOL;
   iSession    	: WORD;
   sRemoteIPAddr	: STRING(15);
END_VAR

bStart: A rising edge activates the block.

iSession: Is linked with the session number from block FB_IpStartSession.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
   iPortNo	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iPortNo: TCP port number that was allocated when the TCP/IP connection was opened (local port number).


FB_IpClose

The block is required for closing a TCP/IP connection from the PLC controller. With a positive edge of bStart a connection with the IP address from sRemoteIpAddr is terminated. The block sends a FIN signal and waits for the confirmation of the disconnection. The partner device and the connection must exist and be operational. If bResetConnection is set the block sends a signal to indicate that the connection was terminated but does not wait for confirmation from the other device. bBusy is set as long as the block is active. If bBusy is reset and bError is FALSE the TCP/IP connection was terminated successfully.

INPUT

VAR_INPUT
   bStart			: BOOL;
   iSession    		: WORD;
   sRemoteIPAddr		: STRING(15);
   iPortNo		: WORD;
   bResetConnection	: BOOL;
END_VAR

bStart: A rising edge activates the block.

iSession: Is linked with the session number from block FB_IpStartSession.

sRemoteIPAddr: IP address of the device with which the connection is to be terminated.

iPortNo: Port number of the device with which the connection is to be terminated.

bResetConnection: FALSE: FIN is sent; TRUE: the TCP/IP connection is closed without waiting for acknowledgement from the partner device. In both cases a new Open is required for re-establishing the connection.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).


FB_IpReceive

The block FB_IpReceice enables receiving of UDP or TCP telegrams. Which of the connections is used is specified in FB_IpStartSession. Received data must be stored in a PLC variable.

To this end a pointer to pBuffAddr is required, and the size of the variable has to be entered in cbBuffLen. A positive edge of bValid indicates that the memory contains data or the data of the associated variable are now valid. A positive edge of bClear indicates that the block is ready to receive data again or, if data are still in the buffer they are copied to the variable next.

With TCP in particular you should monitor how many data were received or are still in the buffer. With TCP/IP data are stored as a "stream", i.e. there is no start or end. With UDP, on the other hand, the content of a UDP frame is always stored in its own buffer.

Up to 4 UDP telegrams can be buffered, further UDP telegrams are lost. cbReceive indicates the number of data in bytes copied into the variable. If the buffer contains more data than were read, the number of remaining data is in cbBytesInStream.

sReceiveIPAddr indicates the IP address of the device that has sent data to the Beckhoff controller and the associated port number iReceivePortNo. Both variables are cleared with bClear. sReceiveIPAddr and iReceivePortNo can be used for sending data back to the device via block FB_IpSend.

INPUT

VAR_INPUT
   bClear		: BOOL;
   iSession    	: WORD;
   sRemoteIPAddr	: STRING(15);
   iPortNo	: WORD;
   pBuffAddr	: DWORD;
   cbBuffLen	: WORD;
END_VAR

bClear: A rising edge clears the memory. The block is then ready to receive data again.

iSession: Is linked with iSession from block FB_StartSession.

sRemoteIPAddr: Can be used as filter for approving only a specific IP address.

iPortNo: Can be used as filter for approving only a specific port.

pBuffAddr: With ADR the pointer to the variable is transferred where the data that were received are to be copied.

cbBuffLen: Size of the variable, can be determined with SIZEOF.

OUTPUT

VAR_OUTPUT
   bValid         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
   cbReceive	: WORD;
   cbBytesInStream	: WORD;
   sReceiveIPAddr	: STRING(15)
   iReceivePortNo	: WORD;
END_VAR

bValid: A positive edge change indicates that new data were received, which are contained in the variable that is linked via the pointer pBuffAddr.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

cbReceive: Indicates the number bytes that were copied.

cbBytesInStream: Indicates the data remaining in the memory. This should always be zero. If the value is >0 the variable linked to pBuffAddr is too small. A further read operation is required for obtaining the remaining data.

sReceiveIPAddr: Indicates the IP address of the device that has sent the data. Cleared with positive edge of bClear.

iReceivePortNo: Indicates the port number of the device that has sent the data. Cleared with positive edge of bClear.


FB_IpSend

The block sends data via TCP or UDP. Which of the connections is used is specified in FB_IpStartSession. In pBuffAddr the pointer to the variable containing data for sending is specified via "ADR". cbBuffLen indicates the length of the data. sRemoteIPAddr indicates the IP address to which the data are sent. With iPortNo this is linked with the port number of FB_IpOpen in TCP. With UDP any port number can be used. iPortNo is the sender port number. The block is activated and the data are sent with a rising edge of bStart. bBusy is TRUE as long the block is active. Once the data have been sent bBusy switches to FALSE. bError also remains FALSE. If an error occurs bError is set.

INPUT

VAR_INPUT
   bStart			: BOOL;
   iSession    		: WORD;
   sRemoteIPAddr		: STRING(15);
   pBuffAddr		: DWORD;
   cbBuffLen		: WORD;
END_VAR

bStart: A rising edge activates the block.

iSession: Is linked with the session number from block FB_IpStartSession.

sRemoteIPAddr: IP port number of the device to which data are to be sent.

iPortNo: Sender port number. For TCP the port number from the FB_IpOpen block must be used, for UDP any port number can be used.

pBuffAddr: Pointer to the data to be sent (command: ADR).

cbBuffLen: Length of the data to be sent. The length should always be less or equal the variable to which the pointer of pBuffAddr points (command: SIZEOF)

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrorId	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).


TCP/IP Client

TCP/IP is a connection-oriented communication type (peer-to-peer connection). In this example we illustrate how a connection is established between the Beckhoff controller and a server. The required blocks are FB_IpStartSession, FB_IpOpen, FB_IpSend and optionally FB_IpReceive, FB_IpClose and FB_IpEndSession.

It is advisable to program a step sequence as illustrated in the example below.

In this case the Beckhoff controller is the client and the partner device a TCP server. The server is a VB6 program.

Step 1

FB_IpStartSession

The block allocates resources on the controller for the TCP/IP communication. The block becomes active with bStart. As long as the block is busy bBusy is set. iDevice should always be zero. iPort is used for the local TCP/IP port number. iMaxConnection indicates the maximum number of connections. The maximum value is 3.

INPUT

bStart: A rising edge activates the block.

iDevice: always "0"

eSocketType: For TCP/IP "SOCK_STREAM" should be used. Please note that the data are stored as a byte stream. The length of the data to be received should be known or a protocol with a start/end ID should be used so that the start and end can be identified from the data stream.

eSocketProtocol: For TCP/IP "IPPROTO_TCP" should be used

iPort: Sender port number

iMaxConnection: Number of possible connections (max. 3)

tTimeout: Time after which the attempt is aborted.

OUTPUT

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iSession: Forwards the session number to all IP blocks for which this connection was created.

Step 2

FB_IpOpen

Received data must be stored in a PLC variable. To this end a pointer to pBuffAddr is required, and the size of the variable is specified in cbBuffLen. A positive edge of bValid indicates that the memory contains data or the data of the associated variable are now valid.

INPUT

bClear: A rising edge clears the memory. The block is then ready to receive data again.

iSession: Is linked with iSession from block FB_StartSession.

sRemoteIPAddr: Can be used as filter for approving only a specific IP address.

eSocketProtocol: For TCP/IP "IPPROTO_TCP" should be used

iPort: Local port number

iMaxConnection: Number of possible connections (max. 3)

tTimeout: Time after which the attempt is aborted.

OUTPUT

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iSession: Forwards the session number to all IP blocks for which this connection was created.

Data can be returned as soon as the first data have been received. This functionality is optional and is used in the example.

Example

VB6 program as TCP/IP server [image] Zip file
TwinCAT project as TCP/IP client [image] prx file


TCP/IP Server

TCP/IP is a connection-oriented communication type (peer-to-peer connection). In this example we illustrate how an external connection is established with the Beckhoff controller. The required blocks are FB_IpStartSession, FB_IpReceive and optionally FB_IpSend, FB_IpClose and FB_IpEndSession.

It is advisable to program a step sequence as illustrated in the example below.

The Beckhoff controller acts as server and the partner device as TCP client. The client is a VB6 program.

Step 1

FB_IpStartSession

The block allocates resources on the controller for the TCP/IP communication. The block becomes active with bStart. As long as the block is busy bBusy is set. iDevice should always be zero. iPort is used for the local TCP/IP port number. iMaxConnection indicates the maximum number of connections. The maximum value is 3.

INPUT

bStart: A rising edge activates the block.

iDevice: always "0"

eSocketType: For TCP/IP "SOCK_STREAM" should be used. Please note that the data are stored as a byte stream. The length of the data to be received should be known or a protocol with a start/end ID should be used so that the start and end can be identified from the data stream.

eSocketProtocol: For TCP/IP "IPPROTO_TCP" should be used

iPort: Receiving port number

iMaxConnection: Number of possible connections (max. 3)

tTimeout: Time after which the attempt is aborted.

OUTPUT

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iSession: Forwards the session number to all IP blocks for which this connection was created.

Step 2

FB_IpReceive

Received data must be stored in a PLC variable. To this end a pointer to pBuffAddr is required, and the size of the variable is specified in cbBuffLen. A positive edge of bValid indicates that the memory contains data or the data of the associated variable are now valid.

INPUT

bClear: A rising edge clears the memory. The block is then ready to receive data again.

iSession: Is linked with iSession from block FB_StartSession.

sRemoteIPAddr: Can be used as filter for approving only a specific IP address.

eSocketProtocol: For TCP/IP "IPPROTO_TCP" should be used

iPort: Local port number

iMaxConnection: Number of possible connections (max. 3)

tTimeout: Time after which the attempt is aborted.

OUTPUT

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

iSession: Forwards the session number to all IP blocks for which this connection was created.

Example

VB6 program as TCP/IP client [image] Zip file
TwinCAT project as TCP/IP server [image] prx file


UDP/IP connection

UDP is a very simple Ethernet connection. UDP data are sent without a mechanism for determining whether the telegram has arrived or not. For UDP communication to work the port number on both sides must be known.

The BX9000 controller from Beckhoff sends data to a VB6 program which then returns these data.

Step 1: Preparation of the UDP communication

FB_IpStartSession

The block allocates resources on the controller for the UDP/IP communication. The block becomes active with bStart. As long as the block is busy bBusy is set. iDevice should always be zero. iPort is used for the local UDP port number of the BX9000. iMaxConnection indicates the maximum number of connections. The maximum value is 3. The eSocketType should be set to "SOCK_DGRAM". eSocketProtocol must be set to "IPPROTO_UDP" for UDP communication. tTimeOut is not used for UDP communication. The iSession must be linked with the following FB_IpSend and FB_ipReceive blocks.

Step 2: Sending of UDP frames

FB_IpSend

A UDP frame is sent with a positive edge of bStart. The IP address is described with sRemoteIPAddr and the destination UDP port number with iPortNo. The sender UDP port number was already configured in the FB_IpStartSession. If bBusy is reset by the block the command was executed.

Step 3: Receiving of UDP frames

FB_IpReceive

This block is used for receiving data. When the block is called the block monitors the arrival of UDP frames. Up to 4 UDP frames are buffered, further UDP frames are discarded. sRemoteIPAddr can be used to set up an IP address filter for receiving data only from a certain device. To receive all UDP frames enter an empty string or leave the variable open. If an IP address filter was configured the port number can also be filtered. Simply enter the corresponding port number in variable iPortNo. To receive all UDP data leave the variable open.
If data are received the variable bValid is set to TRUE. The data are now valid. If the value of the variable cbBytesInStream is not zero, the variable linked with the block is too small and data remain in the buffer.

Example program

Example

VB6 program as TCP/IP server [image] Zip file
BX9000 TwinCAT project as TCP/IP client [image] prx file


ModbusTCP Client

Via the ModbusTCP client the BX9000 can establish a connection to a ModbusTCP server. 3 blocks are available. Fb_MBConnect for establishing a TCP/IP connection, FB_MBGenericReq for the sending and receiving of any Modbus functions, and FB_MBClose for closing the TCP/IP connection. The maximum number of simultaneous client connections is 3. The option of closing and re-opening a TCP/IP connection means that the number of ModbusTCP servers that are accessible is almost unlimited.

FB_MBConnect

FB_MBConnect connects the BX9000 with another device via ModbusTCP. A connection is established with rising edge of bExecute. The IP address is set via sIPAddr. The TCP port number to be used is set via nTCPPort (usually set to 502 for ModbusTCP). bBusy is set as long the block is active. If the ModbusTCP connection was initialised successfully bBusy is set to FALSE and the bError flag is FALSE. If the bError flag is TRUE be, the connection attempt has failed and the associated error code is stored in variable nErrId. nHandle must be connected with blocks FB_MBGernericReq and FB_MBClose.

INPUT

VAR_INPUT
   sIPAddr	: STRING(15);
   nTCPPort    	: UINT;
   bExecute	: BOOL;
   tTimeout	: TIME;
END_VAR

sIPAddr: IP address of the ModbusTCP-server (slave device) with which a Modbus connection is to be established.

nTCPPort : ModbusTCP port number, for ModbusTCP usually 502dec.

bExecute: A rising edge activates the block.

tTimeout: Time after which the attempt is aborted.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrId		: WORD;
   nHandle	: UINT;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

nHandle: Handle that must be connected with blocks FB_MBGernericReq and FB_MBClose.

FB_MBGENERICREQ

Block FB_MBGENERICREQ enables sending and receiving of any ModbusTCP functions. With rising edge of bExecute the block becomes active, bBusy is set and the data contained in pReqBuff are sent. The block reads the length of the data to be sent from variable cbReqLen. Variable nHandle must be linked with the variable from block FB_MBOpen nHandle. The response from the ModbusTCP server (slave) is stored in pResBuff. The size of the variable should be adequate for receiving all data of a ModbusTCP telegram. If the ModbusClient does not receive a response within tTimeOut, bBusy is set to FALSE and bError is set. Variable nErrId contains the error code. cbResponse contains the number of received bytes. This number can be compared with the buffer size of cdResLen. If cbResponse is greater than dResLen data are lost and a larger buffer should be chosen.

INPUT

VAR_INPUT
   nHandle	: UINT;
   pRecBuff	: DWORD;
   cbReqLen    	: WORD;
   pResBuff	: DWORD;
   cbResLen	: WORD;
   bExecute	: BOOL;
   tTimeout	: TIME;
END_VAR

nHandle: Handle - linked with blocks FB_MBOpen.

pReqBuff: Pointer to the data to be sent.

cbReqLen: Length of the data to be sent.

pResBuff: Pointer to the data to be received. The size of the variable must be adequate.

cbResLen: Length of the data to be received. The length must be adequate.

bExecute: A rising edge activates the block.

tTimeout: Time after which the attempt is aborted.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrId		: WORD;
   cbResponse	: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

cbResponse: Number of bytes that were received.

FB_MBCLOSE

Block FB_MBCLOSE enables closing of a TCP/IP connection. The block is activated with a rising edge of bExecute. As long as the block is busy bit bBusy is set. nHandle must be connected with block FB_MBOpen nHandle. If an error occurs bError is set to TRUE. The error code can be found in nErrId. If the block was called without error a new socket can be opened with FB_MBOpen.

INPUT

VAR_INPUT
   nHandle	: UINT;
   iFlags		: UINT;
   bExecute	: BOOL;
   tTimeout	: TIME;
END_VAR

nHandle: Handle - linked with blocks FB_MBOpen.

iFlags: 0 - TCP/IP connection is closed even if the partner device cannot be reached, 1 - TCP/IP connection is terminated with "FIN"; for the block to be able to close the TCP/IP connection without error it must exist and communication must be operational. It is recommend to use 0 because in this case the TCP/IP connection is always closed, irrespective of the state of the partner device.

bExecute: A rising edge activates the block.

tTimeout: Time after which the attempt is aborted.

OUTPUT

VAR_OUTPUT
   bBusy         	: BOOL;
   bError        	: BOOL;
   iErrId		: WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

Example

For the example you need two BX9000 or a BC9x00 instead of a BX9000.

The first BX9000 acts as ModbusTCP client
The second BX9000 (or a BC9x00) acts as ModbusTCP server

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9000 (165) firmware version >=1.14 | TcBaseBX9000.lbx


FB_Smtp

This function block uses the SMTP protocol (simple mail transfer protocol) to send e-mails. The function block can, for instance, be used to send errors, diagnostic information, or warnings in the form of e-mails. The recipients' addresses are passed as strings to the sTo, sCc, sBcc and sSubject input variables. The maximum string length for recipients' addresses is limited to 80 characters in order to save resources. The string with the mail text itself may, however, be longer.

VAR_INPUT

VAR_INPUT
    bStart		: BOOL;
    sSmtpServer	: STRING(15);
    sFrom		: STRING;
    sTo		: STRING;
    sCc		: STRING;
    sBcc		: STRING;
    sSubject		: STRING;
    pMail		: DWORD;
    tTimeOut		: TIME;
END_VAR

bStart: The function block is activated by a rising edge at this input.

sSmtpServer: IP address of the SMTP server as a string.

sFrom: A string containing the e-mail address of the sender. If the string supplied is empty, then the Bus Controller generates an e-mail address from the name of the Bus Controller and the MAC ID. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.

sTo: A string containing the e-mail address of the recipient. A valid e-mail address must be given. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.

sCc: A string containing the e-mail address of a further recipient (Cc = carbon copy). This string can also be empty. A copy of the e-mail is sent to this recipient. The e-mail address of this recipient is visible to other recipients. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.

sBcc: A string containing the e-mail address of a further recipient (Bcc = blind carbon copy). This string can also be empty. A copy of the e-mail is sent to this recipient. The e-mail address of this recipient is not visible to other recipients. The maximum string length is limited to 80 characters. It is possible to enter multiple recipient addresses separated by semicolons.

sSubject: A string containing the e-mail's subject line. This string can also be empty. The maximum string length is limited to 80 characters.

pMail: The address (a pointer) to a null-terminated string containing the e-mail text. This string can also be empty. The address of the string can be determined with the ADR operator.

tTimeOut: Maximum time allowed for the execution of the command.

VAR_OUTPUT

VAR_OUTPUT
    bBusy		: BOOL;
    bError		: BOOL;
    iErrorId		: WORD;
END_VAR

bBusy: This output remains TRUE until the block has executed a command, but at the longest for the duration supplied to the tTimeOut input.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (table).

Error code (hex) | Description
0x8000 | SMTP server not found.
0x8001 | Resource error.
0x8002 | Socket resource error.
0x8003 | Connection fault.
0x8004 | Communication fault.
0x8005 | Rx error. Communication time exceeded.
0x8006 | Rx error. Communication fault.
0x8007 | Rx error. Frame error.
0x8008 | Communication error. Wrong response.
0x8009 | Tx error. Communication fault.
0x800A | Communication shutdown error.
0x800B | Communication timeout.
0x8010 | Invalid parameter.

Example of a call in FBD

PROGRAM MAIN
VAR
    fbSMTP	: FB_Smtp;
    bSend	: BOOL;
    sMsg 	: STRING(100):='Test';
    bBusy 	: BOOL;
    bError 	: BOOL;
    nErrId 	: UDINT;
END_VAR

In this example, a rising edge at the bStart input sends a mail to 4 recipients.

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


Time protocol (SNTP)

(from firmware version 1.12)

The Simple Network Time Protocol is used to synchronize clocks via the internet. The BX9000 can be synchronized with a time server.

FUNCTION_BLOCK FB_SNTP

If an IPAdresse is entered the Bus Terminal controller uses the SNTP protocol. If an empty string is transferred, the time protocol (UDP port 37) is used.

VAR_INPUT

bStart :BOOL;
sSntpServer :STRING(15);
tTimeOut :TIME;

bOpen: Rising edge starts the block
sSntpServer: SNTP server entry. If an empty string is entered, the time protocol is used (UDP port 37)
tTimeOut: TMOut after which the process is to be terminated

VAR_OUTPUT

bBusy :BOOL;
bError :BOOL;
iErrorId :WORD;
tTime :DT;
cCurrSntpServer :STRING(15);

bBusy: The block is active as long it is TRUE.
bError: Error bit.
iErrorId: Error number.
tTime: Time and date.
sCurrSnptServer: IP address of the SMTP server.

Return parameter iErrId | Meaning
0 | No error
> 0 | Error number (#not documented#)

Example:


FB_AddDnsServer

Up to a maximum of three DNS servers can be passed to the Bus Controller with this function block.

INPUT

VAR_INPUT
   bStart      : BOOL;
   sDNSServer  : STRING(15);
END_VAR

bStart: The function block is activated by a rising edge at this input.

sDNSServer: A string containing the IP address of the DNS server.

OUTPUT

VAR_OUTPUT
   bBusy       : BOOL;
   bError      : BOOL;
   iErrorId    : WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


FB_GetHostByAddr

This function block can determine the host name associated with a specified IP address.

INPUT

VAR_INPUT
   bStart          : BOOL;
   sIPAddr         : STRING(15);
   pHostName       : DWORD;
   cbMaxNameLen    : WORD;
END_VAR

bStart: The function block is activated by a rising edge at this input.

sIPAddr: A string containing the IP address of the host.

pHostName: Contains the address of a string buffer into which the host name that has been found is written. It is the programmer who is responsible for dimensioning the buffer appropriately so that cbMaxNameLen bytes can be removed from it. The address can be determined with the ADR operator.

cbMaxNameLen: Contains the length, in bytes, of the buffer into which the host name that has been found is to be written.

OUTPUT

VAR_OUTPUT
   bBusy           : BOOL;
   bError          : BOOL;
   iErrorId        : WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


FB_GetHostByName

This function block can determine the IP address associated with a specified host name.

INPUT

VAR_INPUT
bStart        : BOOL;
pHostName     : DWORD;
END_VAR

bStart: The function block is activated by a rising edge at this input.

pHostName: Contains the address of a string variable with the host name. The address of a string variable can be determined with the ADR operator.

OUTPUT

VAR_OUTPUT
   bBusy      : BOOL;
   bError     : BOOL;
   iErrorId   : WORD;
   sIPAddr    : STRING(15);
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

sIPAddr: When successful, this variable contains the IP address of the host.

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


FB_GetNetworkConfig

This function block can determine information on the current network configuration.

INPUT

VAR_INPUT
   bStart             : BOOL;
END_VAR

bStart: The function block is activated by a rising edge at this input.

OUTPUT

VAR_OUTPUT
   bBusy              : BOOL;
   bError             : BOOL;
   iErrorId           : WORD;
   sMacId             : STRING(17);
   sIPAddr            : STRING(15);
   sSubnetMask        : STRING(15);
   sDefaultGateway    : STRING(15);
   sDnsServer         : STRING(15);
   sTargetName        : STRING(20);
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

sMacId: Returns the MAC ID of the Bus Controller, for example '00-01-05-13-45-63'.

sIPAddr: Returns the IP address of the Bus Controller.

sSubnetMask: Returns the SubNet mask.

sDefaultGateway: Returns the default gateway.

sDnsServer: Returns the default DNS server (assigned by the DHCP server).

sTargetName: Returns the Bus Controller's current target name.

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


FB_SetTargetName

With this function block a target name can be assigned to the Bus Controller.

INPUT

VAR_INPUT
   bStart           : BOOL;
   sTargetName      : STRING(20);
END_VAR

bStart: The function block is activated by a rising edge at this input.

sTargetName: A string containing the new target name of the Bus Controller.

OUTPUT

VAR_OUTPUT
   bBusy            : BOOL;
   bError           : BOOL;
   iErrorId         : WORD;
END_VAR

bBusy: This output remains TRUE until execution of the command is complete.

bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in iErrorId.

iErrorId: Contains the command-specific error code of the most recently executed command (see table).

Development environment | Target platform | PLC libraries to be linked
TwinCAT v2.10.0 and above | BX9xxx (165) firmware version >=1.12 | TcBaseBX9000.lbx


Error codes

Hex | Description
0x8010 | invalid parameter
0x8011 | DNS server list is full
0x801F | Resource error (internal)
0x8020 | invalid host length
0x8021 | no hostname founded
0x802E | Heap error (internal)
0x802F | Resource error (internal)
0x8030 | invalid parameter
0x8031 | invalid hostname
0x8032 | Hostname too long
0x803F | Resource error (internal)
0x804F | Resource error (internal)
0x8050 | no valid IP-Address
0x8052 | no class-D IP-Address
0x8055 | Error inside stack (internal)
0x805F | Resource error (internal)
0x8060 | ERR_SNTP_INVALID_SERVER
0x8061 | ERR_SNTP_NO_MORE_SOCKETS
0x8064 | ERR_SNTP_RX_ERR
0x8065 | ERR_SNTP_CONN_SHUT_DOWN
0x8066 | ERR_SNTP_TIMEOUT
0x8100 | invalid parameter
0x8102 | no open connection
0x8104 | no remote data
0x8106 | Buffer overrun (only UDP)
0x8200 | Connection already opened
0x8201 | Connect error
0x8202 | Timeout
0x8203 | Resource error (internal)
0x8300 | Timeout
0x8301 | Remote connection shutdown
0x8302 | Internal error
0x8303 | Resource error (internal)
0x8304 | no remote connection
0x8400 | Connection not opened
0x8401 | Timeout
0x8800 | no valid network configuration, for example DHCP is still active
0x8F09 | no more ADS Socket possible, to many ADS Sockets are open
0x8F10 | Session not activated
0x8F11 | Session not ready
0x8F12 | invalid session ID
0x8F13 | invalid state (intern)
0x8F20 | no free slot. There are 2 sessions activated
0x8F21 | Error during task initialization
0x8F22 | Session is already closed


Bus Terminal Controller - Programming via Serial Interface

BECKHOFF 总线端子控制器: 编程

通过串行接口编程

每个总线端子控制器都可通过PC的RS232接口来编程。

在 TwinCAT PLC Control中选择串行接口。

串行接口设置, 串口号, 波特率等. 均可在 PLC Control的Online/Communication parameters中找到。总线端子控制器需要设置如下:

  • 波特率: 9600/19200/38400/57600 baud (自动波特率检测)
  • 停止位: 1
  • 校验位: 偶校验

通过串行接口和ADS编程

总线端子控制器可通过PC的 RS232接口来编程。在它可用之前，TwinCAT必须先识别出该总线端子控制器(see serial ADS)。

在TwinCAT PLC Control中选择ADS连接。

PLC Control can be accessed via Online/Communication Parameters....


ModbusTCP Error Answer

BECKHOFF 现场总线组件: ModbusTCP

ModbusTCP 从站错误应答 (BK9000, BC9000, IP/ILxxxx-B/C900)

当用户给从站发送一个耦合器不能识别的请求或信息时，从站将回应一个错误报告。该应答包含功能和错误代码。0x80 被加入到返回的功能值中。

代码 | 名称 | 意义
1 | ILLEGAL FUNCTION | Modbus 功能未实现
2 | ILLEGAL DATA ADDRESS | 无效的地址或长度
3 | ILLEGAL DATA VALUE | 无效的参数 - 诊断功能 - 不正确的读/写存取寄存器号
4 | SLAVE DEVICE ERROR | 看门狗或 K-Bus 错误
6 | SLAVE DEVICE BUSY | 输出数据已被另一IP地址的设备接收。


BX9000 - Diagnostics

BECKHOFF 现场总线组件: 错误处理和诊断

诊断

以太网状态

在许多情况下，了解与更高级别主站通讯的好坏非常重要。为此，将现场总线状态变量与你的PLC程序连接起来。

Fig. 以太网现场总线状态

现场总线状态

Error number | Description | Remedy
0 | No error | -
1 | Watchdog error | Communication interrupted

以太网类型

在此，可以决定哪些以太网协议在访问PLC变量，并从而触发了看门狗(示例，在默认配置区域的数据从地址 %IB1000 和 %QB1000开始)。

Diagnosis number | Description | Remedy
0x0000 | No protocol is accessing the PLC variables | -
0x0001 | ADS TCP | Communication via ADS TCP/IP
0x0002 | ADS UDP | Communication via ADS UDP/IP
0x0010 | ModbusTCP | Communication via Modbus TCP/IP

通过ADS读取现场总线状态

现场总线状态可以通过默认配置下ADSREAD或在TwinCAT组态（开发中）中读取。

Parameter ADSREAD block | Description
NetID | local – empty string
Port |
IndexGroup |
IndexOffset |
LEN |

K-Bus状态

一个内部总线或总线端子错误可以在K-Bus状态中显示出。更精确的故障描述可通过功能块（编制中）获得。为此，将K-Bus状态变量与你的PLC程序连接起来。

Error bit | Description | Error type
0 | No error | No ERROR.
Bit 0 | K-Bus error | ERROR
Bit 2 | K-Bus is re-triggered | NOTE

通过ADS 读取K-Bus状态

在默认或TwinCAT 配置中，现场总线状态可以通过ADSREAD.读取。

Parameter ADSREAD block | Description
NetID | local – empty string
Port | 1
IndexGroup | 16#0006
IndexOffset | 16#000C_9000
LEN | 1


BC9xx0 - Diagnostic LEDs

BECKHOFF Fieldbus Components: Error handling and diagnosis

Diagnostic LEDs

The Bus Terminal Controllers have status LEDs.

BC9050

LEDs for power supply diagnosis

LED (Power LEDs) | Meaning
Power LED Us off | Bus Coupler has no voltage 24 VDC
Power LED Up off | No 24 VDC power supply connected to the power contacts

LEDs for K-bus diagnostics

LED (K-bus) | Meaning
K-bus RUN | on or flashing - K-bus running
K-bus ERR | flashing (see error code)

LEDs for Ethernet diagnostics

LED (Ethernet) | Meaning
LINK/ACT | on - LINK available, flashing - LINK available and communication
ERROR | flashing - DHCP or BootP active. Waiting for an IP address
COM | Communication with controller available

LEDs for PLC diagnostics

LED (Ethernet) | Meaning
PLC | on - PLC running, flashing - cycle time is exceeded, off - cycle time exceeded permanently or PLC stopped
TC/DC | on - TwinCAT configuration active, off - Default configuration active, flashing TwinCAT configuration faulty

BC9120

LEDs for power supply diagnosis

LED (Power LEDs) | Meaning
Power LED Us off | Bus Coupler has no voltage 24 VDC
Power LED Up off | No 24 VDC power supply connected to the power contacts

LEDs for K-bus diagnostics

LED (K-bus) | Meaning
K-bus RUN | on or flashing - K-bus running
K-bus ERR | flashing (see error code)

LEDs for Ethernet diagnostics

LED (Ethernet) | Meaning
LINK/ACT | on - LINK available, flashing - LINK available and communication
10/100Mbaud | on - 100 Mbaud, off - 10 Mbaud
ERROR | flashing - DHCP or BootP active. Waiting for an IP address
COM | Communication with controller available

LEDs for PLC diagnostics

LED (Ethernet) | Meaning
PLC | on - PLC running, flashing - cycle time is exceeded, off - cycle time exceeded permanently or PLC stopped
TC/DC | on - TwinCAT configuration active, off - Default configuration active, flashing TwinCAT configuration faulty

Error code for K-Bus diagnosis

Error
code 		Error
argument 		Description Remedy
- flashing continuously EMC problems
  • Check power supply for overvoltage or undervoltage peaks
  • Implement EMC measures
  • If a K-Bus error is present, it can be localized by a restart of the coupler (by switching it off and then on again)
1 | 0 | EEPROM checksum error | Enter factory settings with the KS2000 configuration software
1 | Code buffer overflow | Insert fewer Bus Terminals. The programmed configuration has too many entries in the table
2 | Unknown data type | Software update required for the Bus Coupler
2 - Reserve -
3 0 K-Bus command error
  • No Bus Terminal inserted
  • One of the Bus Terminals is defective; halve the number of Bus Terminals attached and check whether the error is still present with the remaining Bus Terminals. Repeat until the defective Bus Terminal is located.
4 | 0 | K-Bus data error, break behind the Bus Coupler | Check whether the n+1 Bus Terminal is correctly connected; replace if necessary.
n | Break behind Bus Terminal n | Check whether the Bus End Terminal KL9010 is connected.
5 | n | K-Bus error in register communication with Bus Terminal n | Exchange the nth bus terminal
6 | 0 | Error at initialization | Exchange Bus Coupler
1 | Internal data error | Perform a hardware reset on the Bus Coupler (switch off and on again)
2 | DIP switch changed after a software reset | Perform a hardware reset on the Bus Coupler (switch off and on again)
7 0 Note: Cycle time was exceeded Warning: the set cycle time was exceeded. This indication (flashing LEDs) can only be cleared by booting the Bus Coupler again.
Remedy: increase the cycle time
9 | 0 | Checksum error in Flash program | Transmit program to the BC again
1 | Incorrect or faulty library implemented | Remove the faulty library
10 | n | Bus Terminal n is not consistent with the configuration that existed when the boot project was created | Check the nth Bus Terminal. The boot project must be deleted if the insertion of an nth Bus Terminal is intentional
14 | n | nth Bus Terminal has the wrong format | Start the Bus Coupler again, and if the error occurs again then exchange the Bus Terminal
15 | n | Number of Bus Terminals is no longer correct | Start the Bus Coupler again. If the error occurs again, restore the manufacturers setting using the KS2000 configuration software
16 | n | Length of the K-Bus data is no longer correct | Start the Bus Coupler again. If the error occurs again, restore the manufacturers setting using the KS2000 configuration software


BC9xx0 - First steps

Necessary components

  • A BC9xx0
  • KL1114
  • KL2134
  • KL9010
  • A 24 V DC power supply unit plus cabling material
  • An Ethernet cross cable for a 1:1 connection between PC and BC9020 or BC9050 (without switch)
  • A "normal" Ethernet cable between PC and BC9120

DIP switch settings

Set DIP switch 1 to ON, leave all other DIP switches OFF. A fixed IP address is used. Restart the BC after setting the DIP switches.
BC9050 has IP address 172.16.21.1
BC9020 has IP address 172.16.22.1
BC9120 has IP address 172.16.23.1

Set a suitable IP address on your programming PC, e.g. 172.16.100.100 (SubNetMask 255.255.0.0).

Use the >Ping< command to check whether TCP/IP communication is available. Open the prompt (DOS box) and enter the following, e.g. if a BC9050 is used: Ping 172.16.21.1. If the ping is successful you can continue. If the ping is not answered the communication is faulty. Check the Ethernet connection - right cable, the Controller DIP switch is switched on correctly, the IP address on the PC has changed.

Search BC via the System Manager

Start the System Manager. Select a new target system.

Click Search (Ethernet)...

Then click Broadcast Search. The BC now appears in the window. The host name is formed based on BC plus the last 3 bytes of the MAC ID and is therefore unique in your system. The MAC ID is printed on a label below the Bus Terminal Controller. Set the options button to IP Address and click Add Route. The Connected field should show a cross or "X". If a password query appears confirm with OK (leave blank). The password function is not implemented in the Bus Terminal Controller.

You can now select the Bus Terminal Controller. Click on the BC and confirm with OK.

Your BC with name and IP address is shown in red at bottom left in the System Manager. The field next to it should be blue and show Config Mode. If this is the case you can now scan the device. Right-click on IO Devices then Scan Devices.

The System Manager should find 2 devices, i.e. the Ethernet interface and the K-bus interface with the connected Bus Terminals.

Ethernet interface

Click on Upload to upload the current IP configuration.

PLC configuration

Append your PLC program here. First open the following example: . Save the file locally on your computer.

Recompile the file.

Re-save.

Change back to the System Manager and append your PLC program (right-click on PLC Configuration).

Search for your file (file type: tpy). Then open the tree. You will see all allocated data. Select the variables and link them with your Bus Terminals.
bIN_1 with KL1104 channel 1
bOUT_1 with KL2134 channel 1
bOUT_2 with KL2134 channel 2
bOUT_3 with KL2134 channel 3

After being linked you should now see the following.

Now activate the configuration in the System Manager. Click on [image] to download the configuration to the Bus Terminal Controller. Acknowledge all messages with OK. Finally you will be asked to restart the system. The BC will then reboot. The System Manager will lose the connection with the Bus Terminal Controller. Wait until the System Manager has re-established the connection. After a few seconds the status field at the bottom left of the System Manager should turn green [image]. If it is blue the BC has restarted in Config mode. Check your configuration.

Switch back to PLC Control. Go online and select the target system.

Log in and start the program.


Moving between the controllers

Moving from BCxx00 to BCxx50/BCxx20

File names

At Bus Terminal Controller of BCxx50 and BCxx20 series, libraries are called *.lbx, and programs are saved as *.prx.

Flag variables

The flag variables

  • of BCxx00 are allocated from %MB0...%MB511 (except BC9000/BC9100: %MB0...%B4095)
  • of BCxx20 are allocated from %MB0...%MB4095
  • of BCxx50 are allocated from %MB0...%MB4095

Status information such as K-Bus/fieldbus status or cycle tick is not copied to the BCxx50/BCxx20. For BCxx50/BCxx20 this information is available as a function in the TcSystemBCxx50.lbx library.

The allocated flags don't operate as retain variables.

Retain data

The retain data have to be declared as VAR_RETAIN. Up to 2 kByte are available.

PLC variables

In the default configuration, the PLC variables start at %IB1000 and %QB1000.

Large model

Not available for BCxx50 and BCxx20.

Maximum memory:

  • BCxx50: 48 kByte
  • BCxx20: 128 kByte

Task time

The task time is specified in the PLC Control. It should be set to a realistic value (measuring of PLC cycle time and K-Bus). The background time is no longer used.

Task configuration

A maximum of one task is available. This task has to be configured.

PLC and Field Bus Terminals

On standard bus terminal controllers (BCxx00) it was possible to choose if a bus terminal is allocated to the fieldbus or to the local PLC.

In default configuration of an BCxx50/BCxx20 all bus terminals are allocated to the local PLC. An allocation to the fieldbus is not possible here.

Moving from BCxx00 to BXxx00

File names

At Bus Terminal Controller of BXxx00 series, libraries are called *.lbx, and programs are saved as *.prx.

Flag variables

The flag variables

  • of BCxx00 are allocated from %MB0...%MB511 (except BC9000/BC9100: %MB0...%B4095)
  • of BXxx00 are allocated from %MB0...%B4095

Status information such as K-Bus/fieldbus status or cycle tick is not copied to the BXxx00. For BXxx00 this information is available as a function in the TcSystemBX.lbx library.

The allocated flags don't operate as retain variables.

Retain data

The retain data have to be declared as VAR_RETAIN. Up to 2 kByte are available.

PLC variables

In the default configuration, the PLC variables start at %IB1000 and %QB1000.

Large model

No available for BXxx00. Maximum memory: 256 kByte

Task time

The task time is specified in the PLC Control. It should be set to a realistic value (measuring of PLC cycle time and K-Bus). The background time is no longer used.

Task configuration

A maximum of one task is available. This task has to be configured.

PLC and Field Bus Terminals

On standard bus terminal controllers (BCxx00) it was possible to choose if a bus terminal is allocated to the fieldbus or to the local PLC.

In default configuration of an BXxx00 all bus terminals are allocated to the local PLC. An allocation to the fieldbus is not possible here.

Moving from PC to BCxx50/BCxx20/BXxx00

File names

At Bus Terminal Controllers of BCxx50/BCxx20 and BXxx00 series, libraries are called *.lbx, and programs are saved as *.prx.

Allocated variables

The Bus Terminal Controllers of BCxx50/BCxx20 and BXxx00 series offers a limited number of allocated data:

  • Inputs 2kB, %IB0..2048
  • Outputs 2 kB, %QB0..2048
  • Flags 4 kB, %MB0..4095

Task configuration

A maximum of one task is available. A sensible task time should be selected. Adjust the task time to your application by measuring the required system time (PLC + K-Bus + fieldbus + other).

Retain data

The Bus Terminal Controllers of BCxx50/BCxx20 and BXxx00 series offer up to 2 kB of retain data. Ensure that no (or only very few) retain data are used in function blocks (see RETAIN data).


General operating conditions

The following conditions must be observed if the fieldbus components are to function without error.

Environmental conditions

Operation

The components may not be used without additional protection in the following locations:

  • in difficult environments, such as where there are corrosive vapors or gases, or high dust levels
  • in the presence of high levels of ionizing radiation
Condition | Permissible range
Permissible ambient temperature range during operation | 0°C ... +55°C
Permissible relative humidity during operation | 95 %, no condensation
Installation position | variable
Vibration resistance | conforms to EN 60068-2-6
Shock resistance | conforms to EN 60068-2-27, EN 60068-2-29
EMC resistance burst | conforms to EN 61000-6-2
ESD emission | conforms to EN 61000-6-4

Transport and storage

Condition | Permissible range
Permissible ambient temperature range during storage | -25 °C ... +85°C
Permissible relative humidity | 95 %, no condensation
Free fall | up to 1 m in the original packaging

Protection classes and types

Condition | Permissible range
Protection class in accordance with IEC 536 (VDE 0106, Part 1) | A protective conductor connection to the mounting rail is necessary!
Protection class according to IEC 529 | IP20 (protection against contact with a standard test finger)
Protection against foreign objects | Less than 12 mm in diameter
Protection against water | No protection

Component identification

Every supplied component includes an adhesive label providing information about the product's approvals. For example, on the BK2000:

The following information is printed on the label:

Printed item | In this particular example:
Precise product identification | Lightbus Coupler BK2000
Supply voltage | 24 VDC
Data transfer rate | 2.5 MBaud
manufacturer | Beckhoff Automation GmbH
CE mark | Conformity mark
UL mark

Mark for UL approval. UL stands for the Underwriters Laboratories Inc., the leading certification organization for North America, based in the USA.

C = Canada, US = USA, LISTED 22ZA (the test results can be inspected under this entry)
Production identification

From left to right, this sequence of characters indicates the production week (2 characters), the production year (2 characters), the software version (2 characters) and hardware version (2 characters), along with any special indications (4 characters).

This case therefore is a BK2000
- produced in the 9th calendar week
- of the year 2001
- containing the BF firmware version
- and using the 6th hardware version
- with no special indications


Standards for device testing

EMV

EMC resistance burst

EN 61000-6-2

ESD

EN 61000-6-4

Vibration / Shock resistance

Vibration resistance

EN 60068-2-6

Shock resistance

EN 60068-2-27, EN 60068-2-29


Bibliography

TCP/IP

TCP/IP (English)
Illustrated, Volume1 The Protocols
by W. Richard Stevens
Publisher: ADDISON-WESLEY Longmann Verlag

TCP/IP (German)
Aufbau und Betrieb eines TCP/IP Netzes (Structure and Operation of a TCP/IP Network)
by Kevin Washburn and Jim Evans
Publisher: ADDISON-WESLEY Longmann Verlag

Modbus/TCP

http://www.modicon.com/

http://www.modbus.org

TwinCAT

Beckhoff Information System
http://infosys.beckhoff.com


List of Abbreviations

ADS

Automation Device Specification.

IP (20)

Bus Terminal protection class

IPC

Industrial PC

I/O

Inputs and outputs

K-Bus

Terminal bus

KS2000

Configuration Software for Bus Terminals, Bus Coupler, Bus Terminal Controller, Fieldbus Box Modules and so on

PE

The PE power contact can be used as a protective earth.

TwinCAT

The Windows Control and Automation Technology


Support and Service

Beckhoff and their partners around the world offer comprehensive support and service, making available fast and competent assistance with all questions related to Beckhoff products and system solutions.

Beckhoff's branch offices and representatives

Please contact your Beckhoff branch office or representative for local support and service on Beckhoff products!

The addresses of Beckhoff's branch offices and representatives round the world can be found on her internet pages:
http://www.beckhoff.com

You will also find further documentation for Beckhoff components there.

Beckhoff Headquarters

Beckhoff Automation GmbH

Eiserstr. 5
33415 Verl
Germany

Phone: | +49(0)5246/963-0
Fax: | +49(0)5246/963-198
e-mail: | info@beckhoff.com
Beckhoff Support

Support offers you comprehensive technical assistance, helping you not only with the application of individual Beckhoff products, but also with other, wide-ranging services:

  • support
  • design, programming and commissioning of complex automation systems
  • and extensive training program for Beckhoff system components
Hotline: | +49(0)5246/963-157
Fax: | +49(0)5246/963-9157
e-mail: | support@beckhoff.com
Beckhoff Service

The Beckhoff Service Center supports you in all matters of after-sales service:

  • on-site service
  • repair service
  • spare parts service
  • hotline service
Hotline: | +49(0)5246/963-460
Fax: | +49(0)5246/963-479
e-mail: | service@beckhoff.com