PC SDK: Application Manual
PC SDK: Application Manual
PC SDK: Application Manual
Application manual
PC SDK
Trace back information:
Workspace R12-1 version a4
Checked in 2012-03-15
Skribenta version 875
Application manual
PC SDK
RobotWare 5.14
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: A 5
© Copyright 2010-2012 ABB. All rights reserved.
Table of contents
Index 133
6 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
Overview
Overview
About this manual
ABB's PC Software Development Kit (PC SDK) is a software tool, which enables
programmers to develop customized operator interfaces for the IRC5 robot
controller.
The purpose of this manual is to help software developers get started with PC SDK
application development.
Note
Earlier till version 5.12 PC SDK was a part of RAB (Robot Application Builder).
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:
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. Applic-
ation 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#.
Continued
Chapter Contents
6 Testing, debugging and troubleshooting PC SDK applications. Using printouts,
error codes in exceptions and so on. Checklist for contacting a service organ-
ization.
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 3HAC16581-1
Data 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 5.13 onwards this manual replaces: Application manual - Robot Applic-
ation Builder (3HAC028083-001)
For information on FlexPendant SDK refer Application manual - FlexPendant
SDK
A Released with RobotWare 5.14.02
Minor corrections.
8 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
Product documentation, M2004
Product manuals
Manipulators, controllers, DressPack/SpotPack, and most other hardware will be
delivered with a Product manual that generally contains:
• Safety information.
• Installation and commissioning (descriptions of mechanical installation or
electrical connections).
• Maintenance (descriptions of all required preventive maintenance procedures
including intervals and expected life time of parts).
• Repair (descriptions of all recommended repair procedures including spare
parts).
• Calibration.
• Decommissioning.
• Reference information (safety standards, unit conversions, screw joints, lists
of tools ).
• Spare parts list with exploded views (or references to separate spare parts
lists).
• Circuit diagrams (or references to circuit diagrams).
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).
Continued
• What is included (for example cables, I/O boards, RAPID instructions, system
parameters, DVD with PC software).
• How to install included or required hardware.
• How to use the application.
• Examples of how to use the application.
Operating manuals
The operating manuals describe hands-on handling of the products. The manuals
are aimed at those having first-hand operational contact with the product, that is
production cell operators, programmers, and trouble shooters.
The group of manuals includes (among others):
• Emergency safety information
• General safety information
• Getting started, IRC5 and RobotStudio
• Introduction to RAPID
• IRC5 with FlexPendant
• RobotStudio
• Trouble shooting, for the controller and manipulator.
10 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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 regulations
Before beginning work with the robot, make sure you are familiar with the safety
regulations described in the manual Operating manual - General safety information.
3HAC036957-001 Revision: A 11
© Copyright 2010-2012 ABB. All rights reserved.
This page is intentionally left blank
1 Introduction
1.1 About creating controller applications
1 Introduction
1.1 About creating controller applications
Note
Controller applications are not platform independent. You must choose to develop
the application for either the PC platform or the FlexPendant (refer FlexPendant
SDK application Manual).
Note
Continued
Note
Note
Please read this manual and the release notes before starting to code.
14 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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
Note
You are recommended to keep the help files open while programming, as you
will frequently need them for PC SDK related issues.
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.
Continued
Tip
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.
16 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
1 Introduction
1.3 Terminology
1.3 Terminology
Definitions
Term Definition
C# and Visual Basic.NET .NET programming languages.
Common Language The core runtime engine in the .NET Framework for execution of
Runtime managed code. Provides services such as cross-language integ-
ration, 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.
Microsoft .NET Frame- An integral Windows component supporting the building and
work running of applications.
Network socket A communication end-point unique to a machine communicating
on an Internet Protocol-based network.
PC SDK programmer A programmer who uses PC SDK to develop custom applications.
PC SDK application A custom application developed with PC SDK.
Robot Application Build- ABB software tool, which enabled the development of custom
er operator interfaces for IRC5. Often referred to as RAB. The RAB
is split to FlexPendant SDK and PC SDK. Robot Application
Builder (RAB) was a software tool, which enabled programmers
to develop customized FlexPendant or PC interfaces for the IRC5
robot controller.
Robot Communication The communication layer used by Controller API to communicate
Runtime over the network with an IRC5 controller.
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 unman-
aged.
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
18 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
2 Installation and development environment
2.1 Installation overview
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
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.
Note
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.14 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.
Continued
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 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.14 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
3HAC036957-001 Revision: A 21
© Copyright 2010-2012 ABB. All rights reserved.
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.
Note
22 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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
Note
Continued
Related information
24 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
2 Installation and development environment
2.4 Development environment
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.
Continued
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.
26 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
2 Installation and development environment
2.5 Two development models - virtual and real
Note
Continued
Debugging is easy using the virtual IRC5 and Visual Studio. You attach the
application process to Visual Studio, set a break point in the code, and step through
it as it executes.
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.
28 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
2 Installation and development environment
2.6 Conversion of VS 2005 projects to Visual Studio 2008
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.
3HAC036957-001 Revision: A 29
© Copyright 2010-2012 ABB. All rights reserved.
This page is intentionally left blank
3 Run-time environment
3.1 Overview
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++
PC_architect
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.
3HAC036957-001 Revision: A 31
© Copyright 2010-2012 ABB. All rights reserved.
3 Run-time environment
3.2.1 Overview
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.
32 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
3 Run-time environment
3.2.2 Mastership
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 50.
Note
Continued
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: A
© Copyright 2010-2012 ABB. All rights reserved.
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 64.
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:
<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>
Continued
<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 controller. If an application name is not supplied, the process name is
used.
<defaultUser name="user name" password="password"
application="application"/>
<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" />
Continued
<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.
3HAC036957-001 Revision: A 37
© Copyright 2010-2012 ABB. All rights reserved.
3 Run-time environment
3.2.4 Communication between PC and controller
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 Accessing the controller on page 66.
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.
Note
38 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
3 Run-time environment
3.2.5 Licence verification - applies only to versions earlier than PC SDK 5.10
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
3HAC036957-001 Revision: A 39
© Copyright 2010-2012 ABB. All rights reserved.
3 Run-time environment
3.3 Release upgrades and compatibility
Note
PC SDK 5.11 to 5.13 supports Visual Studio 2008 and PC SDK 5.14 supports
Visual Studio 2010.
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 132. 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 131.
Note
You find all the details about compatibility between different PC SDK versions
in the Release Notes.
Tip
When compiling your project, notice any warnings of obsolete methods, as these
will probably be removed in the next PC SDK release.
Continued
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
3HAC036957-001 Revision: A 41
© Copyright 2010-2012 ABB. All rights reserved.
This page is intentionally left blank
4 Developing Controller applications
4.1 Introduction
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.
3HAC036957-001 Revision: A 43
© Copyright 2010-2012 ABB. All rights reserved.
4 Developing Controller applications
4.2 Analysis and design
Continued
In short, involving end-users from the early stages and keeping them involved
throughout the development project is the best strategy.
Note
Continued
46 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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.
Continued
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
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();
}
Continued
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: A 49
© Copyright 2010-2012 ABB. All rights reserved.
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
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.
Continued
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"
MessageBox.Show(msg, title, MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
Tip
Learn more about UAS and Grant members in the Reference Manual PC SDK.
3HAC036957-001 Revision: A 51
© Copyright 2010-2012 ABB. All rights reserved.
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 value and reference types:
VB:
If TypeOf aRapidData.Value Is Num Then
Dim aNum As Num = DirectCast(aRapidData.Value, Num)
......
End If
C#:
if (aRapidData.Value is Num)
{
Num aNum = (Num)aRapidData.Value;...... }
Continued
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: A 53
© Copyright 2010-2012 ABB. All rights reserved.
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
54 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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:
8.2.2_1Class
Continued
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.
56 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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.
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.
Continued
7.1_1PCApp
Continued
Continued
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 48.
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>(AddControllerToListView),
new Object[] { this, e });
}
This event handler updates the user interface:
VB:
Private Sub AddControllerToListView(ByVal sender As Object, ByVal
e As NetworkWatcherEventArgs)
Dim controllerInfo As ControllerInfo = e.Controller
Dim item As 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
End Sub
Continued
C#:
private void AddControllerToListView(object
sender,NetworkWatcherEventArgs e)
{
ControllerInfo controllerInfo = e.Controller;ListViewItem 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);this.listView1.Items.Add(item);item.Tag
= controllerInfo;
}
Continued
{
MessageBox.Show("Selected controller not available.");
}
}
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.
Continued
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);
}
}
3HAC036957-001 Revision: A 63
© Copyright 2010-2012 ABB. All rights reserved.
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();
For a complete code sample, see Implement network scanning on page 58.
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.
Continued
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.
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 59.
3HAC036957-001 Revision: A 65
© Copyright 2010-2012 ABB. All rights reserved.
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 64. 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 Accessing
the controller on page 66.
Continued
Note
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.
Continued
VB:
Dim aUserInfo As New UserInfo("name", "password")
C#:
UserInfo aUserInfo = new UserInfo("name", "password");
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 62.
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>(OperatingModeChanged);
AController.StateChanged += new
EventHandler<StateChangedEventArgs>(StateChanged);
AController.ConnectionChanged += new
EventHandler<ConnectionChangedEventArgs>(ConnectionChanged);
Note
Controller events use their own threads. Carefully study Controller events and
threads on page 47 to avoid threading conflicts.
Continued
Note
PC SDK 5.09 and onwards uses the generic event handling introduced by .NET
Framework 2.0.
CAUTION
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#:
string restoreDir = "(BACKUP)$" + dirName;
using (Mastership mc =
Mastership.Request(this.aController.Configuration), mr =
Mastership.Request(this.aController.Rapid))
Continued
{
this.aController.Restore(restoreDir, RestoreIncludes.All,
RestoreIgnores.All);
}
Note
You need to be logged in with required grants to perform the above functions.
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();
There are also the asynchronous method calls BeginChangeOperatingMode and
EndChangeOperatingMode. It is important to use the second method in the
callback since it returns the waiting thread to the thread-pool.
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);
Continued
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 56.
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 15.
3HAC036957-001 Revision: A 71
© Copyright 2010-2012 ABB. All rights reserved.
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 78.
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")
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")
Continued
C#:
rd = aController.Rapid.GetTask("T_ROB1").GetModule("user").
GetRapidData("reg1");
Note
From RobotWare 5.12 onwards, even if the data is declared in a Shared Hidden
module it can be accessed by the PC SDK.
Continued
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)
{
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 75.
The following is an example of a complex data type. The ToolDataTframe 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();
Continued
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];
The frame1 coordinate transformation is assigned a value that corresponds to a
displacement in position where X=50mm, Y=0mm, and Z=40mm. There is no
rotation.
The RapidDomain.Pose structure consists of two struct variables called trans
and rot of the data types Pos and Orient. Pos has three floats and Orient consists
of four doubles. The FillFromString format for a Pose object is “[[1.0, 0.0, 0.0,
0.0][10.0, 20.0, 30.0]]”.
The example shows how to write a new value to a RAPID pose variable:
VB:
If TypeOf rd.Value Is Pose Then
Dim rapidPose As Pose = DirectCast(rd.Value, Pose)
rapidPose.FillFromString("[[1.0, 0.5, 0.0, 0.0][10, 15, 10]]")
rd.Value = rapidPose
End If
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;
}
Continued
Note
The string format must be carefully observed. If the string argument has a wrong
format, a RapidDataFormatException is thrown.
Continued
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
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
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 47.
Continued
VB:
Private Sub UpdateGUI(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim tool1 As ToolData = DirectCast(Me.rd.Value, ToolData)
Me.label1.Text = tool1.Tframe.Trans.ToString()
End Sub
C#
private void UpdateGUI(object sender, System.EventArgs e)
{
ToolData tool1 = (ToolData)this.rd.Value;
this.label1.Text = tool1.Tframe.Trans.ToString();
}
Note
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 66.
Continued
VB:
If rd IsNot Nothing Then
rd.Dispose()
rd = Nothing
End If
C#:
if (rd != null)
{
rd.Dispose();
rd = null;
}
3HAC036957-001 Revision: A 79
© Copyright 2010-2012 ABB. All rights reserved.
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 passing the dimension index as argument.
VB:
Dim aRank As Integer = ad.Rank
Dim len As Integer = ad.GetLength(aRank)
C#:
int aRank = ad.Rank;
int len = ad.GetLength(aRank);
Continued
3HAC036957-001 Revision: A 81
© Copyright 2010-2012 ABB. All rights reserved.
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);
Note
82 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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.
Continued
Continued
Continued
C#:
public struct ProcessData: IRapidData
Continued
{
private UserDefined data;
Continued
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
Set(ByVal Value As Integer)
Dim tmp As Num = New Num
tmp.FillFromNum(Value)
IntData.Components(0) = tmp
End Set
End Property
C#:
public int Step
{
get
{
int res = Convert.ToInt32(IntData.Components[0].ToString());
return res;
}
set
{
Num tmp = new Num();
tmp.FillFromNum(value);
IntData.Components[0] = tmp;
}
}
88 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
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)
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 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 de-
clared within the routine, whereas a scope-search will return
the symbols accessible from the routine.
Continued
Property Description
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 Func-
tion, Procedure and Trap. RapidData includes Constant,
Variable and Persistent.)
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 recurs-
ively 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:
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;
Continued
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.
Note
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);
Continued
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;
RapidSymbol[] rsCol;
rsCol = aTask.SearchRapidSymbol(sProp, "num", string.Empty);
Continued
Note
3HAC036957-001 Revision: A 93
© Copyright 2010-2012 ABB. All rights reserved.
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 Accessing the controller on page 66.
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 File system domain on page 112.
Note
Continued
ResetProgramPointer method
Using ResetProgramPointer you can set the program pointer to the main entry
point of the task.
VB:
aTask.ResetProgramPointer()
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();
Note
If your application uses the User Authorization System of the controller (see User
Authorization System on page 50), you should also check whether the current
user has the grant UAS_RAPID_EXECUTE before calling the Start method.
Continued
VB:
AddHandler aController.Rapid.ExecutionStatusChanged, AddressOf
Rapid_ExecutionStatusChanged
C#
aController.Rapid.ExecutionStatusChanged += new
EventHandler<ExecutionStatusChangedEventArgs>(Rapid_ExecutionStatusChanged);
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 106and
Letting the user know that RAPID data has changed on page 77.
96 3HAC036957-001 Revision: A
© Copyright 2010-2012 ABB. All rights reserved.
5 Using the PC SDK
5.5.7 Enable operator response to RAPID UI-instructions from a PC
Note
Remote operator dialog can only be used with RobotWare 5.12 and later.
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 :
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 UI-
AlphaEntryEventArgs.SendAnswer.
Tip
For complete information about the usage in RAPID refer to RAPID Technical
reference manual (accessiable from RobotStudio).
Continued
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 47.
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 of the Rapid class, like this:
Controller c = new Controller();
c.Rapid.UIInstruction.UIInstructionEvent += new
UIInstructionEventHandler(OnUIInstructionEvent);
Tip
Continued
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.
7.5.7_1UIIns
Continued
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_2UIIns
Continued
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:
public void SendAnswer(int listItemIdx, UIButtonResult btnRes);
Note
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 105.
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;
This example shows a how an AnalogSignal is created:
VB:
Dim aiSig As AnalogSignal = DirectCast(Signal1, AnalogSignal)
C#:
AnalogSignal aiSig = (AnalogSignal)signal2
This example shows a how a GroupSignal is created:
VB:
Dim giSig As GroupSignal = DirectCast(signal3, GroupSignal)
C#:
GroupSignal giSig = (GroupSignal)signal3;
Note
Remember to call the Dispose method of the signal when it should no longer
be used.
Continued
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;}
Continued
Analog signal
The following of code reads the value of the analog signal AO1 and displays it in
a textbox:
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();
}
}
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
Continued
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);
Continued
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);
Continued
{
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 Accessing the controller on page 66.
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.
Note
Continued
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,
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 Controller events and threads on page 47.
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.
Continued
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
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 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)
Continued
C#:
aController.FileSystem.PutFile(localFilePath, remoteFilePath);
Continued
Tip
Find out more about the FileSystemDomain in the PC SDK Reference help.
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
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.
Continued
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.
en0700000430
Note
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.
Continued
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_1Messagi
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
Continued
receive a message from RAPID you must first create your own message queue
and use that object with the Receive method.
Note
When the execution context in a RAPID task is lost, for example when the program
pointer is moved to main, the corresponding queue is emptied.
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 120.
Continued
Note
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.
Continued
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_2Syspara
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 119.
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;
Continued
Continued
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;
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;
Continued
ENDTRAP
ENDMODULE
Note
Note
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.
Continued
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 sys-
tem.
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
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.
Continued
Code Description
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.
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.
0xC0049010 Illegal to move PCP to given place.
0xC0049011 Max number of rob targets exceeded.
0xC0049012 Object is not mod possible. Possible reasons are: object is a variable, object
is a parameter, object is an array.
0xC0049013 Operation not allowed with displacement active.
Continued
Code Description
0xC0049014 The robot is not on path and is unable to restart. Regain to path. Clear is
not allowed.
0xC0049015 Previously planned path remains. Choose to either consume the path, which
means the initial movement might be in an unexpected direction, or to clear
the path and move directly to next target.
0xC004A000 General file handling error.
0xC004A001 The device is full.
0xC004A002 Wrong disk. Change disk and try again.
0xC004A003 The device is not ready.
0xC004A004 Invalid path.
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
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 47 and Invoke method
on page 48.
• 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 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 67 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
Continued
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 Licence verification - applies only
to versions earlier than PC SDK 5.10 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.
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
Continued
Index
A
Array, 80 G
dimensions, 80 GAC, 20
enumerator, 81
indexers, 80 I
object, 80 Installation, 19
Requirements, 19
C Invoke, 48
compatibility, 40 IRC5 controller., 13
Configuration, 35
App.config, 35 N
CAPI, 35 NetworkScanner, 64
Section tag, 35 NetworkWatcher, 65
ControllerInfo Object, 65
R
E ReadItem, 82
Exception, 52 Remote operator dialog, 97
.Error Codes, 125
.NET, 53 S
Try-catch, 52 safety, 11
Typecasting, 52 W
WriteItem, 82
ABB AB
3HAC036957-001, Rev A, en
Discrete Automation and Motion
Robotics
S-721 68 VÄSTERÅS, Sweden
Telephone +46 (0) 21 344 400
www.abb.com/robotics