3HAC036957-001 Rev - en
3HAC036957-001 Rev - en
PC SDK
5.13
ABB AB
Robotics Products
SE-721 68 Västerås
Sweden
Table of Contents
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Product documentation, M2004 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1 Introduction 13
1.1 About creating controller applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Documentation and help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Run-time environment 31
3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.2 Running PC SDK Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2.2 Mastership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2.3 PC application configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2.4 Communication between PC and controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.2.5 Licence verification - applies only to versions earlier than PC SDK 5.10. . . . . . . . . . . . . . . . . . . 39
3.3 Release upgrades and compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3HAC036957-001 Revision: - 3
Table of Contents
4 3HAC036957-001 Revision: -
Table of Contents
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 5
Table of Contents
6 3HAC036957-001 Revision: -
Overview
Overview
Usage
PC SDK application manual covers application development using PC SDK. Code samples
are written in C# and Visual Basic. Please note that there exists a separate manual
(Application Manual - FlexPendant SDK) for FlexPendant application development.
Prerequisites
The reader should
• be familiar with IRC5, the FlexPendant, and RobotStudio.
• be used to Microsoft Visual Studio and Windows programming.
• be familiar with one of the .NET programming languages C# or Visual Basic.NET.
• be used to object oriented programming.
Organization of chapters
The manual is organized as follows:
© Copyright 2010 ABB. All rights reserved.
Chapter Contents
1. Introduction. Terminology. Safety.
2. Installation and setup. Development environment . Virtual robot technology.
3. Software architecture. Run-time environment for PC applications. How clients
access controller resources and communicate with the robot controller.
Application configuration. Upgrades and compatibility.
4. Developing PC SDK applications. Analysis and design. Important programming
issues: controller events and threads, UAS, exception handling. Online help.
5. Using the PC SDK. How to add controller functionality using the Controller API.
Programming issues and code samples in VB and C#.
6. Testing, debugging and troubleshooting PC SDK applications. Using printouts,
error codes in exceptions and so on. Checklist for contacting a service organiza-
tion.
Continued
References
Reference Document ID
Operating manual - IRC5 with FlexPendant 3HAC 16590-1
Operating manual - RobotStudio 3HAC032104-001
Operating manual - Getting started, IRC5 and RobotStudio 3HAC027097-001
Technical reference manual - RAPID Instructions, Functions and Data 3HAC16581-1
types
Technical reference manual - System parameters 3HAC17076-1
Application manual - FlexPendant SDK 3HAC036958-001
Application manual - Robot communication and I/O Control. 3HAC020435-001
Revisions
Revision Description
- First edition
From PC SDK 5.13 onwards this manual replaces: Application manual - Robot
Application Builder (3HAC028083-001)
For information on FlexPendant SDK refer Application manual - FlexPendant
SDK
8 3HAC036957-001 Revision: -
Product documentation, M2004
General
The robot documentation may be divided into a number of categories. This listing is based on
the type of information contained within the documents, regardless of whether the products
are standard or optional. This means that any given delivery of robot products will not contain
all documents listed, only the ones pertaining to the equipment delivered. However, all
documents listed may be ordered from ABB. The documents listed are valid for M2004 robot
systems.
However, all documents listed may be ordered from ABB. The documents listed are valid for
M2004 robot systems.
Product manuals
All hardware, robots and controllers, are delivered with a Product manual, which is divided
into two parts:
Product manual, procedures
• Safety information
• Installation and commissioning (descriptions of mechanical installation, electrical
connections)
• Maintenance (descriptions of all required preventive maintenance procedures
including intervals)
• Repair (descriptions of all recommended repair procedures including spare parts)
• Additional procedures, if any (calibration, decommissioning)
Product manual, reference information
• Safety information
• Reference information (article numbers for documentation referred to in Product
manual, procedures, lists of tools, safety standards)
• Part list
• Foldouts or exploded views
© Copyright 2010 ABB. All rights reserved.
• Circuit diagrams
The product manual published as a PDF consists of only one file where the two parts are
presented together, as one Product manual.
3HAC036957-001 Revision: - 9
Product documentation, M2004
Application manuals
Specific applications (for example software or hardware options) are described in
Application manuals. An application manual can describe one or several applications.
An application manual generally contains information about:
• The purpose of the application (what it does and when it is useful)
• What is included (for example cables, I/O boards, RAPID instructions, system
parameters, CD with PC software)
• How to use the application
• Examples of how to use the application
Operating manuals
This group of manuals is aimed at those having first hand operational contact with the robot,
that is, production cell operators, programmers and troubleshooters. It includes:
• Getting started - IRC5 and RobotStudio
• IRC5 with FlexPendant
• RobotStudio
• Troubleshooting
10 3HAC036957-001 Revision: -
Safety
Safety
Safety of personnel
A robot is heavy and extremely powerful regardless of its speed. A pause or long stop in
movement can be followed by a fast hazardous movement. Even if a pattern of movement is
predicted, a change in operation can be triggered by an external signal resulting in an
unexpected movement.Therefore, it is important that all safety regulations are followed when
entering safeguarded space.
Safety of regulations
Before beginning work with the robot, make sure you are familiar with the safety regulations
described in Operating manual - IRC5 with FlexPendant.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 11
Safety
Continued
1 Introduction
1.1. About creating controller applications
NOTE!
A minimum response time for a real controller should be expected to be in the order of 10-
100 milliseconds, meaning that hard real time demands cannot be met on any platform. For
more information, see Communication between PC and controller on page 38.
Continued
14 3HAC036957-001 Revision: -
1 Introduction
1.2. Documentation and help
Introduction
PC SDK includes an extensive on-line help module, which comes with the installation of the
SDK. After having installed RobotStudio, by clicking Windows’ Start menu, then pointing
at Programs > ABB Industrial IT > Robotics IT > RobotStudio 5.xx > SDK you will find:
• Application manual PC SDK
• Reference Manual PC SDK
Application manual
This Application manual PC SDK, is the recommended way to get started if you are new to
PC SDK development. It explains how PC SDK works. It has code examples in C# and
VB.NET and provides hands-on exercises.
The application Manual is provided in two formats, HTML Help and PDF. HTML is the
recommended format for the PC screen and PDF is the best choice if you want printouts.
NOTE!
The Application Manuals PDF can be found in the installation directory, at C:\Program
Files\ABB Industrial IT\Robotics IT\SDK\.
Continued
RobotStudio Community
ABB Robotics launched a community named RobotStudio Community, for its PC Software
users. The Developer Tools in Developer Section of RobotStudio Community has information
and some videos about programming with the PC SDK. At Content Sharing there is a
complete FlexPendant SDK application available for download. It is recommended for
average users and for beginners.
ABB encourage open conversations and believe everyone has something to contribute. The
User Forum of RobotStudio Community has a section dedicated to Robot Application
development. Here beginners as well as experts discuss code and solutions online. If you are
facing a coding problem the User Forum should be your first choice, as there is a good chance
that someone will give you the help you need to proceed.
RobotStudio Community also provides the means to share code and videos. Your contribution
will be appreciated. Working together is many times the key to success.
TIP!
Try it out at www.abb.com/robotics > RobotStudio Community.
MSDN
MSDN (Microsoft Developer Network) at www.msdn.com is a one of many sources of
information for general programming issues related to .NET and Visual Studio.
Continued
1.3. Terminology
Definitions
Term Definition
C# and Visual .NET programming languages.
Basic.NET
Common Language The core runtime engine in the .NET Framework for execution of
Runtime managed code. Provides services such as cross-language inte-
gration, code access security, object lifetime management, and
debugging and profiling support.
Controller Application The public class libraries of PC SDK, which offer robot controller
Programming Interface functionality. Also referred to as CAPI.
Device The FlexPendant is a “smart device” in the .NET vocabulary, that
is, a complete computer in itself with its own processor, operating
system and so on.
FlexPendant ABB’s hand held device, used with IRC5 robot controller. It is
developed with Microsoft’s technology for embedded systems,
Windows CE and .NET Compact Framework.
IRC5 ABB’s robot controller.
JIT compiler When compiling managed code, the compiler translates the
source code into Microsoft Intermediate Language (MSIL), which
is a CPU-independent set of instructions. Before code can be
executed, MSIL must be converted to CPU-specific code, usually
by a just-in-time (JIT) compiler.
managed code Code that is executed and managed by the Microsoft .NET
Framework’s common language runtime. All code produced by
Visual Studio executes as managed code.
Microsoft Visual Studio The integrated development environment that developers work
inside when using the .NET Framework.
© Copyright 2010 ABB. All rights reserved.
Continued
Term Definition
unmanaged code Code that is executed directly by the operating system, outside the
.NET Framework. Unmanaged code must provide its own memory
management, type checking, and security support, unlike
managed code, which receives these services from the common
language runtime. All code executing in the robot controller, as
well as part of the code executing in the FlexPendant is
unmanaged.
Virtual IRC5 Virtual robot technology makes it possible to run a virtual IRC5
controller, virtual mechanical units and a virtual FlexPendant on
the desktop. Included as freeware in ABB’s RobotStudio.
Windows CE The embedded operating system running on the FlexPendant
device.
Acronym Definition
CAPI Controller Application Programming Interface
CLR Common Language Runtime
GUI Graphical User Interface
MSDN Microsoft Developer Network, source of information for .NET
developers at: www.msdn.com
PC SDK Personal Computer Software Development Kit
SDK Software Development Kit
TCP/IP Transmission Control Protocol (TCP) and Internet Protocol (IP)
VB Visual Basic
VS Visual Studio
Continued
Supported platforms
The following software requirements have to be met:
• Operating system: Microsoft Windows XP + SP2, Windows Vista+ SP2 or Windows 7
• Microsoft Visual Studio 2005 Express or better, or, Microsoft Visual Studio 2008
Express or better.
• .NET Framework 2.0 SP2
The following hardware requirement have to be met:
• 50 MB free disk-space on the installation disk
NOTE!
The RobotWare system of a real IRC5 controller to connect to the PC SDK application must
have the option PC Interface.
NOTE!
PC SDK is developed and tested for the English version of Visual Studio. If you are running
Visual Studio in another language you are recommended to switch to the English version.
debugging using a virtual IRC5 learn how to run the virtual IRC5 in RobotStudio.
executing the application targeting a check that the robot system has the controller option
real IRC5 system PC Interface (for PC applications).
Set up a connection between your PC and the robot
controller. For more information, see How to set up
your PC to communicate with robot on page 23 for
details about how this is done.
NOTE!
The Visual Studio installation installs .NET Framework 2.0.
Continued
RAB 5.10
RAB 5.10 upgraded any previously installed PC SDK to 5.10 and installed FlexPendant SDK
5.08, 5.09 and 5.10 side-by-side. The reason for the side-by-side installation of several
FlexPendant SDK versions was to make it easier for FlexPendant SDK users to work on
FlexPendant SDK applications targeting different RobotWare versions. Earlier RAB releases
can be downloaded from http://www.abb.com/robotics > RobotStudioCommunity
>Developer Tools > PC SDK Overview.
What is installed?
The following are installed on your PC:
• SDK assemblies and resources
• Application manual PC SDK
• Reference Manual PC SDK
PC applications
If you install PC SDK 5.13 and previous versions of PC SDK which came along with
FlexPendant SDK as Robot Application Builder, the previous versions will exist on the PC.
You need to choose which PC SDK version to use when adding PC SDK references to the
application project in Visual Studio (browse to the installation directory that matches the
version when adding the PC SDK references to the project). You should also set the Reference
Property Specific Version to true to ensure that the correct version of the PC SDK dlls in the
Global Assembly Cache (GAC) is used in run-time.
RobotStudio Add-In
A RobotStudio Add-In that uses PC SDK cannot decide which version of the PC SDK
assemblies to use during runtime. The reason being an Add-In itself is an assembly that is
loaded into the RobotStudio application domain. As RobotStudio also uses PC SDK
Continued
internally, the PC SDK assemblies are already loaded, and the Add-Ins are forced to use the
same version, which is the same version as RobotStudio. For example, an Add-In that is
loaded into RobotStudio 5.13 will be forced to use the PC SDK 5.13 assemblies.
Installation procedure
The installation procedure is very simple. By default PC SDK is installed when you install
RobotStudio. For more information, see Installing RobotStudio, in Operating Manual -
Getting started, IRC5 and RobotStudio.
An installation wizard will guide you through the installation. If you would like to install
RobotStudio without installing PC SDK, or remove PC SDK from RobotStudio select
Custom in the RobotStudio installation wizard and select or unselect the feature PC SDK
NOTE!
You are also strongly advised to study the Release Notes that you will find on the RobotWare
DVD and on the RobotStudio Community web site, as these hold the most up-to-date
information, including new features and any known limitations of the release.
NOTE!
Please note that there is no license key.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 21
2 Installation and development environment
2.2. How to obtain and install a license key for RAB 5.09 or earlier
2.2. How to obtain and install a license key for RAB 5.09 or earlier
Overview
In RAB 5.10 the license check was removed from the software, which allows anyone to use
Robot Application Builder for free. This means you no longer need to bother about getting a
license, or including a licx file in your PC application.
NOTE!
For RAB version 5.09 or earlier, licensing is the second part of the installation procedure. In
case you need to develop a RAB application for RobotWare 5.09 or earlier you need to turn
to support to get a free license key.
Step Action
1 Detach the license key file from the e-mail and save it to a folder on your PC.
2 Double-click the license key file. This opens the License Install Wizard.
3 Follow the instructions in the wizard.
NOTE!
To execute controller applications towards a real robot controller you must connect your PC
to the robot controller, either through the network or directly to the service port on the
controller. For detailed information, see How to set up your PC to communicate with robot on
page 23.
22 3HAC036957-001 Revision: -
2 Installation and development environment
2.3. How to set up your PC to communicate with robot
Overview
This section describes how to connect your PC to the robot controller.
You can either connect the PC to the controller through an Ethernet network or directly to the
controller service port. When using the controller service port, you can either obtain an IP
address for the PC automatically, or you can specify a fixed IP address.
When the PC and the controller are connected correctly, the controller is automatically
detected by RobotStudio.
NOTE!
A PC SDK application requires RobotStudio or ABB Robot Communications Runtime to
connect to a controller in run-time. The latter is included in the RobotStudio installation.
Continued
Related information
Continued
Overview
This section presents an overview of the development environment used to create PC SDK
applications. The application has to be programmed and debugged using Microsoft Visual
Studio.
NOTE!
From PC SDK 5.11 Visual Studio 2008 is also supported. For information about upgrading
an existing PC SDK project to Visual Studio 2008, see Conversion of VS 2005 projects to
Visual Studio 2008 on page 29.
NOTE!
It is presumed that you are already a .NET programmer. If not, you need to start by learning
the programming language to be used. There are numerous books teaching C# and Visual
Basic.
3HAC036957-001 Revision: - 25
2 Installation and development environment
2.4. Development environment
NOTE!
The help module is not integrated with the Visual Studio Help function. Clicking F1 when
pointing at code, for example, will open the Visual Studio Programmer’s Reference or the
.NET Framework Class Library for the specific language and topic. If your problem is PC
SDK related this will not help you.
TIP!
Depending on what kind of application you are working at, locate the Reference Manual PC
SDK. Click Start menu, point to Programs, ABB Industrial IT, Robotics IT, RobotStudio
5.xx/SDK. Keep the reference file open while programming, as you will be needing it all the
time.
Continued
NOTE!
For more information, see Installing and Licensing RobotStudio in Operating Manual -
RobotStudio
Continued
Deployment to customer
During development, deployment to the controller is done manually. When the development
phase is over and the application needs to be deployed to the customer, this should be done
differently.
For information about how this should be done, see Deployment of a PC SDK application on
page 133.
Continued
Overview
Converting an existing PC SDK Visual Studio 2005 project to Visual Studio 2008 is simple.
When you open a VS 2005 project in VS 2008, the Visual Studio Conversion Wizard appears
automatically. The procedure which converts the project to VS 2008 is easy to follow. It
consists of a few dialog box providing information about what will happen.
© Copyright 2010 ABB. All rights reserved.
Continued
Continued
3 Run-time environment
3.1. Overview
Software architecture
The following illustration shows the Software archtitecture of PC SDK. It shows the PC
platform. Two PC SDK applications developed on top of the PC SDK. The PC SDK CAPI is
the public API offering controller functionality. A PC SDK application can control many
robot controllers on the network. All communication with these is done via the internal Robot
Communication Runtime.
PC platform
Windows
Virtual controller
.NET 2.0
PC SDK app2 C#
Controller B
PC SDK, C#, CAPI
Adaptors, C++
3.1_1
Controller API
The PC SDK offer controller functionality through the public application interface called
Controller API. The interface can be seen as a specification of the controller services
available.
Continued
3.2.1. Overview
Introduction
A PC SDK application runs as a .NET executable, started either by double clicking the exe-
file or by browsing to the program using the Windows Start menu.
Continued
3.2.2. Mastership
NOTE!
In addition to the access right system, there is the User Authorization System, which restricts
what each user is allowed to do with the robot. For more information, see User Authorization
System on page 46.
• Rapid
• Configuration
For code examples, see Start program execution on page 59 in the PC SDK section.
NOTE!
Operations that require mastership are more resource demanding. Mastership should
therefore be released as soon as an operation is completed.
3HAC036957-001 Revision: - 33
3 Run-time environment
3.2.2. Mastership
Losing mastership
Remote clients loses the mastership without warning for the following reasons:
• change from automatic to manual mode
• controller restart
• lost communication
• in manual mode forced revocation of mastership by another client with higher priority
- for example the FlexPendant
If mastership is lost, it has to be taken back explicitly by the client. The controller does not
store the information.
NOTE!
The FlexPendant may also lose mastership without any warning. This may happen in
automatic mode, when a RobotStudio user or a PC SDK application asks for write access to
the controller, for example. The status bar of the FlexPendant will then indicate “Remote
Access in Auto”.
34 3HAC036957-001 Revision: -
3 Run-time environment
3.2.3. PC application configuration
NOTE!
Even if you use the App.config file to specify which controllers to work with you must still
use the netscan functionality to establish a connection from your PC application. For more
information, see Discovery domain on page 61.
NOTE!
The Copy Local property of the PC SDK references used by your application must be set to
true to make use of the App.config file. (In the Solution Explorer in Visual Studio, right-click
the reference and select Properties.)
Section tag
The <section> tag in the <configSection> part of the App.config should specify that
there is a capi section in the file. It should also specify which type is to be used as the
configuration container object as well as the assembly that this type belongs to:
© Copyright 2010 ABB. All rights reserved.
<section name="capi"
type="ABB.Robotics.Controllers.ConfigurationHandler,
ABB.Robotics.Controllers"/>
Capi section
The PC SDK application specific configuration data should be added to the <capi> section.
<capi>
...
</capi>
3HAC036957-001 Revision: - 35
3 Run-time environment
3.2.3. PC application configuration
<defaultSystem>
If there is a controller (robot system) in the network that you connect to often, you may want
to use the <defaultSystem> tag. It has an id attribute containing a string embraced by
curly brackets. It is the system’s globally unique identifier (GUID), which can be find in the
system.guid file in the INTERNAL folder of the robot system.
<defaultSystem id="{469F56DF-938E-4B06-B036-AABBB3E61F83}" />
Using this mechanism enables you to use the default constructor to create a Controller
object for the specified controller:
VB:
Dim aController As Controller = New Controller()
C#:
Controller aController = new Controller();
<remoteControllers>
It is possible to add controllers outside the local network when scanning for available
controllers. One way of doing that is to add the IP address of these controllers in the
<remoteControllers> tag:
<remoteControllers><controller id="192.168.0.9" />
<controller id="192.168.0.19" />
</remoteControllers>
<discovery.networkscanner>
You can configure how long (in ms) a scan operation will last, and increase the value if
netscanning fails. The default value is 200, but if you have a slow PC longer time might be
needed.
<discovery.networkscanner delay="400" />
<defaultUser>
The <defaultUser> tag holds information about user name, password and an optional
application name for the default user. It is used by the UserInfo class to log on to a
© Copyright 2010 ABB. All rights reserved.
<rmmp>
When mastership is requested in manual mode by a remote client such as RobotStudio or a
PC SDK application, a dialog is launched on the FlexPendant asking the operator to confirm
that mastership should be passed from the FlexPendant to a remote client. As long as there is
no confirmation on the FlexPendant the PC SDK application is not given mastership. The
time-out parameter is the time in seconds that the PC SDK application will wait for someone
to confirm remote access in the FlexPendant dialog. The cycle parameter is the time in ms
between poll calls from the PC SDK to check whether mastership has been granted.
<rmmp cycle="550" timeout="65" />
36 3HAC036957-001 Revision: -
3 Run-time environment
3.2.3. PC application configuration
<controllerCall>
You can add a time-out in ms and a multiplicand for slow calls to the controller. The time-out
parameter is the maximum time a call through the Controller API will be permitted. If no
answer is returned within the time specified, an exception is thrown. A slow call is a call that
takes longer than usual, usually operations which require a UAS grant:
<controllerCall timeout="27000" slow="2.1" />
<eventStrategy>
The default way to handle events from the controller is to use asynchronous delegates
(AsyncDelegate), applying the Invoke method to synchronize events and GUI.
By using an <eventStrategy> tag, you can choose to use a windows postback delegate
instead. To make this work you must also implement a subscription to the event from a
windows form, or else the event handler will not receive the event:
<eventStrategy name="WindowDelegate" />
NOTE!
Using this strategy for event handling may affect the performance of your application.
© Copyright 2010 ABB. All rights reserved.
Continued
COM technology
The PC SDK uses an internal Controller API based on COM technology to communicate with
the controller. This API uses sockets and the local TCP/IP stack (see Definitions on page 17)
towards both real and virtual controllers.
NOTE!
You should be aware that the .NET garbage collector does not collect COM objects, but these
need to be disposed of explicitly by the application programmer. For more information, see
Memory management in PC applications on page 63.
Resource identification
All controller resources, both real and virtual, are described using object based hierarchy.
Each resource is uniquely identified, including information about which controller owns the
resource by use of the unique system id or IP address of the controller.
The controller is the top object of the hierarchy:
"/<Controller>/<Domain>/<SubDomain1>/<SubDomain2>/and so on"
TIP!
Error messages including such a path indicate where to look for the problem.
A minimum response time for real controllers should be expected to be in the order of 10-100
milliseconds.
Continued
3.2.5. Licence verification - applies only to versions earlier than PC SDK 5.10
Overview
Deployed PC applications does the license verification during execution, checking that all
application assemblies have been built on a PC with a valid PC SDK license key. If the key
is missing some functions in the PC SDK will raise an exception during execution.
NOTE!
The license verification was removed in the 5.10 release. So the licx file detailed in the next
section is no longer needed.
Licenses.licx
The license key should be placed in a “Licenses.licx” file, which should be added to your
project as an embedded resource. For your convenience, such a file is included in the PC SDK
installation at C:\Program Files\ABB Industrial IT\Robotics IT\SDK\PC SDK 5.xx. The key
for the PC SDK in VS 2005 is:
ABB.Robotics.Controllers.Licenses.PCSdk, ABB.Robotics.Controllers
NOTE!
The preceding path applies to RAB 5.09 and earlier versions. It does not apply for the new
installations.
TIP!
The License Compiler (Lc.exe) is a .Net Framework tool. It generates a .license file from a
.licx file. Search in MSDN (licx , lc.exe) if you want more detailed information.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 39
3 Run-time environment
3.3. Release upgrades and compatibility
NOTE!
PC SDK 5.10 supports Visual Studio 2005. PC SDK 5.11 to 5.13 supports VS 2005 and VS
2008.
RobotWare upgrades
At some time during the lifetime of your application, a robot system that your application
targets may be upgraded with a later RobotWare version.
The PC SDK it is normally compatible with a newer RobotWare release. The PC that hosts
the PC SDK application at the customer, however, still needs an upgrade of the Robot
Communication Runtime, so that it matches the new robotware release. For more
information, see ABB Industrial Robot Communication Runtime.msi on page 133. If you
decide to upgrade the PC SDK application, you must also remember to upgrade the runtime
environment of the customer’s PC. For more information, see Deployment of a PC SDK
application on page 133.
NOTE!
You find all the details about compatibility between different PC SDK versions in the Release
Notes.
© Copyright 2010 ABB. All rights reserved.
TIP!
When compiling your project, notice any warnings of obsolete methods, as these will
probably be removed in the next PC SDK release.
TIP!
Ildasm is a Microsoft tool, which comes with the installation of Visual Studio, that you may
find useful. It enables you to open the manifest of a specified assembly and quickly find out
about dependencies for example.
Find out more about it at http://msdn2.microsoft.com/en-us/library/aa309387(VS.71).aspx
Continued
Basic approach
In most aspects, using the PC SDK for application development presents no major difference
compared to ordinary .NET development. The .NET class libraries are used for everything
that is not robot specific. In addition, you use the public Controller API of the SDKs.
Step Action
1. Before you start
Learn the basics about PC SDK programming by reading all relevant sections of this
manual. Feel reassured that this is a timesaving activity and do not rush into coding.
2. During development
Frequently test application functionality.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 41
4 Developing Controller applications
4.2. Analysis and design
NOTE!
Customer satisfaction is what has driven the development of PC SDK. Do make sure that you
have really understood what the end-users of your application need.
42 3HAC036957-001 Revision: -
4 Developing Controller applications
4.2. Analysis and design
Consideration Advice
How much code is it going If it is going to be a very simple application with just one view
to be? and a few buttons there is no need even to split the code
between different classes and files.
If there will be a substantial amount of code and there might be
further extensions later on, spending time on design becomes
more relevant.
Will different developers If yes, spending time on design becomes more relevant.
work on different classes/
components? Will you
maintain the code yourself,
or may it be done by
others?
Is the real time aspect of If yes, coding efficiently is important. This will much more easily
the application important? be achieved if you spend some time on design.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 43
4 Developing Controller applications
4.3. Controller events and threads
Overview
A controller event is a message from the controller that something has happened. Events can
be caught and acted upon by PC SDK applications.
Controller events use their own threads. This means that user interface threads and controller
event threads can get into conflict. This section gives information on how to prevent this.
Controller events
PC SDK applications can subscribe to a number of controller events. These are all described
in the Reference Manual PC SDK.
The following table shows some events that exists in the PC SDK.
The event... occurs when...
StateChanged the controller state has changed.
OperatingModeChanged the controller operating mode has changed.
ExecutionStatusChanged the controller execution status has changed.
Changed the value or the state of the I/O signal has changed.
MessageWritten the EventLog has a new message
ValueChanged the value of a RAPID data has changed.
NOTE!
There is no guarantee you will get an initial event when setting up/activating a controller
event. You need to read the initial state from the controller.
switch using the Invoke or BeginInvoke method. For more information with code
examples, see Invoke method on page 45.
On the other hand, if the controller event should NOT cause any update of the user interface,
you should not take any special action. Using Invoke / BeginInvoke is performance
demanding and should not be used more than necessary.
NOTE!
Thread conflicts often cause hangings. The PC application UI then stops responding and the
application has to be restarted.
Examine what exception has been thrown when you encounter such a situation. The
exception System.InvalidOperationException (PC platform) indicate thread
conflicts. See the next section for information on how to use Invoke to solve the problem.
44 3HAC036957-001 Revision: -
4 Developing Controller applications
4.3. Controller events and threads
Invoke method
All PC application windows views must inherit Control / TpsControl, which implement
Invoke and BeginInvoke. These methods execute the specified delegate/event handler on
the thread that owns the control's underlying window handle, thus enforcing a switch from a
worker thread to the GUI thread. This is precisely what is needed when a controller event
needs to be communicated to the end user of the system.
Invoke should be called inside the event handler taking care of the controller event. Notice
that you have to create a new object array for the sender and argument objects:
VB:
Me.Invoke(New EventHandler(UpdateUI), New [Object]() {Me, e})
C#:
this.Invoke(new EventHandler(UpdateUI), new Object[] { this, e });
Also notice that if you use EventHandler in the Invoke method and not the specific
delegate class, for exampleDataValueChangedEventHandler, you need to typecast the
argument in the delegate which updates the user interface. How this is done is shown by the
example below:
VB:
Private Sub UpdateUI(ByVal sender As Object, ByVal e As EventArgs)
Dim args As StateChangedEventArgs
args = DirectCast(e, StateChangedEventArgs)
Me.label1.Text = args.NewState.ToString()
End Sub
C#:
private void UpdateUI(object sender, EventArgs e)
{
StateChangedEventArgs args;
args = (StateChangedEventArgs)e;
this.label1.Text = args.NewState.ToString();
}
© Copyright 2010 ABB. All rights reserved.
NOTE!
The difference between Invoke and BeginInvoke is that the former makes a synchronous
call and will hang until the GUI operation is completed, whereas BeginInvoke executes the
specified event handler asynchronously. Which method you want to use depends on the logics
of your program. The recommendation is to choose BeginInvoke whenever possible.
NOTE!
If your code tries to access a GUI control from a background thread the .NET common
language runtime will throw a System.NotSupportedException (FlexPendant platform)
or a System.InvalidOperationException (PC platform).
3HAC036957-001 Revision: - 45
4 Developing Controller applications
4.4. User Authorization System
Overview
In the robot controller there is a system controlling user access: the User Authorization
System (UAS). If this feature is used each user needs a user name and a password to log on to
a robot controller via RobotStudio. If the controller connection for any reason is lost, you
need to log on again.
The controller holds information on which operations different users are allowed to perform.
The UAS configuration is done in RobotStudio.
TIP!
To learn more about UAS use the help function in RobotStudio.
End If
C#:
if (uas.CheckDemandGrant(Grant.LoadRapidProgram))
{
aTask.LoadModuleFromFile(localFile, RapidLoadMode.Replace);
}
NOTE!
The PC SDK application cannot override the UAS configuration. This means that the system
will in the end prevent you from performing an action that is not allowed.
46 3HAC036957-001 Revision: -
4 Developing Controller applications
4.4. User Authorization System
MessageBox feedback
If a UAS grant is missing, you should be informed about it. This can be done in a message as
shown in this example:
msg = "You are not allowed to perform this operation, talk to your
system administrator if you need access."
title = "User Authorization System"
TIP!
Learn more about UAS and Grant members in the Reference Manual PC SDK.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 47
4 Developing Controller applications
4.5. Exception handling
Overview
The .NET programming languages provide built-in support for exception handling, which
allows the program to detect and recover from errors during execution.
In managed code, execution cannot continue in the same thread after an unhandled exception.
The thread terminates, and if it is the program thread, the program itself terminates. To avoid
this, accurate exception handling should be used.
Exceptions thrown from the controller are handled by the PC SDK ExceptionManager,
which converts the internal HRESULT to a .NET exception with a reasonable exception
description, before it is thrown to the custom application layer. The application handling of
these exceptions should apply to general .NET rules.
Exceptions are expensive in a performance perspective and should be avoided if there are
other alternatives. If possible use a try-finally block to clean up system and unmanaged
resource allocations.
Try-catch-finally
Exceptions are handled in try - catch (-finally ) blocks, which execute outside the
normal flow of control.
The try block wraps one or several statements to be executed. If an exception occurs within
this block, execution jumps to the catch block, which handles the exception.
The finally block is executed when the Try block is exited, no matter if an exception has
occurred and been handled. It is used to clean up system or controller resources.
If you do not know what exceptions to expect or how to handle them, you can catch them and
do nothing. This, however, may result in difficult error tracing, as exceptions include
information on what caused the problem. Therefore, try at least to display the exception
message, either by using a message box or the types Debug or Trace.
Typecasting
When typecasting Signal or RapidData values, for example, there is a potential risk of
typecast exceptions. To avoid this you can check the object using the is operator for both
© Copyright 2010 ABB. All rights reserved.
C#:
if (aRapidData.Value is Num)
{
Num aNum = (Num)aRapidData.Value;
......
}
48 3HAC036957-001 Revision: -
4 Developing Controller applications
4.5. Exception handling
In C# it is also possible to use the as operator for reference types. A null value is returned if
the type is not the expected one:
C#:
DigitalSignal di = this.aController.IOSystem.GetSignal(“UserSig”)
as DigitalSignal;
if (di == null)
{
MessageBox.Show(this, null, “Wrong type”);
}
3HAC036957-001 Revision: - 49
4 Developing Controller applications
4.6. How to use the online help
Overview
The online help is available along with the installation of PC SDK and is accessible from
Windows Start menu.
You are recommended to read this Application manual carefully as you develop your first PC
SDK application. PC SDK Reference is an important complement to this manual, as these
make up the complete reference to the class libraries of PC SDK. For more information, see
Documentation and help on page 15.
NOTE!
The SDK Reference is NOT integrated in Visual Studio. You must access it from the Start
menu.
TIP!
For more information on the web address to RobotStudio Community, where PC SDK
developers discuss software problems and solutions online, see Documentation and help on
page 15.
50 3HAC036957-001 Revision: -
5 Using the PC SDK
5.1. Controller API
PC SDK domains
The PC SDK class libraries are organized in the following domains:
• Controllers
• ConfigurationDomain
• Discovery
• EventLogDomain
• FileSystemDomain
• Hosting
• IOSystemDomain
• Messaging
• MotionDomain
• RapidDomain
• UserAuthorizationManagement
CAPI illustration
The classes used to access robot controller functionality together make up the Controller API
(CAPI). The following illustration shows a part of the CAPI object model:
© Copyright 2010 ABB. All rights reserved.
8.2.2_1
3HAC036957-001 Revision: - 51
5 Using the PC SDK
5.1. Controller API
PC SDK Reference
This Application manual covers some of the PC SDK functionality, but is by no means a
complete guide to the APIs of the PC SDK.
The Reference Manual PC SDK is the complete reference of the PC SDK class libraries. It
should be your companion while programming.
It can be launched from Windows Start menu by pointing at Programs - ABB Industrial IT
- Robotics IT - RobotStudio 5.xx - SDK and selecting PC SDK Reference.
52 3HAC036957-001 Revision: -
5 Using the PC SDK
5.2. Create a simple PC SDK application
Overview
To get started with programming, create a simple application that displays all the virtual and
real controllers on the network. It should then be possible to log on to a controller and start
RAPID execution.
CAUTION!
Remote access to controllers must be handled carefully. Make sure you do not unintentionally
disturb a system in production.
Step Action
1. On the File menu in Visual Studio, select New and click Project. Select a Windows
Application project.
2. Add the references to the PC SDK assemblies, ABB.Robotics.dll and ABB.Robot-
ics.Controllers.dll, to the project. The assemblies are located in the installation
directory, by default at C:\Program Files\ABB Industrial IT\Robotics IT\SDK\PC SDK
5.xx.
3. Open Form1.cs and add the needed namespace statements at the top of the source
code page:
VB:
Imports ABB.Robotics
Imports ABB.Robotics.Controllers
Imports ABB.Robotics.Controllers.Discovery
Imports ABB.Robotics.Controllers.RapidDomain
C#:
using ABB.Robotics;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;
© Copyright 2010 ABB. All rights reserved.
using ABB.Robotics.Controllers.RapidDomain;
4. In the Solution Explorer right-click Form1.cs and select View Designer. Create
the Graphical User Interface according to the instruction in the next section.
3HAC036957-001 Revision: - 53
5 Using the PC SDK
5.2. Create a simple PC SDK application
7.1_1
Step Action
1. Change the Text property of the form to “Network scanning window”.
2. Change its Size to 850; 480.
3. Add a ListView control to the form. Set the following properties to get a similar
look as in the figure above:
FullRowSelect - True
GridLines - True
View - Details
4. Add the columns for IPAdress, ID, Availability, Virtual, System name, RobotWare © Copyright 2010 ABB. All rights reserved.
Version and Controller name and adjust the width of the columns.
5. Add a Panel with a Button under the listview. Set the Text of the button.
54 3HAC036957-001 Revision: -
5 Using the PC SDK
5.2. Create a simple PC SDK application
C#:
private NetworkScanner scanner = null;
private Controller controller = null;
private Task[] tasks = null;
private NetworkWatcher networkwatcher = null;
As the application is supposed to scan the network as soon as it is started, we can put the code
for it in the Form1_Load event handler, like this:
VB:
Me.scanner = New NetworkScanner
Me.scanner.Scan()
Dim controllers As ControllerInfoCollection =
Me.scanner.Controllers
Dim controllerInfo As ControllerInfo = Nothing
Dim item As ListViewItem
For Each controllerInfo In controllers
item = New ListViewItem(controllerInfo.IPAddress.ToString())
item.SubItems.Add(controllerInfo.Id)
item.SubItems.Add(controllerInfo.Availability.ToString())
item.SubItems.Add(controllerInfo.IsVirtual.ToString())
item.SubItems.Add(controllerInfo.SystemName)
item.SubItems.Add(controllerInfo.Version.ToString())
item.SubItems.Add(controllerInfo.ControllerName)
Me.listView1.Items.Add(item)
item.Tag = controllerInfo
Next
C#:
this.scanner = new NetworkScanner();
this.scanner.Scan();
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 55
5 Using the PC SDK
5.2. Create a simple PC SDK application
C#:
this.networkwatcher = new NetworkWatcher(scanner.Controllers);
this.networkwatcher.Found += new
EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
this.networkwatcher.Lost += new
EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
this.networkwatcher.EnableRaisingEvents = true;
NOTE!
In C# the event handler skeleton is auto generated using the Tab key twice after “+=” in the
above statements. If you prefer, you can use a simplified syntax when using generic event
handlers:
networkwatcher.Found += HandleFoundEvent;
Handle event
As the events will be received on a background thread and should result in an update of the
user interface the Invoke method must be called in the event handler. For more information
on how to force execution from background to GUI thread, see Invoke method on page 45. © Copyright 2010 ABB. All rights reserved.
VB:
Private Sub HandleFoundEvent(ByVal sender As Object, ByVal e As
NetworkWatcherEventArgs)
Me.Invoke(New EventHandler(Of
NetworkWatcherEventArgs)(AddControllerToListView), New
[Object]() {Me, e})
End Sub
C#:
void HandleFoundEvent(object sender, NetworkWatcherEventArgs e)
{
this.Invoke(new
EventHandler<NetworkWatcherEventArgs>(AddControllerToList
View), new Object[] { this, e });
}
56 3HAC036957-001 Revision: -
5 Using the PC SDK
5.2. Create a simple PC SDK application
Step Action
1. Generate the DoubleClick event of the ListView.
2. In the event handler create a Controller object that represents the selected
robot controller.
3. Log on to the selected controller. For more information, see the code sample
of Implement event handler on page 57.
3HAC036957-001 Revision: - 57
5 Using the PC SDK
5.2. Create a simple PC SDK application
C#:
ListViewItem item = this.listView1.SelectedItems[0];
if (item.Tag != null)
{
ControllerInfo controllerInfo = (ControllerInfo)item.Tag;
if (controllerInfo.Availability ==
Availability.Available)
{
if (this.controller != null)
{
this.controller.Logoff();
this.controller.Dispose();
this.controller = null;
}
© Copyright 2010 ABB. All rights reserved.
this.controller =
ControllerFactory.CreateFrom(controllerInfo);
this.controller.Logon(UserInfo.DefaultUser);
}
else
{
MessageBox.Show("Selected controller not available.");
}
}
58 3HAC036957-001 Revision: -
5 Using the PC SDK
5.2. Create a simple PC SDK application
NOTE!
The check to see whether the Controller object already exists is important, as you should
explicitly log off and dispose of any existing controller object before creating a new one. The
reason is that a logon session allocates resources that should not be kept longer than
necessary.
End If
Catch ex As System.InvalidOperationException
MessageBox.Show("Mastership is held by another client." &
ex.Message)
Catch ex As System.Exception
MessageBox.Show("Unexpected error occurred: " & ex.Message)
End Try
End Sub
3HAC036957-001 Revision: - 59
5 Using the PC SDK
5.2. Create a simple PC SDK application
C#:
private void button1_Click(object sender, EventArgs e)
{
try
{
if (controller.OperatingMode ==
ControllerOperatingMode.Auto)
{
tasks = controller.Rapid.GetTasks();
using (Mastership m
=Mastership.Request(controller.Rapid))
{
//Perform operation
tasks[0].Start();
}
}
else
{
MessageBox.Show("Automatic mode is required to start
execution from a remote client.");
}
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("Mastership is held by
another client." + ex.Message);
}
catch (System.Exception ex)
{
MessageBox.Show("Unexpected error occurred: " + ex.Message);
}
© Copyright 2010 ABB. All rights reserved.
}
60 3HAC036957-001 Revision: -
5 Using the PC SDK
5.3. Discovery domain
Overview
To create a connection to the controller from a PC SDK application it has to make use of the
Netscan functionality of the Discovery namespace. A NetworkScanner object must be
created and a Scan call must be performed.
For the PC SDK to establish a connection either RobotStudio or Robot Communications
Runtime must be installed on the PC hosting the PC SDK application. Robot
Communications Runtime can be installed from C:\Program Files\ABB Industrial
IT\Robotics IT\SDK\PC SDK 5.xx\Redistributable\RobotCommunicationRuntime, if
RobotStudio is not installed.
To find out what controllers are available on the network you use the NetworkScanner
methods Scan, Find, GetControllers and GetRemoteControllers.
NetworkScanner
The NetworkScanner class can be declared and represented at class level. No scanning is
done until the Scan method is called. When the GetControllers method is called a
collection of ControllerInfo objects is returned. Each such object holds information about
a particular controller connected to the local network. Both virtual and real controllers are
detected this way.
VB:
Private aScanner As NetworkScanner = New NetworkScanner
...’ Somewhere in the code
aScanner.Scan()
Dim aCollection As ControllerInfo() = aScanner.GetControllers()
C#:
private NetworkScanner aScanner = new NetworkScanner();
... // Somewhere in the code
aScanner.Scan();
ControllerInfo[] aCollection = aScanner.GetControllers();
© Copyright 2010 ABB. All rights reserved.
For a complete code sample, see Implement network scanning on page 54.
If only real controllers are of interest, you can first scan the network and then request only
real controllers using the NetworkScannerSearchCriterias enumeration in the
GetControllers method.
VB:
Dim aCollection As ControllerInfo() =
aScanner.GetControllers(NetworkScannerSearchCriterias.Real)
C#:
ControllerInfo[] aCollection =
aScanner.GetControllers(NetworkScannerSearchCriterias.Real);
If you know which controller system you want to connect to you can call the Find method,
which finds a specified controller on the network. It takes the system ID as a System.Guid
data type as argument. The system’s globally unique identifier (GUID) can be find in the
system.guid file in the INTERNAL folder of the robot system file system.
3HAC036957-001 Revision: - 61
5 Using the PC SDK
5.3. Discovery domain
ControllerInfo object
When a network scan is performed a collection of ControllerInfo objects is returned. The
ControllerInfo object has information about availability. Remember that the ControllerInfo
object is not updated when controller status changes. If you again need to find out if a
controller is available, you need to perform a new network scan or use an existing
Controller object and check the status directly.
NetworkScanner.AddRemoteController(ipAddress)
Catch ex As FormatException
Me.textBox1.Text = "Wrong IP address format"
End Try
C#:
System.Net.IPAddress ipAddress;
try
{
ipAddress = System.Net.IPAddress.Parse(this.textBox1.Text);
NetworkScanner.AddRemoteController(ipAddress);
© Copyright 2010 ABB. All rights reserved.
}
catch (FormatException ex)
{
this.textBox1.Text = "Wrong IP address format";
}
NetworkWatcher
By using a NetworkWatcher object you can supervise network changes and find out when
a new controller is found or when a controller is lost. For a complete code example, see Add
a network watcher on page 56.
62 3HAC036957-001 Revision: -
5 Using the PC SDK
5.4. Accessing the controller
Controller object
By using a Controller object you can get access to the different domains of the robot
controller, for example IO signals, RAPID, file system and elog messages.
To create a Controller object you normally make a call to the ControllerFactory:
VB:
Dim info As New ControllerInfo(New Guid("systemid"))
Dim aController As Controller
aController = ControllerFactory.CreateFrom(info)
C#:
ControllerInfo info = new ControllerInfo(new Guid("systemid"));
Controller aController;
aController = ControllerFactory.CreateFrom(info);
The argument is a ControllerInfo object, which may have been retrieved during a
network scan, see NetworkScanner on page 61. It is also possible to add an optional argument
if the IP address of the controller or the system ID (guid) should be used.
If the PC application is supposed to work with a single controller it can be specified in an
app.config file. The default constructor can then be used to create the controller object, for
example aController = new Controller(). For more information, see
<defaultSystem> on page 36.
If several classes in your application need to access the controller, it is recommended that they
all reference the same Controller object. This is done either by passing the Controller
object as an argument to the constructor or by using a Controller property.
NOTE!
You should be aware that the .NET objects created for operations toward the robot controller
will access native resources (C++ and COM code). The .NET garbage collector does not
collect such objects, but these must be disposed of explicitly by the application programmer.
For more information, see Memory management in PC applications on page 63.
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 63
5 Using the PC SDK
5.4. Accessing the controller
If your application is running in a Single Threaded Apartment (STA) the Dispose call will
dispose of managed objects, but native resources (created internally by the PC SDK) will
remain. To release these native objects, the method ReleaseUnmanagedResources should
be called periodically, for example when you clicks a certain button or each time data has
been written to the controller. The method call is not costly.
For an application running in a Multi Threaded Apartment (MTA) the Dispose call will
remove both managed and native objects.
NOTE!
The method Controller.ReleaseUnmanagedResources should be called once in a
while to avoid memory leaks in PC SDK applications running in STA.
Dispose
It is the creator of a disposable object that is responsible for its lifetime and for calling
Dispose. A check should be done that the object still exists and any subscriptions to
controller events should be removed before the Dispose call. This is how you dispose of a
Controller object:
VB:
If aController IsNot Nothing Then
aController.Dispose()
aController = Nothing
End If
C#:
if (aController != null)
{
aController.Dispose();
aController = null;
}
If it is necessary for your application to handle users with different rights, these users can be
configured by using the UserAuthorizationManagement namespace or by using the UAS
administration tool in RobotStudio. This is how you create a new UserInfo object for login
purposes.
VB:
Dim aUserInfo As New UserInfo("name", "password")
C#:
UserInfo aUserInfo = new UserInfo("name", "password");
64 3HAC036957-001 Revision: -
5 Using the PC SDK
5.4. Accessing the controller
NOTE!
It is necessary to log off from the controller at application shut down at the latest.
VB: AController.LogOff()
C#: aController.LogOff();
Mastership
In order to get write access to some of the controller domains the application has to request
mastership. The Rapid domain, that is, tasks, programs, modules, routines and variables that
exist in the robot system, is one such domain. The Configuration domain is another.
For more information, see Mastership on page 33.
It is important to release mastership after a modification operation. One way of doing this is
applying the using statement, which results in an automatic disposal of the Mastership
object at the end of the block. Another possibility is releasing mastership in a Finally block,
which is executed after the Try and Catch blocks. See how it can be coded in the examples
of Start program execution on page 59.
Controller events
The Controller object provides several public events, which enable you to listen to
operating mode changes, controller state changes, mastership changes and so on.
VB:
AddHandler AController.OperatingModeChanged, AddressOf
OperatingModeChanged
AddHandler AController.StateChanged, AddressOf StateChanged
AddHandler AController.ConnectionChanged, AddressOf
ConnectionChanged
C#:
AController.OperatingModeChanged += new
EventHandler<OperatingModeChangeEventArgs>(OperatingModeChan
ged);
AController.StateChanged += new
EventHandler<StateChangedEventArgs>(StateChanged);
© Copyright 2010 ABB. All rights reserved.
AController.ConnectionChanged += new
EventHandler<ConnectionChangedEventArgs>(ConnectionChanged);
NOTE!
Controller events use their own threads. Carefully study Controller events and threads on
page 44 to avoid threading conflicts.
NOTE!
PC SDK 5.09 and onwards uses the generic event handling introduced by .NET Framework
2.0.
CAUTION!
Do not rely on receiving an initial event when setting up/activating a controller event. There
is no guarantee an event will be triggered, so you had better read the initial state from the
controller.
3HAC036957-001 Revision: - 65
5 Using the PC SDK
5.4. Accessing the controller
Backup sample
As the backup process is performed asynchronously you can add an event handler to receive
a BackupCompleted event when the backup is completed. The backup directory should be
created in the system backup directory, or else an exception will be thrown.
VB:
Dim backupDir As String = "(BACKUP)$" & backupDirName
AddHandler Me.aController.BackupCompleted, AddressOf
aController_BackupCompleted
Me.aController.Backup(backupDir)
C#:
string backupDir = "(BACKUP)$" + backupDirName;
this.aController.BackupCompleted += new
EventHandler<BackupEventArgs>(aController_BackupCompleted);
this.aController.Backup(backupDir);
Restore sample
The Restore method is synchronous, that is, execution will not continue until the restore
operation is completed.
VB:
Dim restoreDir As String = "(BACKUP)$" & dirName
Using mc As Mastership =
Mastership.Request(Me.aController.Configuration), mr As
Mastership = Mastership.Request(Me.aController.Rapid)
Me.aController.Restore(restoreDir, RestoreIncludes.All,
RestoreIgnores.All)
End Using
C#:
© Copyright 2010 ABB. All rights reserved.
NOTE!
You need to be logged in with required grants to perform the above functions.
66 3HAC036957-001 Revision: -
5 Using the PC SDK
5.4. Accessing the controller
VirtualPanel
You can programmatically change the operating mode of the virtual IRC5 using the
VirtualPanel class and its ChangeMode method. This blocks the application thread until
you manually accepts the mode change to Auto using the Virtual FlexPendant. An alternative
to blocking the application thread eternally is to add a time-out and use a try-catch block
to catch the TimeoutException.
VB:
Dim vp As VirtualPanel = VirtualPanel.Attach(aController)
Try
'user need to acknowledge mode change on flexpendent
vp.ChangeMode(ControllerOperatingMode.Auto, 5000)
Catch ex As ABB.Robotics.TimeoutException
Me.textBox1.Text = "Timeout occurred at change to auto"
End Try
vp.Dispose()
C#:
VirtualPanel vp = VirtualPanel.Attach(aController);
try
{
//user need to acknowledge mode change on flexpendent
vp.ChangeMode(ControllerOperatingMode.Auto, 5000);
}
catch (ABB.Robotics.TimeoutException ex)
{
this.textBox1.Text = "Timeout occurred at change to auto";
}
vp.Dispose();
VB:
Dim vp As VirtualPanel = VirtualPanel.Attach(aController)
vp.BeginChangeOperatingMode(ControllerOperatingMode.Auto, New
AsyncCallback(ChangedMode), vp)
C#:
VirtualPanel vp = VirtualPanel.Attach(aController);
vp.BeginChangeOperatingMode(ControllerOperatingMode.Auto, new
AsyncCallback(ChangedMode), vp);
3HAC036957-001 Revision: - 67
5 Using the PC SDK
5.4. Accessing the controller
The callback method must have the following signature and call the
EndChangeOperatingMode as well as dispose the VirtualPanel.
VB:
Private Sub ChangedMode(ByVal iar As IAsyncResult)
Dim vp As VirtualPanel = DirectCast(iar.AsyncState,
VirtualPanel)
vp.EndChangeOperatingMode(iar)
vp.Dispose()
......
End Sub
C#:
private void ChangedMode(IAsyncResult iar)
{
VirtualPanel vp = (VirtualPanel) iar.AsyncState;
vp.EndChangeOperatingMode(iar);
vp.Dispose();
....
}
Learn more
This Application manual only covers some of the PC SDK functionality. To get the full
potential of the PC SDK you should make use of the PC SDK Reference located in the PC
SDK installation directory. For more information, see PC SDK Reference on page 52.
You can also learn a lot by becoming an active member of the RobotStudio Community. Its
PC SDK User Forum should be your number one choice when you find yourself stuck with
a coding issue you cannot solve on your own. For more information, see RobotStudio
Community on page 16.
68 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.1. Working with RAPID data
Overview
The RapidDomain namespace enables access to RAPID data in the robot system. There are
numerous PC SDK classes representing the different RAPID data types. There is also a
UserDefined class used for referring to the RECORD structures in RAPID.
The ValueChanged event enables notification from the controller when persistent RAPID
data has changed.
To speed up event notification from the controller there is a new functionality in PC SDK
5.10, which allows you to set up subscription priorities. This possibility applies to I/O signals
and persistent RAPID data. This mechanism is further described in Implementing high
priority data subscriptions on page 75.
NOTE!
To read RAPID data you need to log on to the controller. To modify RAPID data you must
also request mastership of the Rapid domain.
Direct access
Direct access requires less memory and is faster, and is therefore recommended if you do not
need to use the task and module objects afterwards.
The following example shows how to create a RapidData object that refers to the instance
“reg1” in the USER module.
VB:
Dim rd As RapidData = aController.Rapid.GetRapidData("T_ROB1",
"user", "reg1")
© Copyright 2010 ABB. All rights reserved.
C#:
RapidData rd = aController.Rapid.GetRapidData("T_ROB1", "user",
"reg1");
Hierarchical access
If you need the task and module objects hierarchical access can be more efficient.
GetRapidData exists in the Rapid, Task and Module class.
VB:
rd = aController.Rapid.GetTask("T_ROB1").GetModule("user").
GetRapidData("reg1")
C#:
rd = aController.Rapid.GetTask("T_ROB1").GetModule("user").
GetRapidData("reg1");
3HAC036957-001 Revision: - 69
5 Using the PC SDK
5.5.1. Working with RAPID data
70 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.1. Working with RAPID data
C#:
//declare a variable of data type RapidDomain.Bool
ABB.Robotics.Controllers.RapidDomain.Bool rapidBool;
ABB.Robotics.Controllers.RapidDomain.RapidData rd =
aController.Rapid.GetRapidData("T_ROB1", "MainModule",
"flag");
//test that data type is correct before cast
if (rd.Value is ABB.Robotics.Controllers.RapidDomain.Bool)
{
rapidBool =
(ABB.Robotics.Controllers.RapidDomain.Bool)rd.Value;
//assign the value of the RAPID data to a local variable
bool boolValue = rapidBool.Value;
}
If you want only to read this variable you can use the following technique instead of creating
a RapidDomain.Bool object:
VB:
Dim b As Boolean = Convert.ToBoolean(rd.Value.ToString())
C#:
bool b = Convert.ToBoolean(rd.Value.ToString());
The .NET type ToolData (representing the RAPID data type tooldata) can be created like
this:
VB:
Dim aTool As ToolData
If TypeOf rd.Value Is ToolData Then
aTool = DirectCast(rd.Value, ToolData)
End If
C#:
ToolData aTool;
if (rd.Value is ToolData)
© Copyright 2010 ABB. All rights reserved.
{
aTool = (ToolData) rd.Value;
}
IRapidData.ToString method
All RapidDomain structures representing RAPID data types implement the IRapidData
interface. It has a ToString method, which returns the value of the RAPID data in the form
of a string. This is a simple example:
string bValue = rapidBool.ToString();
The string is formatted according to the principle described in IRapidData.FillFromString
method on page 72.
3HAC036957-001 Revision: - 71
5 Using the PC SDK
5.5.1. Working with RAPID data
The following is an example of a complex data type. The ToolData Tframe property is of
type Pose. Its Trans value is displayed in a label in the format [x, y, z].
VB:
Me.label1.Text = aTool.Tframe.Trans.ToString()
C#:
this.label1.Text = aTool.Tframe.Trans.ToString();
IRapidData.FillFromString method
The IRapidData interface also has a FillFromString method, which fills the object with
a valid RAPID string representation. The method can always be used when you need to
modify RAPID data. Using the method with the RapidDomain.Bool variable used earlier
in the chapter will look like this:
rapidBool.FillFromString("True")
Using it for a RapidDomain.Num variable is similar:
rapidNum.FillFromString("10")
String format
The format is constructed recursively. The following example illustrate it.
Example:
The RapidDomain.Pose structure represents the RAPID data type pose, which describes
how a coordinate system is displaced and rotated around another coordinate system.
public struct Pose : IRapidData
{
public Pos trans;
public Orient rot;
}
The following is an example in RAPID:
VAR pose frame1;
...
frame1.trans := [50, 0, 40];
frame1.rot := [1, 0, 0, 0]; © Copyright 2010 ABB. All rights reserved.
72 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.1. Working with RAPID data
C#:
if (rd.Value is Pose)
{
Pose rapidPose = (Pose) rd.Value;
rapidPose.FillFromString("[[1.0, 0.5, 0.0, 0.0][10, 15, 10]]");
rd.Value = rapidPose;
}
NOTE!
The string format must be carefully observed. If the string argument has a wrong format, a
RapidDataFormatException is thrown.
C#:
//Assign new value to .Net variable
rapidBool.Value = false;
//Request mastership of Rapid before writing to the controller
© Copyright 2010 ABB. All rights reserved.
this.master = Mastership.Request(this.aController.Rapid);
//Change: controller is repaced by aController
rd.Value = rapidBool;
//Release mastership as soon as possible
this.master.Dispose();
For more information on how the controller handles write accesa, see Mastership on page 33
and for another code example of implementing mastership in a PC SDK application, see Start
program execution on page 59.
The preceding example is simple, as the value to change was a simple bool. Often, however,
RAPID uses complex structures. By using the FillFromString method you can assign a
new Value to any RapidData and write it to the controller.
3HAC036957-001 Revision: - 73
5 Using the PC SDK
5.5.1. Working with RAPID data
The string must be formatted according to the principle described in the IRapidData.
FillFromString section. The following example shows how to write a new value to the
pos structure (x, y, z) of a RAPID tooldata:
VB:
Dim aPos As New Pos()
aPos.FillFromString("[2,3,3]")
aTool.Tframe.Trans = aPos
Using Mastership.Request(aController.Rapid)
rd.Value = aTool
End Using
C#:
Pos aPos = new Pos();
aPos.FillFromString("[2,3,3]");
aTool.Tframe.Trans = aPos;
using (Mastership.Request(aController.Rapid))
{
rd.Value = aTool;
}
NOTE!
The new value is not written to the controller until the last statement is executed.
Add subscription
This is how you add a subscription to the ValueChanged event:
VB:
AddHandler rd.ValueChanged, AddressOf rd_ValueChanged © Copyright 2010 ABB. All rights reserved.
C#:
rd.ValueChanged += new
EventHandler<DataValueChangedEventArgs>(rd_ValueChanged);
Handle event
The following example shows the implementation of the event handler. Remember that
controller events use their own threads, and avoid Winforms threading problems by the use
of Control.Invoke, which forces the execution from the background thread to the GUI
thread.
VB:
Private Sub rd_ValueChanged(ByVal sender As Object, ByVal e As
DataValueChangedEventArgs)
Me.Invoke(New EventHandler(UpdateGUI), sender, e)
End Sub
74 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.1. Working with RAPID data
C#
private void rd_ValueChanged(object sender,
DataValueChangedEventArgs e)
{
this.Invoke(new EventHandler(UpdateGUI), sender, e);
}
To learn more about potential threading conflicts in PC SDK applications, see Controller
events and threads on page 44.
NOTE!
Subscriptions work only for RAPID data declared as PERS.
priorities for persistent RAPID data. To do this, you can use the Subscribe method and the
enumeration EventPriority as argument. The following example shows an ordinary signal
subscription and a subscription with high priority:
VB:
AddHandler rd.ValueChanged, AddressOf rd_ValueChanged
rd.Subscribe(rd_ValueChanged, EventPriority.High)
C#:
rd.ValueChanged += new
EventHandler<DataValueChangedEventArgs>(rd_ValueChanged);
rd.Subscribe(rd_ValueChanged, EventPriority.High);
To deactivate subscriptions with high priority you can call the Unsubscribe method as
described in the following example:
VB:
rd.Unsubscribe(rd_ValueChanged)
3HAC036957-001 Revision: - 75
5 Using the PC SDK
5.5.1. Working with RAPID data
C#:
rd.Unsubscribe(rd_ValueChanged);
NOTE!
High priority subscriptions can be used for I/O signals and RAPID data declared PERS. The
controller can handle 64 high priority subscriptions.
RapidData disposal
You are recommended to dispose the RapidData objects when they are no longer needed.
For more information, see Memory management in PC applications on page 63.
VB:
If rd IsNot Nothing Then
rd.Dispose()
rd = Nothing
End If
C#:
if (rd != null)
{
rd.Dispose();
rd = null;
}
76 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.2. Handling arrays
Overview
In RAPID you can have up to three dimensional arrays. These are accessible by using a
RapidData object like for any other RAPID data.
There are mainly two ways of accessing each individual element of an array: by indexers or
by an enumerator.
ArrayData object
If the RapidData references a RAPID array is Value property returns an object of
ArrayData type. Before making a cast, check the type using the is operator or by using the
IsArray property on the RapidData object.
VB:
Dim rd As RapidData = aController.Rapid.GetRapidData("T_ROB1",
"user", "num_array")
If rd.IsArray Then
Dim ad As ArrayData = DirectCast(rd.Value, ArrayData)
.....
End If
C#:
RapidData rd = aController.Rapid.GetRapidData("T_ROB1", "user",
"num_array");
if (rd.IsArray)
{
ArrayData ad = (ArrayData)rd.Value;
.....
}
Array dimensions
The dimension of the array is returned by the Rank property. If you need to check the length
of the individual arrays you can use the GetLength method on the ArrayData object
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 77
5 Using the PC SDK
5.5.2. Handling arrays
C#:
double aSum = 0d;
Num aNum; © Copyright 2010 ABB. All rights reserved.
RapidData rd = aController.Rapid.GetRapidData("T_ROB1", "user",
"num_array");
ArrayData ad = (ArrayData)rd.Value;
int aRank = ad.Rank;
if (ad.Rank == 1)
{
for (int i = 1; i <= ad.Length; i++)
{
aNum = (Num)ad[i];
aSum += (double)aNum;
}
}
else if (ad.Rank == 2)
{
for (int i = 1; i <= ad.GetLength(0); i++)
78 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.2. Handling arrays
{
for (int j = 1; j <= ad.Length; j++)
{
aNum = (Num)ad[i, j];
aSum += (double)aNum;
}
}
}
else
{
for (int i = 0; i < ad.GetLength(0); i++)
{
for (int j = 0; j < ad.GetLength(1); j++)
{
for (int k = 0; k < ad.GetLength(2); k++)
{
aNum = (Num)ad[i, j, k];
aSum += (double)aNum;
}
}
}
}
Next
C#:
double sum = 0d;
foreach (Num ANum in ad)
{
sum += (double)ANum;
}
3HAC036957-001 Revision: - 79
5 Using the PC SDK
5.5.3. ReadItem and WriteItem methods
Overview
An alternative way of accessing RAPID data stored in an array are the ReadItem and
WriteItem methods.
ReadItem method
Using the ReadItem method you can directly access a RapidData item in an array, for
example an array with RobTargets or Nums. The index to the item is explicitly specified in
the ReadItem call. The first item is in position 1, that is, the array is 1-based as in RAPID.
VB:
Dim aNum As Num = DirectCast(rd.ReadItem(1, 2), Num)
C#:
Num aNum = (Num)rd.ReadItem(1, 2);
This example retrieves the second Num value in the first array of the RAPID data variable
referenced by rd.
WriteItem method
It is possible to use the WriteItem method to write to an individual RAPID data item in an
array. The following example shows how to write the result of an individual robot operation
into an array representing a total robot program with several operations:
VB:
Dim aNum As New Num(OPERATION_OK)
rd.WriteItem(aNum, 1, 2)
C#:
Num aNum = new Num(OPERATION_OK);
rd.WriteItem(aNum, 1, 2);
80 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.4. UserDefined data
Overview
RECORD structures are common in RAPID code. To handle these unique data types, a
UserDefined class is available. This class has properties and methods to handle individual
components of a RECORD.
In some cases implementing your own structure can improve application design and code
maintenance.
Each individual string can then be used in a FillFromString method to convert the
component into a specific data type, for example RobTarget or ToolData. For more
information, see IRapidData.FillFromString method on page 72.
3HAC036957-001 Revision: - 81
5 Using the PC SDK
5.5.4. UserDefined data
82 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.4. UserDefined data
}
}
private void SearchSymbolStructure(RapidSymbol[] rsCol)
{
RapidDataType theDataType;
foreach (RapidSymbol rs in rsCol)
{
Console.WriteLine("RapidSymbol name = " + rs.Name);
theDataType = RapidDataType.GetDataType(rs);
Console.WriteLine("DataType = " + theDataType.Name);
if (theDataType.IsRecord)
{
RapidSymbol[] syms =
theDataType.GetComponents();
SearchSymbolStructure(syms);
}
}
}
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 83
5 Using the PC SDK
5.5.4. UserDefined data
84 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.4. UserDefined data
DataType = num
RapidSymbol name = eax_b
DataType = num
RapidSymbol name = eax_c
DataType = num
RapidSymbol name = eax_d
DataType = num
RapidSymbol name = eax_e
DataType = num
RapidSymbol name = eax_f
DataType = num
The struct implementation should include a FillFromString and ToString method, that
is, inherit the IRapidData interface. Any properties and methods may also be implemented.
VB:
Public Structure ProcessData
Implements IRapidData
Private data As UserDefined
3HAC036957-001 Revision: - 85
5 Using the PC SDK
5.5.4. UserDefined data
End Get
C#:
public struct ProcessData: IRapidData
{
private UserDefined data;
86 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.4. UserDefined data
End Sub
C#:
public void FillFromString(string newValue)
{
IntData.FillFromString(newValue);
}
NOTE! The ToString method has to use the Overrides keyword in Visual Basic and the
override keyword in C#.
Property implementation
Each item in the RECORD structure should have a corresponding property in the extended
.NET data type. The get and set methods have to implement the conversion from/to controller
data type to .NET data type.
VB:
Public Property Step() As Integer
Get
Dim res As Integer =
Convert.ToInt32(IntData.Components(0).ToString())
Return res
End Get
© Copyright 2010 ABB. All rights reserved.
C#:
public int Step
{
get
{
int res =
Convert.ToInt32(IntData.Components[0].ToString());
return res;
3HAC036957-001 Revision: - 87
5 Using the PC SDK
5.5.4. UserDefined data
}
set
{
Num tmp = new Num();
tmp.FillFromNum(value);
IntData.Components[0] = tmp;
}
}
88 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.5. RAPID symbol search
Overview
Most RAPID elements (variables, modules, tasks, records and so on.) are members of a
symbol table, in which their names are stored as part of a program tree structure.
It is possible to search this table and get a collection of RapidSymbol objects, each one
including the RAPID object name, location, and type.
Search method
The search must be configured carefully, due to the large amount of RAPID symbols in a
system. To define a query you need to consider from where in the program tree the search
should be performed, which symbols are of interest, and what information you need for the
symbols of interest. To enable search from different levels, the SearchRapidSymbol
method is a member of several different SDK classes, for example Task, Module, and
Routine. The following example shows a search performed with Task as the starting point:
VB:
Dim RSCol As RapidSymbol()
RSCol = ATask.SearchRapidSymbol(SProp, "num", string.Empty)
C#:
RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty)
The SearchRapidSymbol method has three arguments. The first argument, of data type
RapidSymbolSearchProperties, is detailed in the next section. The second and third
arguments are detailed in the following sections.
Search properties
The RapidSymbolSearchProperties type is complex and requires some knowledge
about RAPID concepts.
It is used to specify search method, type of RAPID symbol to search for, whether the search
should be recursive, whether the symbols are local and/or global, and whether or not the
© Copyright 2010 ABB. All rights reserved.
search result should include only symbols currently used by a program. If a property is not
valid for a particular symbol, it will be discarded and will not exclude the symbol from the
search result.
The table describes the different properties of RapidSymbolSearchProperties.
Property Description
SearchMethod Specifies the direction of the search, which can be Block
(down) or Scope (up). Example: If the starting point of the
search is a routine, a block-search will return the symbols
declared within the routine, whereas a scope-search will return
the symbols accessible from the routine.
Types Specifies which RAPID type(s) you want to search for. The
SymbolTypes enumeration includes Constant, Variable,
Persistent, Function, Procedure, Trap, Module,
Task, Routine, RapidData. and so on. (Routine includes
Function, Procedure and Trap. RapidData includes
Constant, Variable and Persistent.)
3HAC036957-001 Revision: - 89
5 Using the PC SDK
5.5.5. RAPID symbol search
Property Description
Recursive For both block and scope search it is possible to choose if the
search should stop at the next scope or block level or
recursively continue until the root (or leaf) of the symbol table
tree is reached.
GlobalSymbols Specifies whether global symbols should be included.
LocalSymbols Specifies whether local symbols should be included.
InUse Specifies whether only symbols in use by the loaded RAPID
program should be searched.
Default instance
RapidSymbolSearchProperties has several static methods that return a default instance.
VB:
Dim SProp As RapidSymbolSearchProperties =
RapidSymbolSearchProperties.CreateDefault()
C#:
RapidSymbolSearchProperties sProp =
RapidSymbolSearchProperties.CreateDefault();
The default instance has the following values:.
Property Description
SearchMethod SymbolSearchMethod.Block
Types SymbolTypes.NoSymbol
Recursive True
GlobalSymbols True
LocalSymbols True
InUse True
Using this instance you can specify the search properties of the search you want to perform.
Example:
VB:
© Copyright 2010 ABB. All rights reserved.
SProp.SearchMethod = SymbolSearchMethod.Scope
SProp.Types = SymbolTypes.Constant Or SymbolTypes.Persistent
SProp.Recursive = False
C#:
sProp.SearchMethod = SymbolSearchMethod.Scope;
sProp.Types = SymbolTypes.Constant | SymbolTypes.Persistent
sProp.Recursive = false;
NOTE!
The default instance has the property Types set to NoSymbol. It must be specified in order
for a meaningful search to be performed!
NOTE!
The Types property allows you to combine several types in a search. See the preceding
example.
90 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.5. RAPID symbol search
NOTE!
See PC SDK Reference for the static methods CreateDefaultForData and
CreateDefaultForRoutine.
NOTE!
To search for a UserDefined data type, the complete path to the module that holds the
RECORD definition must be passed. For example:
result = tRob1.SearchRapidSymbol(sProp,"RAPID/T_ROB1/MyModule/
MyDataType", string.Empty);
However, if MyModule is configured as -Shared the system sees its data types as installed,
and the task or module should not be included in the path
result = tRob1.SearchRapidSymbol(sProp,"MyDataType", string.Empty);
character sequence “abc”, it is necessary to add some meta characters. The regular expression
for this is “.*abc.*”.
The available meta character set is shown below:
Expression Meaning
. Any single character
^ Any symbol starting with
[s] Any single character in the non-empty set s, where s is a
sequence of characters. Ranges may be specified as c-c.
[^s] Any single character not in the set s.
r* Zero or more occurrences of the regular expression r.
r+ One or more occurrences of the regular expression r.
r? Zero or one occurrence of the regular expression r.
(r) The regular expression r. Used for separate that regular
expression from another.
3HAC036957-001 Revision: - 91
5 Using the PC SDK
5.5.5. RAPID symbol search
Expression Meaning
r | r’ The regular expressions r or r’.
.* Any character sequence (zero, one or several characters).
Example 1
"^c.*"
Returns all symbols starting with c or C.
Example 2
"^reg[1-3]"
Returns reg1, Reg1, REG1, reg2, Reg2, REG2, reg3, Reg3 and REG3.
Example 3
"^c.*|^reg[1,2]"
Returns all symbols starting with c or C as well as reg1, Reg1, REG1, reg2, Reg2 and REG2.
SearchRapidSymbol example
This example searches for VAR, PERS or CONST num data in a task and its modules. The
search is limited to globally declared symbols. By default the search method is Block, so it
does not have to be set.
VB:
Dim sProp As RapidSymbolSearchProperties =
RapidSymbolSearchProperties.CreateDefault()
sProp.Types = SymbolTypes.Data
sProp.LocalSymbols = False
Dim rsCol As RapidSymbol()
rsCol = aTask.SearchRapidSymbol(sProp, "num", String.Empty)
C#:
RapidSymbolSearchProperties sProp =
RapidSymbolSearchProperties.CreateDefault();
sProp.Types = SymbolTypes.Data;
sProp.LocalSymbols = false; © Copyright 2010 ABB. All rights reserved.
RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty);
92 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.5. RAPID symbol search
NOTE!
If myModule is configured as -Shared and all myData instances are declared in myModule,
the search method must be set to Scope and the SearchRapidSymbol call should look like
this:
rsCol = aTask.SearchRapidSymbol(sProp, "mydata", string.Empty);
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: - 93
5 Using the PC SDK
5.5.6. Working with RAPID modules and programs
Overview
Using the Task object it is possible to load and save individual modules and programs. You
can also unload programs, as well as reset the program pointer and start program execution.
NOTE!
All these operations require mastership of the RAPID domain. For more information, see
Mastership on page 65.
NOTE!
All program files must reside in the file system of the controller and not locally on the PC. In
order to load a program from the PC, you must first download it to the controller by using the
FileSystem.PutFile method. For more information, see Saving files on page 113.
NOTE!
If the User Authorization System of the controller is used by the PC SDK application, it is
required that the logged on user has the UAS grant UAS_RAPID_LOADPROGRAM to load
and unload RAPID programs. For more information about which grants are necessary for a
specific PC SDK method, see the PC SDK Reference.
94 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.6. Working with RAPID modules and programs
ResetProgramPointer method
Using ResetProgramPointer you can set the program pointer to the main entry point of
the task.
VB:
aTask.ResetProgramPointer()
© Copyright 2010 ABB. All rights reserved.
C#:
aTask.ResetProgramPointer();
Start program
Starting program execution in the robot controller can only be done in automatic operating
mode. There are several overloaded Start methods to use, the simplest way to start RAPID
execution of a controller task is:
VB:
aTask.Start()
C#:
aTask.Start();
3HAC036957-001 Revision: - 95
5 Using the PC SDK
5.5.6. Working with RAPID modules and programs
NOTE!
If your application uses the User Authorization System of the controller (see User
Authorization System on page 46), you should also check whether the current user has the
grant UAS_RAPID_EXECUTE before calling the Start method.
For more information on how to write the event handler that is needed to update the GUI due
to a controller event, see Avoiding threading conflicts on page 107and Letting the user know
that RAPID data has changed on page 74.
96 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.7. Enable operator response to RAPID UI-instructions from a PC
UIInstructionType
The PC SDK UIInstructionType enumeration defines the different RAPID instructions
listed above. For a description of each instruction type, see PC SDK Reference. The following
is an example of such a description.
Example UIInstructionType.UIAlphaEntry :
© Copyright 2010 ABB. All rights reserved.
Member Description
UIAlphaEntry The UIAlphaEntry (User Interaction Alpha Entry) is used to let
an operator communicate with the robot system via RAPID, by
enabling him to enter a string from the FlexPendant or from a
PC SDK application. After the operator has entered the text, it is
transferred back to the RAPID program by calling UIAlphaEn-
tryEventArgs.SendAnswer.
TIP!
For complete information about the usage in RAPID refer to RAPID Technical reference
manual (accessiable from RobotStudio).
3HAC036957-001 Revision: - 97
5 Using the PC SDK
5.5.7. Enable operator response to RAPID UI-instructions from a PC
Increased flexibility
Making use of the Remote operator dialog feature, the end-user of the robot system can
choose whether to use the FlexPendant or the PC SDK application to answer a RAPID UI- or
TP-instruction.
The FlexPendant will always show the operator dialog the usual way. If the operator responds
from the PC the message on the FlexPendant will disappear.
NOTE!
The dialog box of the PC SDK application should disappear if the operator chooses to respond
from the FlexPendant. This is handled by the PC SDK programmer.
Basic approach
The basic procedure for implementing Remote operator dialog in a PC SDK application is
shown below. The same approach is used internally by the FlexPendant when it launches its
operator view.
Step Action
1 Set up a subscription to UIInstructionEvent.
2 In the event handler check the UIInstructionEventType from the event
arguments. If Post or Send create an operator dialog by using the information
provided by the event arguments.
3 To transfer the response of the end-user to the RAPID program call the
SendAnswer method of the specialized UIInstructionEventArgs object.
4 Remove any existing operator dialog if you get a UIInstructionEvent of
UIInstructionEventType.Abort.
NOTE!
The controller events are always received on a background thread and you need to enforce
execution to the GUI thread by the use of Invoke before launching the operator dialog. For
more information, see Controller events and threads on page 44.
UIInstructionEvent
To be notified when a UI-instruction event has occurred in the controller, you need to set up
a subscription to UIInstructionEvent. To do that you use the UIInstruction property © Copyright 2010 ABB. All rights reserved.
of the Rapid class, like this:
Controller c = new Controller();
c.Rapid.UIInstruction.UIInstructionEvent += new
UIInstructionEventHandler(OnUIInstructionEvent);
TIP!
For a code example including an event handler see UIInstructionEvent in the PC SDK
Reference.
98 3HAC036957-001 Revision: -
5 Using the PC SDK
5.5.7. Enable operator response to RAPID UI-instructions from a PC
UIInstructionEventArgs
The UIInstructionEventArgs object holds information about which RAPID task and
which UI- or TP-instruction triggered the event. The following picture shows all
UIInstructionEventArgs members.
© Copyright 2010 ABB. All rights reserved.
7.5.7_1
UIInstructionEventArgs is a base class of several specialized classes, one for each UI-
and TP- instruction. The specialized class holds the additional information needed to create
the operator dialog, so type casting the UIInstructionEventArgs object to the correct
specialized type is necessary. To do that you first check the InstructionType property,
which you can see in the preceding image.
3HAC036957-001 Revision: - 99
5 Using the PC SDK
5.5.7. Enable operator response to RAPID UI-instructions from a PC
UIListViewEventArgs
As an example of a specialized type, the members of the UIListViewEventArgs class are
shown below. The Buttons and ListItems properties are of course crucial for creating the
operator dialog.
7.5.7_2
UIInstructionEventType
An important property in the picture above is UIInstructionEventType. It is inherited
from the base class and comes with all UI- and TP- instruction events.
The following table shows the members of the UIInstructionEventType enumeration.
Member Description
Undefined Undefined. Should not occur.
Post Post event type, for example TPWrite, TPErase. When the event is of this type
RAPID expects no response from the operator.
Send Send event type, for example TPReadNum, UIListView. When the event is of
this type the running RAPID program expects feedback from the operator
before execution continuous.
Abort When the controller gets a response from a client (the FlexPendant or a PC
SDK application) it sends an event of Abort type. This tells all subscribing
clients that the UI-Instruction has been aborted, closed or confirmed by the
operator. When you get an event of this type you should remove any open
operator dialog.
NOTE!
If the robot system has several RAPID tasks, it is necessary to keep track of which operator
dialog belongs to which task, and so on.
A RAPID task can handle only one pending Send, and it is not guaranteed that an Abort
event will always follow a Send event. Therefore, if you receive a new Send event from the
same task without a preceding Abortevent, you should remove the existing dialog and
display the new one.
SendAnswer method
To transfer the response of the end-user back to the RAPID program, you can call the
SendAnswer method. See the image of the UIListViewEventArgs class above.
SendAnswer is called with different arguments depending on the RAPID instruction.
For example, if it is a UIAlphaEntry instruction you can send the string that the operator
has entered as argument. But if it is a UIListView instruction the SendAnswer method will
look like this:
© Copyright 2010 ABB. All rights reserved.
NOTE!
There is no mastership handling involved in using Remote operator dialog.
Overview
A robot system uses input and output signals to control processes. Signals can be of digital,
analog, or group signal type. Such IO signals are accessible using the SDK.
Signal changes in the robot system are often significant, and there are many scenarios where
end-users of the system need notification of signal changes.
To speed up event notification from the controller, there is new functionality in PC SDK 5.10,
which allows you to set up subscription priorities. This possibility applies to I/O signals and
persistent RAPID data. This mechanism is further described in Implementing high priority
event subscription on page 106.
Accessing signals
Accessing signals is done through the Controller object and its property IOSystem, which
represents the IO signal space in the robot controller.
To access a signal you need the system name of the signal. The object that is returned from
the IOSystem.GetSignal method is of type Signal.
VB:
Dim signal1 As Signal =
aController.IOSystem.GetSignal("signal_name")
C#:
Signal signal1 = aController.IOSystem.GetSignal("signal_name");
The returned Signal object has to be typecast to digital, analog or group signal. This
example shows a how a signal of type DigitalSignal is created:
VB:
Dim diSig As DigitalSignal = DirectCast(signal1, DigitalSignal)
C#:
DigitalSignal diSig = (DigitalSignal)signal1;
© Copyright 2010 ABB. All rights reserved.
NOTE!
Remember to call the Dispose method of the signal when it should no longer be used.
The following code iterates the signal collection and adds all signals to a ListView control.
The list has three columns displaying signal name, type, and value:
VB:
For Each signal As Signal In signals
item = New ListViewItem(signal.Name)
item.SubItems.Add(signal.Type.ToString())
item.SubItems.Add(signal.Value.ToString())
listView1.Items.Add(item)
Next
© Copyright 2010 ABB. All rights reserved.
C#:
foreach (Signal signal in signals)
{
item = new ListViewItem(signal.Name);
item.SubItems.Add(signal.Type.ToString());
item.SubItems.Add(signal.Value.ToString());
listView1.Items.Add(item);
}
If the signal objects are no longer needed they should be disposed of:
VB:
For Each signal As Signal In signals
signal.Dispose()
Next
C#:
foreach (Signal signal in signals)
{
signal.Dispose();
}
Digital signal
The following code reads the digital signal DO1 and selects a checkbox if the signal value is
1 (ON):
VB:
Dim sig As Signal = aController.IOSystem.GetSignal("DO1")
Dim digitalSig As DigitalSignal = DirectCast(sig, DigitalSignal)
Dim val As Integer = digitalSig.[Get]()
If val = 1 Then
Me.checkBox1.Checked = True
End If
C#:
Signal sig = aController.IOSystem.GetSignal("DO1");
DigitalSignal digitalSig = (DigitalSignal)sig;
int val = digitalSig.Get();
if (val == 1)
{
this.checkBox1.Checked = true;
}
Analog signal
The following of code reads the value of the analog signal AO1 and displays it in a textbox: © Copyright 2010 ABB. All rights reserved.
VB:
Dim asig As Signal = aController.IOSystem.GetSignal("AO1")
Dim analogSig As AnalogSigna = DirectCast(asig, AnalogSignal)
Dim analogSigVal As Single = analogSig.Value
Me.textBox1.Text = analogSigVal.ToString()
C#:
Signal asig = aController.IOSystem.GetSignal("AO1");
AnalogSigna analogSig = (AnalogSignal)asig;
float analogSigVal = analogSig.Value;
this.textBox1.Text = analogSigVal.ToString();
NOTE!
In manual mode, a signal value can be modified only if the Access Level of the signal is ALL.
If not, the controller has to be in auto mode.
Digital signal
The following code changes the value of a digital signal in the controller when you select/
unselect a checkbox:
VB:
Private Sub checkBox1_Click(ByVal sender As Object, ByVal e As
EventArgs)
If Me.checkBox1.Checked Then
digitalSig.[Set]()
Else
digitalSig.Reset()
End If
End Sub
C#:
private void checkBox1_Click(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
digitalSig.Set();
}
else
{
digitalSig.Reset();
© Copyright 2010 ABB. All rights reserved.
}
}
NOTE! You can also set the value using the Value property.
Analog signal
The following code writes the value entered in a text box to the analog signal AO1. The value
is converted from string to a float before it is written to the controller:
VB:
Dim analogSigVal As Single = Convert.ToSingle(Me.textBox1.Text)
analogSig.Value = analogSigVal
C#:
float analogSigVal = Convert.ToSingle(this.textBox1.Text);
analogSig.Value = analogSigVal;
Visual Basic
Friend WithEvents sig As AnalogSignal
...
AddHandler sig.Changed, AddressOf sig_Changed
...
Private Sub sig_Changed(ByVal sender As Object, ByVal e As
SignalChangedEventArgs)
.....
End Sub
C#
sig.Changed += new
EventHandler<SignalChangedEventArgs>(sig_Changed);
...
private void sig_Changed(object sender, SignalChangedEventArgs e)
{..... }
C#:
sig.Changed += new
EventHandler<SignalChangedEventArgs>(sig_Changed);
sig.Changed -= new
EventHandler<SignalChangedEventArgs>(sig_Changed);
C#:
signal.Changed += new
EventHandler<SignalChangedEventArgs>(sig_Changed);
signal.Subscribe(sig_Changed, EventPriority.High);
To deactivate subscriptions with high priority you call the Unsubscribe method like this:
VB:
signal.Unsubscribe(sig_Changed)
C#:
signal.Unsubscribe(sig_Changed);
C#:
private void UpdateUI(object sender, SignalChangeEventArgs e)
{
SignalState state = e.NewSignalState;
....
float val = state.Value
this.textBox1.Text = val.ToString()
}
NOTE!
There is no guarantee you will receive an initial event when setting up the subscription. To
get initial information about the value of a signal, you should read it using the Value
property.
NOTE!
Make sure the subscription is removed before you dispose of the signal. For more
information, see Memory management in PC applications on page 63.
Overview
Event log messages may contain information about controller status, RAPID execution, the
running processes of the controller, and so on.
Using the SDK it is possible to either read messages in the queue or to use an event handler
that will receive a copy of each new log message. An event log message contains queue type,
event type, event time, event title, and message.
cat = log.GetCategory[4];
NOTE!
The EventLogCategory should be disposed of when it is no longer used.
or
Dim msg As EventLogMessage
For Each msg In cat.Messages
Me.textBox1.Text = msg.Title
.....
Next Item
C#:
EventLogMessage msg = cat.Messages[1];
or
foreach (EventLogMessage emsg in cat.Messages)
{
this.textBox1.Text = emsg.Title;
.......
}
MessageWritten event
It is possible to add an event handler that is notified when a new messages is written to the
controller event log. This is done by subscribing to the EventLog event MessageWritten.
The event argument is of type MessageWrittenEventArgs and has a Message property,
which holds the latest event log message.
VB:
Private Sub log_MessageWritten(ByVal sender As Object, ByVal e As
MessageWrittenEventArgs)
Dim msg As EventLogMessage = e.Message
End Sub
C#:
private void log_MessageWritten(object sender,
© Copyright 2010 ABB. All rights reserved.
MessageWrittenEventArgs e)
{
EventLogMessage msg = e.Message;
}
NOTE!
If the application user interface needs to be updated as a result of the event, you must delegate
this job to the GUI thread using the Invoke method. For more information and code samples,
see Invoke method on page 45.
TIP!
Find out more about the EventLogDomain in the PC SDK Reference help.
Overview
The MotionDomain namespace lets you access the mechanical units of the robot system.
Motion system
You can access the motion system by using the Controller property MotionSystem.
VB:
Private aMotionSystem As MotionSystem
aMotionSystem = aController.MotionSystem
C#
private MotionSystem aMotionSystem;
aMotionSystem = aController.MotionSystem;
By using the MotionSystem object you can, for example, use its SpeedRatio property to
find out about the current speed of the robot.
C#:
RobTarget aRobTarget =
aController.MotionSystem.ActiveMechanicalUnit.GetPosition(C
oordinateSystemType.World);
JointTarget aJointTarget=
aController.MotionSystem.ActiveMechanicalUnit.
GetPosition();
TIP!
To read Rapid data that is, RobTarget and JointTarget, user must Logon to controller
Find out more about the MotionDomain in the PC SDK Reference help.
Calibrating Axes
The revolution counters of a TCP mechanical unit is updated using the method
MechanicalUnit.SetRevolutionCounter. For example, when the control system is
disconnected and the robot axis is moved update the revolution counters.
MechanicalUnit.GetMechanicalUnitStatus property shows whether calibration is
needed or not.
Fine calibration is performed using the method MechanicalUnit.FineCalibrate.
For more information, see Reference Manual PC SDK.
FineCalibrate and SetRevolutionCounter require the system to be either in ’Auto
mode and Motors off state’ or in ’manual mode and granted access’ by the FlexPendant.
FineCalibrate and SetRevolutionCounter also require the corresponding UAS grants.
For more information on how to perform calibration, see Operating manual - IRC5 with
FlexPendant.
CAUTION!
If a revolution counter is incorrectly updated, it will cause incorrect robot positioning,
which in turn may cause damage or injury.
© Copyright 2010 ABB. All rights reserved.
Overview
Using the SDK it is possible to create, save, load, rename, and delete files in the controller
file system. It is also possible to create and delete directories.
Environment variables
When specifying file system paths you can use environment variables to denote the HOME,
system, backup, and temp directories of the currently used system. When an application uses
“(BACKUP)$” it is internally interpreted as the path to the backup directory of the current
system. The other environment variables are: HOME, TEMP and SYSTEM.
Loading files
You can load a file from the controller to the PC using the GetFile method. The method
© Copyright 2010 ABB. All rights reserved.
generates an exception if the operation did not work. The arguments are complete paths
including filenames.
VB:
aController.FileSystem.GetFile(remoteFilePath, localFilePath)
C#:
aController.FileSystem.GetFile(remoteFilePath, localFilePath);
Saving files
You can save a file on the controller file system by using the PutFile method. The method
generates an exception if the operation did not work. The arguments are complete paths
including filenames.
VB:
aController.FileSystem.PutFile(localFilePath, remoteFilePath)
C#:
aController.FileSystem.PutFile(localFilePath, remoteFilePath);
ControllerFileSystemInfo[] anArray;
ControllerFileSystemInfo info;
anArray = aController.FileSystem.GetFilesAndDirectories("search
pattern");
for (int i=0;i<anArray.Length;i++) {
info = anArray[i];
......
}
TIP!
Find out more about the FileSystemDomain in the PC SDK Reference help.
© Copyright 2010 ABB. All rights reserved.
Overview
The Messaging domain of the PC SDK can be used to send and receive data between a PC
SDK application and a RAPID task.
The corresponding RAPID functionality, RAPID Message Queue, includes RAPID data types
and RAPID instructions and functions for sending and receiving data. It enables
communication between RAPID tasks or between a RAPID task and a PC SDK application.
This section provides information about how to implement messaging in a PC SDK
application. To make it work it is necessary to do part of the implementation in RAPID. In
order to show how this can be done, a code example in C# and RAPID is provided at the end
of the section.
NOTE!
For more information on how to implement messaging in RAPID, see Application manual -
Robot communication and I/O Control.
RobotWare option
The functionality in RAPID that is needed to utilize messaging - RAPID Message Queue - is
included in the RobotWare options PC Interface, FlexPendant Interface and Multitasking. As
PC Interface is required on a robot controller to be used with a PC SDK client, this means no
extra option is needed to start using RAPID Message Queue with a PC SDK application.
Messaging illustration
The following illustration shows possible senders and receivers in the robot system. The
arrows represent ways to communicate by posting a message to a queue.
PC SDK Client
en0700000430
NOTE!
In principle, messages might as well be sent between a PC SDK client and a PC SDK
application running on the FlexPendant.
NOTE!
The messaging functionality of the FlexPendant SDK has not yet been made public, but in
PC SDK 5.11 a mechanism has been implemented, which allows advanced users to access it.
You should contact the customer support if you need information about how to use it.
Benefits
Together with RAPID Message Queue the functionality of the Messaging domain represent
a new, flexible way for a PC SDK application to interact with a RAPID task.
Messaging is usually done when a RAPID task is executing, but it is also possible to send a
message to a RAPID task when it has been stopped. The RAPID interrupt will then occur
once the RAPID task has been started.
An simple example of usage would be to set a flag from a PC SDK application in order to
control the program flow in the RAPID program.
NOTE!
Sending messages can be done in both manual and auto mode. As opposed to using
RapidData to modify a RAPID variable no mastership is required.
7.9_1
The Ipc class is used to handle message queues with methods like GetQueue,
CreateQueue, DeleteQueue and so on. When you have an IpcQueue object you can use
its Send method to send an IpcMessage to a RAPID task or its Receive method to receive
a message from a RAPID task.
When sending a message you use an existing queue in the controller as the IpcQueue object.
The naming principle of queues in the controller is using the name of the corresponding task
prefixed with “RMQ_”, e.g “RMQ_T_ROB1”. To receive a message from RAPID you must
first create your own message queue and use that object with the Receive method.
Basic approach
To utilize messaging in a PC SDK application, you need to do the implementation both in
RAPID and in the PC application.
To send data from a PC application and receive it in a RAPID task:
1. In the PC application connect to the queue of the RAPID task.
2. Create the message.
3. Send the message.
4. In the RAPID program set up a trap routine that reads the message. Connect an
interrupt so that the trap routine is called each time a new message appears.
For a complete code example using this scenario, see Code example on page 122.
NOTE!
The IpcMessage.Data is set and retrieved as a byte array, SetData(byte[] data)
and byte[] GetData(). This means you must convert the message data string to a byte
array before calling the SetData method. It may look like this in C#:
Byte[] data = new UTF8Encoding().GetBytes("string;\"Hello world\"");
For more examples, see Code example on page 122.
NOTE!
The RAPID program can specify what RAPID data type it expects to receive by connecting
it to a TRAP routine. A message containing data of a data type that no interrupt is connected
to will be discarded with only an event log warning.
NOTE!
To read the values of these system parameter from the PC SDK you use the IpcQueue
properties RemoteAccessible, MessageSizeLimit and Capacity.
Remote RmqType
The system parameter RmqType must be set to Remote to enable messaging between RAPID
and PC SDK:
7.9_2
© Copyright 2010 ABB. All rights reserved.
Code example
This simple messaging example can be tested with a virtual or a real controller. The system
parameter RmqType must be set to Remote as shown in RAPID Message Queue system
parameters on page 120.
The following code sample creates a message and sends it to a RAPID task, which reads it
and sets a RAPID variable accordingly. Then an “Acknowledged” message is sent back to the
PC SDK queue. Finally, the PC SDK application launches the received message in a Message
Box.
PC SDK - C#
A message is created and sent to the RAPID queue “RMQ_T_ROB1”. An answer message is
then received from RAPID and launched in a Message Box.
C#:
//declarations
private Controller c;
private IpcQueue tRob1Queue;
private IpcQueue myQueue;
private IpcMessage sendMessage;
private IpcMessage recMessage;
...
if (ret == IpcReturnType.OK)
{
//convert msg data to string
answer = new UTF8Encoding().GetString(recMessage.Data);
MessageBox.Show(answer);
RAPID
A trap is created for a message of data type bool. In the trap, the value of the message data
is assigned to the flag variable. Then an “Acknowledged” message is sent back to the PC SDK
client. In main the WHILE loop is executed until a message with a TRUE value is received.
MODULE RAB_COMMUNICATION
VAR bool flag := FALSE;
VAR intnum connectnum;
© Copyright 2010 ABB. All rights reserved.
PROC main()
CONNECT connectnum WITH RABMsgs;
IRMQMessage flag, connectnum;
WHILE flag = FALSE DO
!do something, eg. normal processing...
WaitTime 3;
ENDWHILE
!PC SDK message received - do something...
TPWrite "Message from PC SDK, will now...";
IDelete connectnum;
EXIT;
ENDPROC
TRAP RABMsgs
VAR rmqmessage msg;
VAR rmqheader header;
VAR rmqslot rabclient;
VAR num userdef;
VAR string ack := "Acknowledged";
RMQGetMessage msg;
RMQGetMsgHeader msg \Header:=
header\SenderId:=rabclient\UserDef:=userdef;
ENDTRAP
ENDMODULE
NOTE!
Error handling should be implemented in C# and in RAPID.
NOTE!
From RobotWare 5.12 there is a new RAPID instruction, RMQEmptyQueue, that can be used
to empty the queue in a task.
© Copyright 2010 ABB. All rights reserved.
Introduction
Using the Visual Studio debugger for a PC SDK application presents no difference compared
to standard .NET development. Debugging can be done using the virtual IRC5 in
RobotStudio or a real controller.
Code Description
0x80040401 The requested poll level could not be met, poll level low is used.
0x80040402 The requested poll level could not be met, poll level medium is used.
0xC0040401 No connection with controller.
0xC0040402 Error connecting to controller.
0xC0040403 No response from controller.
0xC0040404 Message queue full. (Should only happen if asynchronous calls are made.)
0xC0040405 Waiting for a resource.
0xC0040406 The message sent is too large to handle.
0xC0040408 A string does not contain characters exclusively from a supported encoding,
for example ISO-8859-1 (ISO-Latin1).
0xC0040409 The resource can not be released since it is in use.
0xC0040410 The client is already logged on as a controller user.
0xC0040411 The controller was not present in NetScan.
0xC0040412 The NetScanID is no longer in use. Controller removed from list.
0xC0040413 The client id is not associated with a controller user. Returned only by
methods that need to check this before sending request to controller.
Otherwise, see 0xC004840F.
© Copyright 2010 ABB. All rights reserved.
0xC0040414 The RobotWare version is later than the installed Robot Communication
Runtime. A newer Robot Communication Runtime needs to be installed.
Returned by RobHelperFactory.
0xC0040415 The major and minor part of the RobotWare version is known, but the
revision is later and not fully compatible. A newer Robot Communication
Runtime needs to be installed. Code returned by RobHelperFactory.
0xC0040416 The RobotWare version is no longer supported. Code returned by RobHelp-
erFactory.
0xC0040417 The helper type is not supported by the RobotWare. Helper might be
obsolete or for later RobotWare versions, or the helper may not be supported
by a BootLevel controller. Code returned by RobHelperFactory.
0xC0040418 System id and network id mismatch, they do not identify the same controller.
0xC0040601 Call was made by other client than the one that made the Connect() call.
0xC0040602 File not found on the local file system. Can be that file, directory or device
does not exist.
Code Description
0xC0040603 File not found on the remote file system. Can be that file, directory or device
does not exist.
0xC0040604 Error when accessing/creating file on the local file system.
0xC0040605 Error when accessing/creating file on the remote file system.
0xC0040606 The path or filename is too long or otherwise bad for the VxWorks file
system.
0xC0040607 The file transfer was interrupted. When transferring to remote system, the
cause may be that the remote device is full.
0xC0040608 The local device is full.
0xC0040609 Client already has a connection and can not make a new connection until the
present one is disconnected.
0xC0040701 One or more files in the release directory is corrupt and cannot be used when
launching a VC.
0xC0040702 One or more files in the system directory is corrupt and cannot be used when
launching a VC.
0xC0040703 A VC for this system has already been started; only one VC per system is
allowed.
0xC0040704 Could not warm start VC since it must be cold started first.
0xC0040705 The requested operation failed since VC ownership is not held or could not
be obtained.
0xC0048401 Out of memory.
0xC0048402 Not yet implemented.
0xC0048403 The service is not supported in this version of the controller.
0xC0048404 Operation not allowed on active system.
0xC0048405 The data requested does not exist.
0xC0048406 The directory does not contain all required data to complete the operation.
0xC0048407 Operation rejected by the controller safety access restriction mechanism.
0xC0048408 The resource is not held by caller.
0xC0048409 An argument specified by the client is not valid for this type of operation.
0xC004840A Mismatch in controller id between backup and current system.
0xC004840B Mismatch in key id, that is, options, languages and so on. between backup © Copyright 2010 ABB. All rights reserved.
and current system.
0xC004840C Mismatch in robot type between backup and current system.
0xC004840D Client not allowed to log on as local user.
0xC004840F The client is not logged on as a controller user.
0xC0048410 The requested resource is already held by caller
0xC0048411 The max number of the requested resources has been reached.
0xC0048412 No request active for the given user.
0xC0048413 Operation/request timed out on controller.
0xC0048414 No local user is logged on.
0xC0048415 The operation was not allowed for the given user.
0xC0048416 The URL used to initialize the helper does not resolve to a valid object.
0xC0048417 The amount of data is too large to fulfill the request.
0xC0048418 Controller is busy. Try again later.
0xC0048419 The request was denied.
Code Description
0xC004841A Requested resource is held by someone else.
0xC004841B Requested feature is disabled.
0xC004841C The operation is not allowed in current operation mode. For example, a
remote user may not be allowed to perform the operation in manual mode.
0xC004841D The user does not have required mastership for the operation.
0xC004841E Operation not allowed while backup in progress.
0xC004841F Operation not allowed when tasks are in synchronized state.
0xC0048420 Operation not allowed when task is not active in task selection panel.
0xC0048421 Mismatch in controller id between backup and current system.
0xC0048422 Mismatch in controller id between backup and current.
0xC0048423 Invalid client id.
0xC0049000 RAPID symbol was not found.
0xC0049001 The given source position is illegal for the operation.
0xC0049002 The given file was not recognized as a program file, for example the XML
semantics may be incorrect.
0xC0049003 Ambiguous module name.
0xC0049004 The RAPID program name is not set.
0xC0049005 Module is read protected.
0xC0049006 Module is write protected.
0xC0049007 Operation is illegal in current execution state.
0xC0049008 Operation is illegal in current task state.
0xC0049009 The robot is not on path and is unable to restart. Regain to or clear path.
0xC004900A Operation is illegal at current execution level.
0xC004900B Operation can not be performed without destroying the current execution
context.
0xC004900C The RAPID heap memory is full.
0xC004900D Operation not allowed due to syntax error(s).
0xC004900E Operation not allowed due to semantic error(s).
0xC004900F Given routine is not a legal entry point. Possible reasons are: routine is a
function, or routine has parameters.
© Copyright 2010 ABB. All rights reserved.
Code Description
0xC004A005 Not a valid device.
0xC004A006 Unable to create directory.
0xC004A007 The directory does not exist.
0xC004A008 The directory already exists.
0xC004A009 The directory contains data.
0xC004A00B Unable to create file.
0xC004A00C File not found or could not be opened for reading.
0xC004A200 Disable of unit not allowed at trustlevel 0.
6.2. Troubleshooting
Overview
If you encounter problems with your PC SDK application follow these steps before
contacting ABB support.
Action
1 Check whether your problem is in the checklist in the next section.
2 Answers to many questions are available in the Release Notes of the specific PC SDK
release. The document is available on the RobotWare DVD and on the Software
Download Site.
3 Pinpoint the problem by debugging your code so that a precise problem description can
be provided.
4 Check the User Forum of ABB’s RobotStudio Community, which includes a forum
dedicated to discussion and chat on PC SDK topics.
TIP!
At www.abb.com/roboticssoftware there is a link to the RobotStudio Community.
Checklist
• Unable to connect to controllers? Make sure the system on the controller has the
RobotWare option PC Interface. This applies to both virtual and real controllers.
• Is the problem is GUI hangings? Make sure you use Invoke when modifying the user
interface due to a robot controller event. For more information, see GUI and controller
event threads in conflict on page 44 and Invoke method on page 45.
• Is the problem is related to netscan? If NetworkScanner.Scan does not find the robot
controller during netscan you should try to increase the time allowed for scanning.
Increase the networks scanner delay time in an app.config file as explained in
Application configuration file on page 35 or add the time directly in the code like this:
NetworkScanner aScanner = new NetworkScanner(); aScanner.Scan();
System.Threading.Thread.Sleep(4000);aScanner.Scan();
• Do you get “Invalid Client ID” when trying to do a read operation toward the robot
© Copyright 2010 ABB. All rights reserved.
controller? If so, the reason is probably that you have forgotten to log on to the
controller. To write to RAPID data or to the configuration database, for example, you
also need to require mastership. For more information, see Logon and logoff on page
64 and Mastership on page 33.
• If you are working with a previous version of PC SDK (earlier than 5.10) you might
run into problems related to licence verification? If you get the run-time error “A valid
license cannot be granted for the type ABB.Robotics.Controllers.Licenses.PCSdk.
Contact the manufacturer of the component for more information“ when accessing the
NetworkScanner and the Controller classes you need to add a licx file to the
project. For more information, see Licenses.licx on page 39.
Introduction
When your application is ready it has to be deployed to the customer’s PC. This chapter gives
information about the facilities for deployment included in the PC SDK installation.
NOTE!
Neither PC SDK nor a PC SDK licence need to be installed on the PC that will host your
application. Furthermore, from PC SDK 5.10 you do NOT need to add the licence key to your
project as described in Licenses.licx on page 39, as deployed PC applications no longer
perform license verification when executing.
ABBControllerAPI.msm
A PC SDK application cannot execute without the PC SDK assemblies it references. For your
convenience, the ABBControllerAPI merge module contains the PC SDK assemblies. Add it
to your install program to have them installed in the Global Assembly Cache (GAC).
The GAC is automatically installed with the .NET runtime. It enables a PC to share
assemblies across numerous applications. If the customer’s PC has RobotStudio Online of the
same release as the PS SDK used to create the application the PC SDK dlls your application
needs should be in the GAC already.
© Copyright 2010 ABB. All rights reserved.
NOTE!
If you want to create an msi file (or a setup.exe) of the msm file, you can include the
ABBControllerAPI.msm file in a Visual Studio SetUp Project.
NOTE!
Before, ABBControllerAPI.msm worked only with InstallShield. This problem has now been
resolved.
A
Array 77
dimensions 77
enumerator 79
indexers 77
object 77
C
compatibility 40
Configuration 35
App.config 35
CAPI 35
Section tag 35
ControllerInfo Object 62
E
Exception 48
.Error Codes 127
.NET 49
Try-catch 48
Typecasting 48
G
GAC 20
I
Installation 19
Requirements 19
Invoke 45
IRC5 controller. 13
N
NetworkScanner 61
NetworkWatcher 62
R
ReadItem 80
Remote operator dialog 97
W
WriteItem 80
© Copyright 2010 ABB. All rights reserved.
3HAC036957-001 Revision: -
© Copyright 2010 ABB. All rights reserved.