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.


ADS Return Codes

Error codes: 0x000..., 0x500..., 0x700..., 0x1000..., 0x274C...

Global Error Codes

Hex | Dec | Description
0x0 | 0 | 没有错误
0x1 | 1 | 内部错误
0x2 | 2 | No Rtime
0x3 | 3 | 锁定内存分配错误
0x4 | 4 | 嵌入邮箱错误
0x5 | 5 | HMSG接收错误
0x6 | 6 | 没有找到目标端口
0x7 | 7 | 没有找到目标机
0x8 | 8 | 未知的指令ID
0x9 | 9 | 任务ID出错
0xA | 10 | 无IO
0xB | 11 | 未知AMS指令
0xC | 12 | Win 32 出错
0xD | 13 | 端口未连接
0xE | 14 | AMS长度无效
0xF | 15 | AMS Net ID无效
0x10 | 16 | 安装版本过低
0x11 | 17 | 无调试
0x12 | 18 | 端口禁用
0x13 | 19 | 端口已连接
0x14 | 20 | AMS Sync Win32出错
0x15 | 21 | AMS Sync超时
0x16 | 22 | AMS Sync AMS出错
0x17 | 23 | AMS Sync no index map
0x18 | 24 | AMS端口无效
0x19 | 25 | 无内存
0x1A | 26 | TCP 发送错误
0x1B | 27 | 主机未连接

Router Error Codes

Hex | Dec | Error type | Description
0x500 | 1280 | internal | ROUTERERR_NOLOCKEDMEMORY 没有锁定的内存可以分配.
0x501 | 1281 | internal | ROUTERERR_RESIZEMEMORY 路由器内存大小不能改变.
0x502 | 1282 | internal | ROUTERERR_MAILBOXFULL 该AmsPort的邮箱已满. 当前发送的邮件被取消.
0x503 | 1283 | internal | ROUTERERR_DEBUGBOXFULL 该Ams邮箱的调试端口达最大值 . 调试监视器不在显示发送的邮件.
0x504 | 1284 | internal | ROUTERERR_UNKNOWNPORTTYPE
0x505 | 1285 | internal | ROUTERERR_NOTINITIALIZED 路由器(还)没有初始化
0x506 | 1286 | internal | ROUTERERR_PORTALREADYINUSE 所需的端口数已经分配.
0x507 | 1287 | internal | ROUTERERR_NOTREGISTERED Ams Port 未注册
0x508 | 1288 | internal | ROUTERERR_NOMOREQUEUES Ams Ports达到最大数.
0x509 | 1289 | internal | ROUTERERR_INVALIDPORT
0x50A | 1290 | internal | ROUTERERR_NOTACTIVATED TwinCAT 路由器(还)没有启动.

General ADS Error Codes

Hex | Dec | Description
0x700 | 1792 | 出错类<设备出错>
0x701 | 1793 | 服务器不支持服务
0x702 | 1794 | 无效的索引组
0x703 | 1795 | 无效的索引偏移
0x704 | 1796 | 不允许读/写
0x705 | 1797 | 参数大小不正确
0x706 | 1798 | 无效的参数值(s)
0x707 | 1799 | 设备还未在就绪状态
0x708 | 1800 | 设备正忙
0x709 | 1801 | 无效的环境 (必须在 Windows 下)
0x70A | 1802 | 内存不足
0x70B | 1803 | 无效参数值(s)
0x70C | 1804 | 未找到 (文件, ...)
0x70D | 1805 | 命令或文件语法错误
0x70E | 1806 | 对象不匹配
0x70F | 1807 | 对象已存在
0x710 | 1808 | 未找到符号
0x711 | 1809 | 符号版本无效
0x712 | 1810 | 服务器处于无效状态
0x713 | 1811 | AdsTransMode不支持
0x714 | 1812 | 通知处理无效
0x715 | 1813 | 通知客户端未注册
0x716 | 1814 | 没有更多的通知处理
0x717 | 1815 | 监视的范围过大
0x718 | 1816 | 未初始化设备
0x719 | 1817 | 设备已超时
0x71A | 1818 | 查询接口失败
0x71B | 1819 | 接口要求错误
0x71C | 1820 | class ID 无效
0x71D | 1821 | object ID 无效
0x71E | 1822 | 请求被挂起
0x71F | 1823 | 请求被终止
0x720 | 1824 | 预警信号
0x721 | 1825 | 无效的数组索引
0x722 | 1826 | 符号为启动 -> 释放手柄，然后再试一次
0x723 | 1827 | 访问被拒绝
0x740 | 1856 | Error class <client error>
0x741 | 1857 | 服务中无效的参数
0x742 | 1858 | 指令列表为空
0x743 | 1859 | var 链接正在使用
0x744 | 1860 | 请求的 ID 正在使用
0x745 | 1861 | 超时已过
0x746 | 1862 | win32 子系统出错
0x748 | 1864 | ads-port未打开
0x750 | 1872 | ads sync内部出错
0x751 | 1873 | hash 表溢出
0x752 | 1874 | hash中未找到key
0x753 | 1875 | 缓存中没有符号
0x754 | 1876 | 接收到无效的响应
0x755 | 1877 | sync port 被锁定

RTime Error Codes

Hex | Dec | Error type | Description
0x1000 | 4096 | internal | RTERR_INTERNAL TwinCAT real-time system内部的错误
0x1001 | 4097 | internal | RTERR_BADTIMERPERIODS 定时器数值不正确
0x1002 | 4098 | internal | RTERR_INVALIDTASKPTR 任务指针有无效值 ZERO
0x1003 | 4099 | internal | RTERR_INVALIDSTACKPTR 任务堆栈指针有无效值 ZERO.
0x1004 | 4100 | internal | RTERR_PRIOEXISTS 任务优先级已分配.
0x1005 | 4101 | internal | RTERR_NOMORETCB TCB已满 (Task Control Block) . 最大TCBs数为64.
0x1006 | 4102 | internal | RTERR_NOMORESEMAS No more free semaphores available. Maximum number of semaphores is 64.
0x1007 | 4103 | internal | RTERR_NOMOREQUEUES 行列数已满. 最大行列数为64.
0x1008 | 4104 | internal | TwinCAT 保留.
0x1009 | 4105 | internal | TwinCAT 保留.
0x100A | 4106 | internal | TwinCAT 保留.
0x100B | 4107 | internal | TwinCAT 保留.
0x100C | 4108 | internal | TwinCAT 保留.
0x100D | 4109 | internal | RTERR_EXTIRQALREADYDEF 已应用外部同步中断.
0x100E | 4110 | internal | RTERR_EXTIRQNOTDEF 无需外部同步中断应用.
0x100F | 4111 | internal | RTERR_EXTIRQINSTALLFAILED The apply of the external synchronisation interrupt failed.
0x1010 | 4112 | internal | RTERR_IRQLNOTLESSOREQUAL 再错误环境下调用服务功能.

Winsock Error Codes

Hex | Dec | Description
0x274c | 10060 | 无法访问主机时，可以尝试套接字操作
0x274d | 10061 | 由于连接方超出正常响应时间而导致连接失败， 或者由于主机没有响应，导致建立连接失败。
0x2751 | 10065 | 目标机拒绝而导致无法连接
 |  | 更多Winsock 错误代码: Win32 Error Codes


TwinCAT Quick Start - Beispiel Maschine mit Silverlight JavaScript

TwinCAT Quick Start

装有Microsoft Silverlight和JavaScript的样机

Microsoft Silverlight 是一个网络演示技术.

软件要求:

- runtime:
- Microsoft Silverlight 1.0 / 1.1

- developer tools:
- Microsoft Visual Studio 2008 Beta 2
- Microsoft Silverlight Tools Alpha Refresh for Visual Studio (July 2007)
or
- Microsoft Visual Studio 2005
- Microsoft Silverlight 1.0 Software Development Kit
For this sample Microsoft Visual Studio 2005 was used.

- designer tools:
- Expression Blend 2

- others:
- TwinCAT 2.10
- Browser (for example Internet Explorer 7 or Mozilla Firefox 2)
- Microsoft .NET Framework Version 3.0

第一步...

一步一步，教你学会开发silverlight的应用，包括TwinCAT ADS 网络服务。

1. 创建新项目:

启动Microsoft Expression Blend 2，并创建一个新的用户界面 'Menu → File → new Project...' .再打开对话框 'Create New Project' 后, 你可以编辑该类型, 名称, 位置和语言。在此示例选择类型'Silverlight 应用程序 (JavaScript)' 并命名为'Machine'.

2.创建用户界面:

一些控件可以用于silverlight应用程序中用户界面的开发。你可以在画布中创建一个RadioButton， 一个Textbox和两个椭圆。进度条可以在画布中分别用三个矩形组成。
该接口的属性在 Page.xaml file中描述。
注意，你不能设置对象大小为“自动”。之后可能会出错。

你可以在左上角看到两个输出。计算工件的变量，放在下面。你可以使用右侧的两个RadioButtons来改变电机转速。显示的步骤相当于返回给输出1的时钟数。

3. Add XMLHTTP.JS

在 Visual Studio 中'Project → Add Existing Item...' 添加文件 'XMLHTTP.JS'. 这个文件包含读写PLC变量和数据类型转换的基本方法。

4. Edit source code

打开在Visual Studio 中的文件 'Default.html' 并且头文件中必须包含‘XMLHTTP.JS'文件。

<script type="text/javascript" src="xmlhttp.js"></script>

在HEAD-field of the HTML page添加一个JavaScript-range。你会看到下列源代码:

全局变量必须先声明.

<script type="text/javascript">

    //enter URL to webservice here:
    var url = "http://localhost/TcAdsWebService/TcAdsWebService.dll";
    //enter netId here:
    var netId = "172.16.2.63.1.1";
    //enter the port here:
    var port = 811;
    //send soap request every x seconds:
    var refresh = 1000;

    var inuse = false;

    var b64s, success, errors, req;

    var vUp, vDown, vProgressbar, vCount, vFast, vSlow;

...

你必须对应相应的TcAdsWebService网址，netID和接口。

GUI对象不能被直接访问。如果要进行访问，只有在应用程序启动后，将其分配给已声明的变量。

function Load(sender, eventArgs)
{
    vUp = sender.findName("pathUp");
    vDown = sender.findName("pathDown");
    vProgressbar = sender.findName("recProgressbar");
    vCount = sender.findName("txbCount");
    vFast = sender.findName("ellPointFast");
    vSlow = sender.findName("ellPointSlow");
}

装在方法包含变量分配。对于执行Load method Loaded，必须添加Page.xaml中的Load。

<Canvas
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="368" Height="256"
    x:Name="Page"
    Loaded="Load"
>
...

function loop(x)
{
    Read(netId, port, '16416', '0', '86'); //send soap read request via xmlhttprequest
    window.setTimeout("loop("+x+")", x);
}

Read PLC variable

Read(netId, nPort, indexGroup, indexOffset, cbLen)
  • netId: 字符串显示了PLC的AMS-Net-Id
  • nPort: 运行系统的端口号
  • indexGroup: 读取变量的IndexGroup
  • indexOffset: 读取的第一个字节
  • ncbLen: 读取的字节数

function init()
{
    b64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    success = 0;
    errors = 0;
    loop(refresh); //send request every x seconds
}

Add onload="init()" into <body>, 因此，该方法在装载中被执行。

<body onload="init()" >

读取下一个函数并显示他们的值。Machine.pro 中的变量地址必须正确，参见: Declaration of variables...

function processReqChange()
{
    /*
    readyStates:
    0 = uninitialized
    1 = loading
    2 = loaded
    3 = interactive
    4 = complete
    */

    if (req.readyState == 4)
    {
        // only if "OK"
        if (req.status == 200)
        {
            response = req.responseXML.documentElement;

            inuse = false;

            try //check if there was an error in the request
            {
                errortext = response.getElementsByTagName('faultstring')[0].firstChild.data;
                try
                {
                    errorcode = response.getElementsByTagName('errorcode')[0].firstChild.data;
                }
                catch (e){errorcode="-";}
                    alert(errortext + " ("+errorcode+")");
                return;
            }
            catch (e)
            {
                errorcode=0;
            }

            var data;
            try //if the server returns a <ppData> element decode it, otherwise (write request) do nothing
            {
                data = response.getElementsByTagName('ppData')[0].firstChild.data;
                mode = "read";
            }
            catch (e)
            {
                data = "";
                mode = "";
            }

            if (mode=="read")
            {
                try
                {
                    data = b64t2d(data); //decode result string

                    steps = toInt(data.substr(1, 2));

                    bool = toInt(data.substr(5,2));
                    bool2 = toInt(data.substr(4,2));

                    count = toInt(data.substr(3, 2));

                    speed = toInt(data.substr(6, 2));
                }
                catch (e)
                {
                    alert("Parsing Failed:" + e);
                    return;
                }

                vProgressbar.Width = 306.321/100*steps*4;

                if (bool2 != "1")
                    { vCount.Text = count.toString();}

                if (bool == "1")
                    { vUp.Opacity=1.0;
                      vDown.Opacity=0.0; }
                else if (bool2 == "1")
                    { vUp.Opacity=0.0;
                      vDown.Opacity=1.0; }
                else
                    { vUp.Opacity=0.0;
                      vDown.Opacity=0.0; }

                if (speed == "0")
                   { vFast.Opacity=1.0;
                     vSlow.Opacity=0.0; }
                else
                   { vSlow.Opacity=1.0;
                     vFast.Opacity=0.0; }

            }
        }
        else alert(req.statusText+" "+req.status); //cannot retrieve xml data
    }
}

With the last two methods the PLC variable, which controls the speed of the machine, is set to zero or one.

function Fast_MouseLeftButtonDown(sender, eventArgs)
{
    Write(netId, port, '16416', '6', '2', '0', 'int');
}
function Slow_MouseLeftButtonDown(sender, eventArgs)
{
    Write(netId, port, '16416', '6', '2', '1', 'int');
}

Write SPS Variables

Write(netId, port, indexGroup, indexOffset, cbLen, pwrData, type)
  • netId:字符串显示了PLC的AMS-Net-Id
  • nPort: 运行系统的端口号
  • indexGroup:读取变量的IndexGroup
  • indexOffset: 写入的第一个字节
  • ncbLen: 写入的字节数
  • pwrData: 写入数据所包含的数组
  • type: "bool", "int" or "string"

It has to be changed to 'Expression Blend 2' as it has been done with the 'Load' function for declaring the according rows as 'Click' event for both buttons.

<Canvas x:Name="canvasFast" MouseLeftButtonDown="Fast_MouseLeftButtonDown" ...
<Canvas x:Name="canvasSlow" MouseLeftButtonDown="Slow_MouseLeftButtonDown" ...

5. Testing:

调试应用程序时，你可能会发现他不正常工作。为了防止这种情况，你可以选择'Build -> Publish'.

在对话框中选择"目标位置"，然后“所有项目文件”将会被“复制”。

如果状态栏显示'Publish succeded',你可以在浏览器中运行和测试应用程序。

Download:

Silverlight-Sample