SYS600 - Communication Programming Interface
SYS600 - Communication Programming Interface
4
Communication Programming Interface (CPI)
Trace back information:
Workspace Main version a26
Checked in 2014-05-16
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Contents
1 Copyrights ............................................................................................. 5
2 Introduction ........................................................................................... 7
2.1 This manual .................................................................................. 7
2.2 Use of symbols ............................................................................. 8
2.3 Related documents ....................................................................... 9
2.4 Document conventions ................................................................. 9
2.5 Document revisions ...................................................................... 10
3
SYS600 9.4 MicroSCADA Pro 1MRS758104
7 Terminology ........................................................................................... 77
8 Abbreviations ........................................................................................ 79
Index ....................................................................................................... 81
4
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
1 Copyrights
The information in this document is subject to change without notice and should not be
construed as a commitment by ABB Oy. ABB Oy assumes no responsibility for any
errors that may appear in this document.
In no event shall ABB Oy be liable for direct, indirect, special, incidental or consequential
damages of any nature or kind arising from the use of this document, nor shall ABB Oy
be liable for incidental or consequential damages arising from the use of any software
or hardware described in this document.
This document and parts thereof must not be reproduced or copied without written
permission from ABB Oy, and the contents thereof must not be imparted to a third party
nor used for any unauthorized purpose.
The software or hardware described in this document is furnished under a license and
may be used, copied, or disclosed only in accordance with the terms of such license.
Copyright © 2014 ABB Oy. All rights reserved.
Trademarks
ABB is a registered trademark of ABB Group. All other brand or product names
mentioned in this document may be trademarks or registered trademarks of their respective
holders.
Guarantee
Please inquire about the terms of guarantee from your nearest ABB representative.
Third Party Copyright Notices
List of third Party Copyrights notices are documented in "3rd party licenses.txt" and
included in SYS600 installation package.
5
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
2 Introduction
CPI interface
Communication Programming Interface CPI is a protocol environment software that is
used for externally implemented protocol converters.
CPI is a collection of functions that enables the data transfer between the SYS600 base
system and the CPI application program. The CPI library contains functions for sending
and receiving messages to or from the SYS600 base system, as well as functions for
packing and unpacking data of messages. The CPI application program may be run on
different computers as can be seen in Figure 2.1 or also on the same computer with
SYS600.
The CPI application program (gateway program), which uses the CPI interface, emulates
the NET containing stations of the RTU, SPA or SPI (RP 570 slave) device type. The
SPI device type can also be emulated as a RTU device type. In this case, the SPI station
should be configured as a RTU station by the SYS600 base system. CPI supports both
the slave and the master communication.
Normally, only those messages sent from the base system to the station devices (RTU,
SPA), which have been configured in the CPI application node, are visible for the CPI
functions. To be able to emulate a conventional NET unit operation, there is also a need
to access messages directed to the CPI application node itself (NET object). To access
these messages, filtering must be disabled using the message filtering functions (see
Chapter 5 CPI library).
7
SYS600 9.4 MicroSCADA Pro 1MRS758104
Figure 2.1: SYS600 connected to a foreign system that has a CPI application program as a part
of it. The data transmission between the CPI application program and the SYS600 base system
is implemented through the TCP/IP interface.
TCP/IP interface
The communication between applications using CPI and SYS600 is based on the TCP/IP
protocol. Transmission Control Protocol/Internet Protocol is used for data transmission
in LAN network to provide communication with several protocols across the connected
networks of computers (see Figure 2.1). On the TCP/IP interfaces, the ACP messages
are sent via stream type BSD sockets.
The CPI interface is designed to support connections to several applications running one
or more SYS600 base systems. All applications on one certain SYS600 base system can
be reached by using the same TCP/IP socket.
8
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Although warning hazards are related to personal injury, and caution hazards are
associated with equipment or property damage, it should be understood that operation
of damaged equipment could, under certain operational conditions, result in degraded
process performance leading to personal injury or death. Therefore, comply fully with
all warnings and caution notices.
9
SYS600 9.4 MicroSCADA Pro 1MRS758104
The user may be told to enter the string MIF349 in a field. The string is shown as
follows in the procedure: MIF349
• Variables are shown using lowercase letters: sequence name
10
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
3 CPI overview
Figure 3.1: CPI communication emulates the communication between the SYS600 base system
and the NET unit
GV_Initialize_Connection()
/* Infinite loop*/
for(;;)
{
in_set = out_set = exp_set = 0x7;
cpiSelect( &in_set, &out_set, &exp_set,15);
11
SYS600 9.4 MicroSCADA Pro 1MRS758104
if (cpiISSET(1, in_set)) {
cpiGetMessage(1, &recv_id, &msg_type);
switch( msg_type ) {
case cpiWRMSG:
GV_Initialize_Connection()
reply_ready = 1;
/*Infinite loop*/
for(;;)
{
in_set = out_set = exp_set = 0x1;
12
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
13
SYS600 9.4 MicroSCADA Pro 1MRS758104
The NET unit can communicate simultaneously with several applications on the base
system. The CPI library using the ACP communication supports the following types of
message dialogues presented in Figure 3.2:
a) Write commands: The base system writes the value of an attribute to the CPI application
program.
b) Read commands: The base system requests the value of an attribute from the CPI
application program.
c) Write commands: The CPI application program writes data to the base system process
database.
d) Notifications: The system message is sent from the CPI application program to the
base system.
ACP messages
Each communication system contains a set of system objects, which specify the line
properties, connected devices etc. These objects can be created, modified and deleted
by SCIL (Supervisory Control Implementation Language), and setting the attributes of
the objects can change the properties. The detailed description of attributes can be found
in Chapter 6 Support for System Configuration Tool and the creation of protocol
converters in Chapter 4 Creating protocol converters with CPI.
The target of the ACP message sent by the SYS600 base system is an attribute of a
communication system object (NET, STA), which has been configured in the NET unit.
The attributes of the communication system object can be divided into two main
categories:
• Configuration attributes
14
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
• Communication attributes
Configuration attributes refer to the internal data of the NET unit.The NET unit can reply
to these messages immediately. Communication attributes refer to the external data of
the device. In this case, the ACP message must first be converted to the protocol of the
external device before sending it forward. The replies to the communication attributes
are usually not sent back to the base system before the actual reply from the external
device is received.
Data transmission from the base system to the CPI application program is done by setting
the attributes of the communication system object or the process object. This may happen
by using SCIL and its commands.
ACP implements the layers presented in Table 3.1
Table 3.1: ACP-OSI layer mapping
OSI ACP Feature Remark ACP layers
Application Varying Not explicity specified ACP
application layer
Proc. database and SCIL interface Device profiles
Presentation ACP Data Array formats Data coding rules
Session Attribute read/write Connectionless session model com-
parable with remote proc. calls
Transport ACP Transport ACP end-to-end acknowledge flow
control by delayed acknoledge
Network Device level network info Device level addressing ACP
network layer
ANSI X3.28 Node level addressing
Link TCP/IP ANSI Common Integrated According to system ACP
X3.28 RAM LINK components and topology link layer
Physical LAN HW RS-232-C Computer Computer According to link ACP
HW HW physical layer
15
SYS600 9.4 MicroSCADA Pro 1MRS758104
Table 3.3: Fields used for message routing on the device level
Field Description CPI function
LDS Logical destination cpiGetRtuNo (not read directly), cpiGet-
DeviceType, cpiGetDeviceNumber
LSR Logical source Connection number
CNT Transaction count
FNC Function cpiGetMessageType
(not read directly)
MBX Mailbox
ATR Attribute cpiGetAttribute
IND1 First index cpiGetIndex
IND2 Last index cpiGetIndex
DATA Device data cpiGetNextData, cpiGetNextDataType,
cpiGetNextAddrData
The following examples describe the relationship between SCIL and fields of the ACP
message:
Writing data to the CPI application:
#SET STA1:SDT(1..2)=(1,2)
16
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Reserved attributes
Because the CPI application program emulates STA objects in the NET unit, the use of
attributes is not completely free. Some attribute names are reserved for the RTU process
data communication. They cannot be used as the attributes of an application unless they
have been used exactly in the same way as in the RTU or SPA devices.
The following attributes are used by the system and therefore they are not allowed to be
used as the attributes of the application program. Except for the attributes below, attributes
can be formed by using any abbreviation that consist of two letters.
Table 3.4: The attributes not allowed to be used as the attributes of the application
program
Attribute Description
DA Process data
SM System status message
The messages to the DA attribute are generated automatically by the base system when
the output process objects are set. If this method is used with the CPI application program,
it must emulate the DA attribute handling exactly in the same way as the RTU device
does.
The attributes IU, SA, AL, AS, MI and MS are used with the RTU type station. It is
recommended that these attributes should be used in the same way as documented in
SYS600 System Objects manual.
17
SYS600 9.4 MicroSCADA Pro 1MRS758104
message, it usually will not help to transmit the same message again for it is very
possible that it replies with the error status again.
Configuration steps
To configure SYS_BASCON.COM:
1. Define the base system.
2. Define a LAN link.
3. Define an application.
4. Define nodes.
5. Define the RTU stations. The number of RTU stations can be the same as the number
of the connected process units. This way, the information related to a certain process
unit can be routed to the corresponding station in the NET unit. This way, the
information can be differentiated between different process units. In the COM 500i
configuration, it is possible to use a maximum of 8 NCC stations
The definitions are made in the example below. For more information on the system
objects, see SYS600 System Objects. Steps 1..3 are necessary , but they are configured
using the standard SYS_BASCON.COM template. Steps 4..5 are necessary for the CPI
application.
Example
The following is an example of the SYS_BASCON.COM file for communication with
the Modbus slave protocol. An application CPI_TEST together with two stations is
defined in the SYS600 base system.
;***********************************************************
;
; SYS_BASCON.COM
18
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
;***********************************************************
;
; COMMUNICATION LINKS
;***********************************************************
;
; COMMUNICATION NODES
;***********************************************************
;
; PRINTERS
;***********************************************************
;
; MONITORS
#LOOP_WITH I = 1..5
#CREATE MON'I':B = LIST(-
TT = "LOCAL",- ;TRANSLATION TYPE
DT = "X") ;X MONITOR
@MON_MAP(%I) = -1
#LOOP_END
#LOOP_WITH I = 6..10
#CREATE MON'I':B = LIST(-
TT = "LOCAL",- ;TRANSLATION TYPE
DT = "VS") ;VISUAL SCIL MONITOR
@MON_MAP(%I) = -1
#LOOP_END
;***********************************************************
;
; APPLICATIONS
#CREATE APL:V = LIST(-
TT = "LOCAL",- ;TRANSLATION TYPE
NA = "CPI_TEST",- ;NAME OF APPLICATION DIRECTORY
AS = "HOT",- ;APPLICATION STATE: COLD,WARM,HOT
HB = 2000,- ;HISTORY BUFFER SIZE)
RC = VECTOR("FILE_FUNCTIONS_CREATE_DIRECTORIES"),-
AP = (1,2),-
MO = %MON_MAP,- ;MONITOR MAPPING
19
SYS600 9.4 MicroSCADA Pro 1MRS758104
;***********************************************************
; STATIONS
20
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
When a protocol converter is implemented using the CPI library, the project normally
consists of the following parts:
• The application programming required in SYS600.
• The program that utilizes the CPI library for data transfer with the SYS600 base
system.
• The program that converts the messages between the foreign protocol and the CPI
application program.
• The program that handles the foreign protocol functions.
• An interface between the CPI part and the foreign protocol part of the program.
Furthermore, the protocol converters done with CPI can usually be divided into two
categories. In the first case, the SYS600 base system is seen as a master and the slave
devices connected via CPI collect data into the SYS600 process database. In the second
case, the SYS600 base system is seen as a slave device and data is sent from the SYS600
process database to the master via CPI. The use of CPI and the work needed in different
parts of the project differs significantly in these two cases. The following sections explain
the differences and give information about the possible solutions of implementing protocol
converters with CPI.
21
SYS600 9.4 MicroSCADA Pro 1MRS758104
Figure 4.1: The CPI application program acts as a master collecting data from the slave device
to the SYS600 process database. The slave device is seen as a RTU station by the SYS600 base
system.
Data transfer with the SYS600 base system using the CPI library
The process data received from the slave devices can be sent to the SYS600 process
database using the following CPI functions (detailed descriptions of each function can
be found in Chapter 5 CPI library). Notation “XXX” means that there are several functions
with variable timestamps.
Indications: cpiSendRtuIndicationXXX
Analog values: cpiSendRtuAnalogValueXXX
Pulse counters: cpiSendRtuPulseCounterXXX
Digital values: cpiSendRtuDigitalValue
22
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
The commands from the SYS600 base system can be handled using the following cpi
function:
cpiGetNextAddrData
With this function, it is possible to read the command object type, address and the value.
The object type of the command can be one of the following:
• Object command (binary output).
• Regulation command.
• Digital setpoint.
• Analog setpoint.
• General persistent output.
Interface between the CPI part and the foreign protocol part of the
program
There are several ways of handling the communication between the CPI part and the
foreign protocol part of the program. The example program delivered with the CPI
installation package named CPI_EXAMPLE uses common global variables for
transferring data between the program parts (threads).
23
SYS600 9.4 MicroSCADA Pro 1MRS758104
as closely as possible in order to be able to use the existing applications in the SYS600
base system. These applications are used for data transfer between the SYS600 base
system and the CPI application program (COM 500i).
Figure 4.2: SYS600 connected with the CPI application (e.g. Modbus Slave). The CPI application
acts as a slave providing data from the SYS600 database for the master.
24
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Interface between the CPI part and the foreign protocol part of the
program
There are several ways of handling the communication between the CPI part and the
foreign protocol part of the program. The example program delivered with the CPI
installation package named CPI_EXAMPLE uses common global variables for
transferring data between the program parts (threads).
25
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
5 CPI library
General
CPI library is a collection of functions for sending and receiving messages between
SYS600 and the CPI application, and also for message handling, packing and unpacking.
The functions contained in the CPI library are specified in this chapter. A list of the
program files is presented in Table 5.1 below.
Table 5.1: Program files for CPI
File Name Description
cpint.lib Microsoft Developer Studio Win32 Static Library file.
cpi.h Header file for the CPI functions.
cpicl.h CPI internal definition, type and function header file.
bufms.h CPI buffer handling definitions.
Part of the definition file cpi.h, which contains the definition for different data types:
typedef int cpiMsgID;
#define cpiU8 0
#define cpiS8 1
#define cpiU16 2
#define cpiS16 3
#define cpiU32 4
#define cpiS32 5
#define cpiF32 6
#define cpiADDR 7
#define cpiBV 8
#define cpiB 9
typedef struct {
cpiObjectType ObjectType;
unsigned int ObjectAddress;
int ObjectValue;
}addressItem;
typedef struct {
cpiDataType item_type;
union { /* this definition is cpu specific */
27
SYS600 9.4 MicroSCADA Pro 1MRS758104
/* Message types */
#define chaperons 1
#define cpiMsgID 2
#define cpiMsgID 3
#define cabinets 4
typedef struct {
unsigned char (year,month,day,hour,minute,second,ms)
} cpiTime;
28
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Function Description
cpiGetMessage Reads an ACP formatted message from the received message
queue.
cpiClearExceptionStatus Clearing the status when an exception has occurred.
cpiSetApplicationCold Set the "data not accepted flag" of the application.
cpiGetApplicationCold Returns the "data not accepted flag" of the application.
cpiSelect
This function checks the TCP/IP socket in case there are any messages coming from the
base system application, and if there are any connections ready for writing. It also returns
information if any of the connections have failed or any message has not got a reply in
time. Some of the communication between the base system and application is actually
done inside this function, so it must be called in the main loop of the CPI application.
The cpiSelect function returns when one of the specified input connections has received
a message, or after the specified time has elapsed.
When this function is called, its arguments specify which connections the user is interested
in. Then the function modifies the arguments to indicate the status of each connection.
Table 5.3: The bit position indicates the status of the connection
RD WR EX Description
bit0 bit0 bit0 connection 1 flags
bit1 bit1 bit1 connection 2 flags
bit2 bit2 bit2 connection 3 flags
RD Bit is set when CPI has received a message from this connection.
WR Bit is set when CPI does not wait any reply from this connection.
EX Bit is set when CPI has lost this connection or data message does not get reply
from this connection. The actual cause of exception can be determined by using
the cpiException function.
Return values:
0 : OK
cpiException
This function determines the cause of exception (cpiSelect EX flags).
int cpiException(int CONNECTION);
Return values:
29
SYS600 9.4 MicroSCADA Pro 1MRS758104
1 : TCP/IP error
- Connection to this node has been lost
2 : No reply error
- Message sent by CPI has not received a reply from
SYS600
6 : Application error
- Message sent by CPI has received a reply with error
status from SYS600
cpiSendMessage
This function sends an ACP formatted message to SYS600. Before using this function,
the message buffer must be reserved by using the functions cpiGetTransmissionBuffer
or GetReplyBuffer, and formatted by using some of the cpiPutXXXData functions
presented in Section 5.5.2 Data filling functions. (Notation XXX means that any function
of this type is available.)
int cpiSendMessage(int DESTIN, cpiMsgID ID, int TIMEOUT);
Return values:
0 : OK
-2 : Invalid MsgID ; the buffer ID is not free, or it is
unknown
cpiSendRtuMessage
This function sends an ACP formatted message to SYS600 from the RTU. Before using
this function, the message buffer must be reserved by using the function
cpiGetTransmissionBuffer and formatted by using some of the cpiPutXXXData functions
presented in Section 5.5.2 Data filling functions. (Notation XXX means that any function
of this type is available.)
int cpiSendRtuMessage(int DESTIN, int SOURCE, cpiMsgID ID, int TIMEOUT);
Return values:
0 : OK
-2 : Invalid MsgID
cpiSendSystemMessage
The following function can be used to send a system message from any device. This
function is present for backward compatibility and the usage of it is currently discouraged.
Function cpiSendStandardSystemMessage is preferred instead.
30
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
int cpiSendSystemMessage(int con, int source, int address, int dataValid, short
status)
source Source logical device, the following macro LOGICAL_AD-
DRESS(deviceType,deviceNumber)
address address of the ANSI analog input process object to be
updated
dataValid cpiDATA_VALID
;The updated data values from the device are valid
cpiDATA_NOT_VALID
status status value for the ANSI analog input process object
Example:
;Sending NET1 line status 12602 to address 6103:
cpiSendSystemMessage( con,
LOGICAL_ADDRESS(NET_DEVICE,1),
6103,
0,
12602)
cpiSendStandardSystemMessage
This function can be used to send a system message from any device. State values
cpiDEVICE_STATUS_CHANGES_TO_SUSPENDED and
cpiDEVICE_STATUS_CHANGES_TO_RUNNING will activate the predefined event
channel APL_EVENT. For more information, see SYS600 Application Objects. When
cpiSendStandardSystemMessage function is called, an ANSI analog input status point
with settings UN=0, OA=address in the receiving application is updated also. The usage
of this function is preferred instead of cpiSendSystemMessage.
int cpiSendStandardSystemMessage(int con, int source, int address, int newState,
short status)
where
source source Source logical device, the following macro should
be used to calculate the value LOGICAL_ADDRESS(device-
Type, deviceNumber)
address address of the ANSI analog input process object to be
updated
newState cpiDEVICE_STATUS_NOT_CHANGED
;Device status is not changed
cpiDEVICE_STATUS_CHANGES_TO_SUSPENDED
;Device status changes to suspended
cpiDEVICE_STATUS_CHANGES_TO_RUNNING
;Device status changes to running
status status value for the ANSI analog input process object
Example:
; Send a suspension status 13251 from SPA device 2.
cpiSendStandardSystemMessage( con,
LOGICAL_ADDRESS(SPA_DEVICE, 2)
1002,
cpiDEVICE_STATUS_CHANGES_TO_SUSPENDED,
13251)
cpiSendStandardSystemMessageWithBinary
This function can be used to send a system message from any device. State values
cpiDEVICE_STATUS_CHANGES_TO_SUSPENDED and
cpiDEVICE_STATUS_CHANGES_TO_RUNNING will activate the predefined event
31
SYS600 9.4 MicroSCADA Pro 1MRS758104
channel APL_EVENT, see System Application Objects manual for more information.
When cpiSendStandardSystemMessageWithBinary function is called, an ANSI analog
input status point with settings UN=0, OA=address and an ANSI binary input status
point with settings UN=0, OA=address+16777216 (1000000hex) in the receiving
application are updated. Values for the binary object are 1=OK, 0=not OK. The usage
of this function is preferred instead of cpiSendSystemMessage.
int cpiSendStandardSystemMessageWithBinary(int con, int source, int address, int
newState, short status)
where
con Connection number to destination application
source Source logical device, the following macro should be
used to calculate the value LOGICAL_ADDRESS(deviceType,
deviceNumber)
address address of the ANSI analog input process object to be
updated. The address of binary input status object is
address+16777216
newState cpiDEVICE_STATUS_NOT_CHANGED
;Device status is not changed (binary input status object
not updated)
cpiDEVICE_STATUS_CHANGES_TO_SUSPENDED
;Device status changes to suspended (binary input status
object updated to 0)
cpiDEVICE_STATUS_CHANGES_TO_RUNNING
;Device status changes to running (binary input status
object updated to 1)
status status value for the ANSI analog input process object
Example:
; Send a 'RUNNING' status from SPA device 2, analog input status object will be
updated with value 0 (no error) and the binary input will be updated with value
1 (connection OK)
cpiSendStandardSystemMessageWithBinary( con,
LOGICAL_ADDRESS(SPA_DEVICE, 2
1002,
cpiDEVICE_STATUS_CHANGES_TO_RUNNING,
0);
cpiSendNodeSystemMessage
This function can be used to send a system message from the CPI node itself. Calling
this function will update the ANSI analog input process object with the setting UN=0,
OA=address. The value of the process object can be given with the parameter STATUS
but for correct co-operation with System Self Supervision, it is recommended to use the
value 10001=NETP_SYSTEM_INITIALIZED. SSS uses this process object in its displays
to indicate the status of the node.
int cpiSendNodeSystemMessage(int con, int address, short status)
where
con Connection number to destination application
address address of the ANSI analog input process object to be
updated, value used by SSS is 6000+node number
status status value for the ANSI analog input process object
Example:
; Send NETP_SYSTEM_INITIALIZED status message indicating that the CPI node has
started and established connection to the basesystem.
cpiSendNodeSystemMessage( con,
32
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
6002,
10001);
cpiSendNodeSystemMessageWithBinary
This function can be used to send a system message from the CPI node itself. Calling
this function will update the ANSI analog input process object with the setting UN=0,
OA=address, and the ANSI binary input process object with setting UN=0, OA=address
+ 1000000hex. The value of the analog input process object can be given with the
parameter STATUS but for correct co-operation with System Self Supervision, it is
recommended to use the value 10001=NETP_SYSTEM_INITIALIZED. The value of
the binary input object will always be 1.
SSS uses these process objects in its displays to indicate the status of the node.
int cpiSendNodeSystemMessageWithBinary(int con, int address, short status)
where
con Connection number to destination application
address address of the ANSI analog input process object to be
updated, value used by SSS is 6000+node number
status status value for the ANSI analog input process object
Example:
; Send NETP_SYSTEM_INITIALIZED status message indicating that the CPI node has
started and established connection to the basesystem.
cpiSendNodeSystemMessageWithBinary( con,
6002,
10001);
cpiSendStandardUserActivityMessage
This function can be used to send a user activity event system message from the station
object to any device. When cpiSendStandardUserActivityMessage function is called, a
corresponding ACP message is sent to the basesystem node. The content of the message
is based on the information in the structure pointer by the pUAL_Event.
Parameter pathstr should refer to attribute MN
int cpiSendStandardUserActivityMessage (int con, UAL_EventType *pUALEvent, char
*pathstr, int timeout, cpiMsgID *id);
pUAL_EVENT Pointer UAL_EventType Structure containing the user
activity event information
pathstr pointer to NULL-terminated string of max. 16 characters
to identify the sender STA object
TIMEOUT Timeout in ms
cpiGetMessage
This function reads an ACP formatted message from the received message queue.
33
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-4 : No messages from this source
cpiClearExceptionStatus
This function clears a certain status code when an exception has occurred. If, for example,
the function cpiException has returned 6=Application Error, the status can be cleared in
order to retry the data transmission to the base system as well as enable the accessing of
CPI Node from other MicroSCADA application. This function is needed, for example,
in the Hot Standby implementation, if the main application receiving the data is not ready
to accept data and causes an exception, access from WD application is still needed.
int cpiClearExceptionStatus(int CONNECTION, short c_status);
Example: if cpiException has returned 6 = application error, the
status should be cleared with a call
cpiClearExceptionStatus(mConn, SYST_APPLICATION_DOES_NOT_EXIST);
Return values:
0 : OK
cpiSetApplicationCold
This function sets the value of the "data not accepted" flag of the given application. This
function is not necessarily used but it can be used if there is a need clear the mentioned
flag. See also cpiGetApplicationCold.
void cpiSetApplicationCold( int CONNECTION, int STATE);
CONNECTION Source connection number
STATE 0=application accepts data
1=application does not accept data
cpiGetApplicationCold
This function returns the value of the "data not accepted" flag of the given application.
This function is needed in Hot Standby implementations in order to know if the next
transmission to the application should be done or not. In case an error
SYST_APPLICATION_DOES_NOT_EXIST=7049 has been returned to the previous
data transmission, the "data not accepted" flag of the receiving application is set to 1 to
indicate that the application is not ready to accept data. The retransmission can be done
after a delay to see if the situation has changed. In MicroSCADA version 9.3 and newer,
the application which is in COLD state may also accept data since it uses its own
buffering.
34
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : application accepts data
1 : application does not accept data
cpiGetFailedMessage
This function returns the id of the failed message. The failed message has not received
a reply from the application.
int cpiGetFailedMessage(int DESTIN, cpiMsgID *ID);
ID Id for failed message
DESTIN Destination connection number
Return values:
0 : OK
-4 : No failed messages in this connection
cpiRetransmitMessage
This function retransmits the message, which is in the failed message queue.
int cpiRetransmit(cpiMsgId ID);
Return values:
0 : OK, retransmission started
-2 : Invalid MsgID
cpiGiveUp
This function deletes a message from the failed message queue.
int cpiGiveUp(cpiMsgId ID);
Return values:
0 : OK
35
SYS600 9.4 MicroSCADA Pro 1MRS758104
-2 : Invalid MsgID
cpiNetMessageFiltering
The current state of the filtering can be read by this function.
int cpiNetMessageFiltering();
Return values:
0 = off
1 = on
cpiSetNetMessageFiltering
Controls filtering of messages sent by the base system.
void cpiNetMessageFiltering(int value);
value:
0 = off
1 = on (default)
36
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
The RTU Object Model is based on an object type and object block number concept (see
SYS600 Application Objects). For input process data the object block number range is
1…255. For commands (from the SYS600 application to the CPI application) the range
is 1…2047.
Table 5.6: RTU - application level data transmission services
Function Description
cpiSendRtuStatusMessage Sends an ACP formatted notification message to SYS600.
cpiSendRtuIndication Sends indication values to the base system process database.
cpiSendRtuIndicationBlock Sends an indication value block to the base system process data-
base.
cpiSendRtuIndication- Sends the indication values with timestamp to the base system
WithTS process database.
cpiSendRtuAnalogValue Sends an analog value to the base system process database.
cpiSendRtuAnalogValue- Sends an analog value with timestamp to the base system process
WithTS database.
cpiSendRtuPulseCounter Sends a pulse counter value to the base system process database.
cpiSendRtuPulseCounter- Sends a pulse counter value with timestamp to the base system
WithTS process database.
cpiSendRtuBitStream Sends a bit string to the process object database of the base sys-
tem.
cpiSendRtuStatusMessage
This function sends an ACP formatted notification message to SYS600. A reply to this
message is not expected.
int cpiSendRtuStatusMessage(int DESTIN, int SOURCE, int STYPE, int DATAVALID,
short STATUS );
DESTIN Destination connection number
SOURCE Source RTU number
STYPE Status type
0 -> Device status message
1 -> Terminal status message
2 -> Terminal event message
3 -> Terminal message
DATAVALID 0 -> data is not longer valid in this RTU.
1-> data is valid in this RTU
STATUS Status code
Return values:
0 : OK
-13 : No buffer -> CPI cannot get a buffer for the message
37
SYS600 9.4 MicroSCADA Pro 1MRS758104
The following status codes are valid when the front-end emulates the RTU device (see
SYS600 Status Codes):
RTU level status codes:
0 OK_STATUS
12602 RTUP_DEVICE_SUSPENDED
12603 RTUP_TIMEOUT_WHILE_WAITING_RESPONSE
12604 RTUP_DEVICE_STOPPED
12605 RTUP_DEVICE_STARTED
12658 RTUC_INVALID_INDEX_RANGE
12662 RTUC_ATTRIBUTE_IS_WRITE_ONLY
12665 RTUC_NOT_EXECUTED_RESPONSE
12676 RTUC_UNEXPECTED_VALUE
Descriptions:
0 OK_STATUS
The purpose of this status message is to indicate that the CPI application program
considers the RTU connection to be working properly. This should always be sent right
after the start-up situation, when a connection has been established. It should also be
sent after a communication break, when the connection has been re-established.
12602 RTUP_DEVICE_SUSPENDED
When the CPI application program activates an RTU device image for the process
communication, this is the first system message to be sent. It indicates that the CPI
application program does not currently have the connection to this RTU but it is trying
to establish it since this is the RTU connection start-up situation.
It is also sent when the CPI application program detects that the connection to a certain
RTU is lost. The DATAVALID parameter is set to false to indicate that the process
database image of this RTU is no longer valid (see above).
12603 RTUP_TIMEOUT_WHILE_WAITING_RESPONSE
This status message indicates that the RTU did not react to the message initiated from
a SYS600 application. Note that this means no response at all. The negative acknow-
ledgements are handled by the "Not executed response" status code.
38
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
12604 RTUP_DEVICE_STOPPED
The RTU device emulated in the CPI application program can be stopped by setting
its IU attribute to zero. This means that the connection to the RTU is properly discon-
nected. When this is done, the RTU image should send this status message to the SYS600
application. The DATAVALID flag should be set to FALSE since the updating of the
SYS600 process database now stops from this RTU image.
12605 RTUP_DEVICE_STARTED
When the IU attribute of a device is set to one (1), the RTU image should respond by
this system message. If this is the first time the RTU image is started after start-up, the
DATAVALID should be set to FALSE. If the RTU image receives an IU attribute while
the device connection is OK, the DATAVALID is set to TRUE.
12658 RTUC_INVALID_INDEX_RANGE
If the SYS600 application attempts to update an attribute with an invalid index (e.g.
index equal to 5 when the highest allowed index is 4), the RTU image responds with
this status message.
12662 RTUC_ATTRIBUTE_IS_WRITE_ONLY
The RTU image responds with this status message for attempts to read values from at-
tributes that can only be written. A typical example might be some of the command
type attributes.
12665 RTUC_NOT_EXECUTED_RESPONSE
This status message is sent to the SYS600 application when the RTU responds to the
command with a negative acknowledgement from the application.
12676 RTUC_UNEXPECTED_VALUE
This status message indicates the attempts to write an invalid value to a RTU image
attribute, e.g. a text value to an integer type attribute.
cpiSendRtuIndication
This function sends an indication value to the base system process database.
int cpiSendRtuIndication(int DESTIN, int SOURCE, int BLOCK, int BIT, int VAL,
int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
BLOCK Object address of the process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications, 10,11,12,13 for
double indications
39
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message has been
failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
Sending failed because of the reply for the previously
sent message
-22 : Invalid value
cpiSendRtuIndicationBlock
This function sends an indication value block to the base system process database.
int cpiSendRtuIndicationBlock(int DESTIN, int SOURCE, int BLOCK, int BVAL, int
STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
BLOCK Object address of the process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications, 10,11,12,13 for
double indications
BVAL 16 bit value
TS Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message has been
failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
The sending failed because the reply for the previously
sent message has not been received
-22 : Invalid value
cpiSendRtuIndicationWithTS
This function sends an indication value with timestamp to the base system process
database.
int cpiSendRtuIndicationWithTS(int DESTIN, int SOURCE, int BLOCK, int BIT, int
VAL, cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
BLOCK Object address of the process object
BIT Bit number destination word (0..15)
40
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message has been
failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
The sending failed because the reply for the previously
sent message
-22 : Invalid value
cpiSendRtuAnalogValue
This function sends an analog value to the base system process database.
int cpiSendRtuAnalogValue(int DESTIN, int SOURCE, int BLOCK, int VAL,int STATUS,
int FLAGS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
BLOCK Object address of process object
VAL Value of an analog value, the value range is [-
2000...+2000].
Incoming values must be scaled to this range.
TS Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
FLAGS Status flags of analog value process objects
bit0 -> Lo Alarm flag
bit1 -> Lo Warning flag
bit2 -> Hi Warning flag
bit3 -> Hi Alarm flag
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message has been
failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
The sending failed because of the reply for the previ-
ously sent message
-22 : Invalid value
cpiSendRtuAnalogValueWithTS
This function sends an analog value with timestamp to the base system process database.
int cpiSendRtuAnalogValueWithTS(int DESTIN, int SOURCE, int BLOCK, int VAL,
cpiTime TS, int STATUS, int FLAGS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
41
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message has been
failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
The sending failed because of the reply for the previ-
ously sent message
-22 : Invalid value
cpiSendRtuPulseCounter
This function sends a pulse counter value to the base system process database.
int cpiSendRtuPulseCounter(int DESTIN, int SOURCE, int BLOCK, long VAL,int
STATUS,int FLAGS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
BLOCK Object address of the process object
VAL Value of the pulse counter
TS Timestamp
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0= ok)
FLAGS Status flags of the pulse counter process objects
bit4 -> End of the period flag
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message has been
failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting
The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendRtuPulseCounterWithTS
This function sends a pulse counter value with timestamp to the base system process
database.
42
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message has been
failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendRtuBitStream
This function sends a bit string to the process object database of the base system.
int cpiSendRtuBitStream(int DESTIN, int SOURCE, int ADDR, int LEN, char STREAM[],
int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source RTU number
ADDR Address of the process object
LEN Length of bitstream in bits !!
STREAM Array of bits stored on the char array
(Bitstream begins fromv bit0 of first char)
TIMEOUT Timeout in milliseconds
FLAGS Status flags of the pulse counter process objects
bit4 -> End of the period flag
Return values:
0 : OK
-7 : Buffer full, the length of the bit stream is too long.
The following functions reserve a buffer for a message, fill and send it from the SPA
type device to the base system.
Table 5.7: SPA - application level data transmission services
Function Description
cpiSendSpaAnalogValueWithTSandFlags Sends an analog value with alarm flags and
timestamp to the base system process data-
base.
43
SYS600 9.4 MicroSCADA Pro 1MRS758104
Function Description
cpiSendSpaAnalogValueWithTS Sends an analog value with timestamp to the
base system process database.
cpiSendSpaAnalogValue Sends an analog value to the base system pro-
cess database.
cpiSendSpaDigitalValueWithTSandFlags Sends a digital value with alarm flags and
timestamp to the base system process data-
base.
cpiSendSpaDigitalValueWithTS Sends a digital value with timestamp to the base
system process database.
cpiSendSpaDigitalValue Sends a digital value to the base system pro-
cess database.
cpiSendSpaIndicationWithTS Sends an indication value with timestamp to the
base system process database.
cpiSendSpaIndicationBlockWithTS Sends an indication value block with timestamp
to the base system process database.
cpiSendSpaIndication Sends an indication value to the base system
process database.
cpiSendSpaIndicationBlock Sends an indication value block to the base
system process database.
cpiSendSpaPulseCounterWithTS Sends a pulse counter value with timestamp to
the base system process database.
cpiSendSpaStatusMessage Sends an ACP formatted notification message
to SYS600.
cpiSendSpaMessage Sends an ACP formatted message to SYS600
from SPA.
cpiSendSpaBitStream3 Updates a bitstream process object in the base
system process database.
cpiSendSpaBitStream3WithTS Updates a bitstream process object with
timestamp in the base system process data-
base.
cpiSendBufferedSpaIndicationWithTS Sends an indication value with timestamp to the
base system process database. Indication is
marked as buffered.
cpiSendSpaBufferedIndicationBlockWithTS Sends an indication value block with timestamp
to the base system process database. Indication
block is marked as buffered.
cpiSendSpaAnalogValueWithTSandFlags
This function sends an analog value with timestamp to the base system process database.
The parameter 'FLAGS' is used to provide alarm information of the measured value.
int cpiSendSpaAnalogValueWithTSandFlags(int DESTIN, int SOURCE, int BLOCK, float
VAL, cpiTime TS, int STATUS, int FLAGS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
44
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-The sending failed because the reply to the previously
sent message has not been received
-20 : Connection waiting
-22 : Invalid value
cpiSendSpaAnalogValueWithTS
This function sends an analog value with timestamp to the base system process database.
int cpiSendSpaAnalogValueWithTS(int DESTIN, int SOURCE, int BLOCK, float VAL,
cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
VAL Value of an analog value
TS Timestamp
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting, previously sent message has not
been received
-22 : Invalid value
cpiSendSpaAnalogValue
This function sends an analog value without timestamp to the base system process
database.
int cpiSendSpaAnalogValue(int DESTIN, int SOURCE, int BLOCK, float VAL, int
STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of the process object
VAL Value of an analog value
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0 = ok)
45
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaDigitalValueWithTSandFlags
This function sends a digital value with timestamp to the base system process database.
The parameter FLAGS is used to provide alarm information of the measured value.
int cpiSendSpaDigitalValueWithTSandFlags(int DESTIN, int SOURCE, int BLOCK, short
VAL, cpiTime TS, int STATUS, int FLAGS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of the process object
VAL Digital value
TS Timestamp
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0 = ok)
FLAGS Status flags of analog value process objects
bit0 -> Lo Alarm flag
bit1 -> Lo Warning flag
bit2 -> Hi Warning flag
bit3 -> Hi Alarm flag
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaDigitalValueWithTS
This function sends a digital value with timestamp to the base system process database.
int cpiSendSpaDigitalValueWithTS(int DESTIN, int SOURCE, int BLOCK, short VAL,
cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of the process object
VAL Digital value
TS Timestamp
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0 = ok)
Return values:
0 : OK
46
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
cpiSendSpaDigitalValue
This function sends a digital value without timestamp to the base system process database.
int cpiSendSpaDigitalValue(int DESTIN, int SOURCE, int BLOCK, short VAL, int
STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
VAL Digital value
TS Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaIndicationWithTS
This function sends an indication value with timestamp to the base system process
database.
int cpiSendSpaIndicationWithTS(int DESTIN, int SOURCE, int BLOCK, int BIT, int
VAL, cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications, 10,11,12,13 for
double indications
BVAL 16 bit value
TS Timestamp Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message failed
-13 : cannot get buffer for transmission message
47
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiSendSpaIndicationBlockWithTS
This function sends an indication value block with timestamp to the base system process
database.
int cpiSendSpaIndicationBlockWithTS(int DESTIN, int SOURCE, int BLOCK, int BVAL,
cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications,
BVAL 16 bit value
TS Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaIndication
This function sends an indication value to the base system process database.
int cpiSendSpaIndication(int DESTIN, int SOURCE, int BLOCK, int BIT, int VAL,
int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications,
BVAL 16 bit value
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
48
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
cpiSendSpaIndicationBlock
This function sends an indication value block to the base system process database.
int cpiSendSpaIndicationBlock(int DESTIN, int SOURCE, int BLOCK, int BVAL, int
STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
BIT Bit number destination word (0..15)
VAL Value of bit 0,1 for single indications,
10,11,12,13 for double indications
BVAL 16 bit value
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaPulseCounterWithTS
This function sends a pulse counter value with timestamp to the base system process
database.
int cpiSendSpaPulseCounterWithTS(int DESTIN, int SOURCE, int BLOCK, long VAL,
cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
VAL Value of the pulse counter
TS Timestamp
TIMEOUT Timeout in milliseconds
STATUS Status code for data (0 = ok)
Return values:
0 : OK
-7 : Buffer full, the filling of the ACP message failed
-13 : Cannot get buffer for transmission message
-20 : Connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaStatusMessage
This function sends an ACP formatted notification message to SYS600.
49
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-13 : No buffer -> cpi cannot get buffer for message
The following status codes are valid when the front-end emulates the SPA device (see
SYS600 Status Codes):
SPA status codes:
0 OK_STATUS
13201 SPAC_SC_DATA_OVERFLOW
13202 SPAC_TOO_LONG_REPLY_RECEIVED
13203 SPAC_SPA_ADDRESS_NOT_CONFIGURED
13204 SPAC_DEVICE_MUST_BE_ALLOCATED
13205 SPAC_UNKNOWN_DIAGNOSTIC_COUNTER
13206 SPAC_INVALID_INDEX_RANGE
13207 SPAC_INVALID_RT_ATTRIBUTE_VALUE
13208 SPAC_UNKNOWN_SPA_ATTRIBUTE
13209 SPAC_ILLEGAL_APPLICATION_FOR_OPERATION
13210 SPAC_ATTRIBUTE_IS_WRITE_ONLY
13211 SPAC_ILLEGAL_BROADCAST_ACTION
13212 SPAC_UNEXPECTED_RESPONSE
13213 SPAC_INVALID_ATTRIBUTE_VALUE
13214 SPAC_CHAR_TYPE_EXPECTED
13215 SPAC_INTERNAL_ERROR
13216 SPAC_INVALID_POINT_DEFINITION
13217 SPAC_DATABASE_UPDATE_COMPLETED
13218 SPAC_TOO_MANY_ARGUMENTS
13219 SPAC_ARGUMENT_EXPECTED
13220 SPAC_UNABLE_TO_ALLOCATE_MEMORY
50
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
13221 SPAC_POINT_DEFINITION_NOT_FOUND
13222 SPAC_NO_ACKNOWLEDGE_RESPONSE
13223 SPAC_UNEXPECTED_VALUE_TYPE
13224 SPAC_ILLEGAL_OBJECT_TYPE
13225 SPAC_ONLY_WRITE_IS_POSSIBLE
13226 SPAC_NO_ACKNOWLEDGE_REPLY
13227 SPAC_EVENT_DATA_DISCREPANCY_DETECTED
13251 SPAP_DEVICE_SUSPENDED
13252 SPAP_DEVICE_STOPPED
13253 SPAP_DEVICE_STARTED
13254 SPAP_OUT_OF_BUFFERS
13255 SPAP_TIMEOUT_WHILE_WAITING_RESPONSE
13256 SPAP_UNEXPECTED_BC_REPLY
13257 SPAP_BROADCAST_FAILURE
13258 SPAP_DATABASE_UPDATE_COMPLETED
17201 SPCP_TIMEOUT_WHILE_WAITING_CTS
17202 SPCP_CTS_LINE_FAILURE_WHILE_TRANSM
17203 SPCP_REDUNDANCY_ERRORS_IN_RESPONSE
17205 SPCP_TIMEOUT_WHILE_WAITING_RESPONSE
17211 SPPC_INVALID_ATTRIBUTE_VALUE
Node level:
14016 NETW_UNKNOWN_DESTINATION_DEVICE
14018 NETW_UNKNOWN_DEVICE_ATTRIBUTE
cpiSendSpaMessage
This function sends an ACP formatted message to SYS600 from SPA. Before using this
function, the message buffer must be reserved by using the function
cpiGetTransmissionBuffer and formatted by using some of the cpiPutXXXData functions
presented in Section 5.5.2 Data filling functions. (Notation XXX means that any function
of this type is available.)
int cpiSendSpaMessage(int DESTIN, int SOURCE, cpiMsgID ID, int TIMEOUT);
DESTIN Destination connection number
SOURCE Source SPA number
ID Message buffer identification
TIMEOUT Waiting time for the base system reply in milliseconds,
0-> no time-out supervision
51
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-2 : Invalid MsgID
cpiSendSpaBitStream3
This function updates a bitstream process object in the base system process database.
int cpiSendSpaBitStream3(int DESTIN, int SOURCE, int ADDR, int LEN, char STREAM[]
, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
ADDR Address of the process object
LEN Length of bitstream in bits
STREAM Array of bits stored on the char array (Bitstream begins
from bit 0 of first char)
STATUS Status code for data (0 = OK)
TIMEOUT Timeout in milliseconds
FLAGS Status flags of the pulse counter
Return values:
0 : OK
-7 : Buffer full, the length of the bit stream is too long
cpiSendSpaBitStream3WithTS
This function updates a bitstream process object in the base system process database.
Timestamp of the process object is updated with a given time.
int cpiSendSpaBitStream3(int DESTIN, int SOURCE, int ADDR, int LEN, char STREAM[]
, int STATUS, cpiTime TS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
ADDR Address of the process object
LEN Length of bitstream in bits
STREAM Array of bits stored on the char array (Bitstream begins
from bit 0 of first char)
STATUS Status code for data (0 = OK)
TS Timestamp
TIMEOUT Timeout in milliseconds
FLAGS Status flags of the pulse counter
Return values:
0 : OK
-7 : Buffer full, the length of the bit stream is too long
cpiSendBufferedSpaIndicationWithTS
This function sends an indication value with timestamp to the base system process
database. The indication is marked with BE_SUBITEM, which can be used to indicate
that the data has been buffered in the application.
52
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
cpiSendSpaBufferedIndicationBlockWithTS
This function sends an indication value block with timestamp to the base system process
database. The indication is marked with BE_SUBITEM, which can be used to indicate
that the data has been buffered in the application.
int cpiSendSpaBufferedIndicationBlockWithTS(int DESTIN, int SOURCE, int BLOCK,
int BVAL, cpiTime TS, int STATUS, int TIMEOUT, cpiMsgID *ID);
DESTIN Destination connection number
SOURCE Source SPA number
BLOCK Object address of process object
BVAL 16 bit value
TS Timestamp
TIMEOUT Timeout in ms;
STATUS Status code for data (0= ok)
Return values:
0 : OK
-7 : buffer full, the filling of the ACP message failed
-13 : cannot get buffer for transmission message
-20 : connection waiting
-The sending failed because the reply to the previously
sent message has not been received
-22 : Invalid value
53
SYS600 9.4 MicroSCADA Pro 1MRS758104
messages with them also for special purposes, usually when the functions needed do not
exist. This can occur, for example, when several analog values need to be sent in a single
message.
Before any of the following packet building functions can be called, the buffer where
the message is going to be built up must be reserved by using the
cpiGetTransmissionBuffer function.
In order to be able to emulate a conventional NET unit operation, the following functions
can be freely used for setting the logical destination and source.
Table 5.8: Message header source
Function Description
cpiPutSource Sets the logical source of the message.
cpiPutDestination Sets the logical destination of the message.
cpiPutSource
With this function the logical source of the message can be set.
int cpiPutSource(cpiMsgID id, int SOURCE)
SOURCE SOURCE Source logical device, the following macro should
be used to calculate the value LOGICAL_ADDRESS(device-
Type, deviceNumber)
Example:
;Setting the logical source for NET1:
cpiPutSource(id, LOGICAL_ADDRESS(NET_DEVICE,1));
Return values:
0 : OK
-5 : Unknown Message ID
cpiPutDestination
With this function the logical destination of the message can be set.
int cpiPutDestination(cpiMsgID id, int DESTINATION)
DESTINATION Destination logical device, the following macro should
be used to calculate the value LOGICAL_ADDRESS(device-
Type,deviceNumber)
Example:
;Setting the logical destination for APL1:
cpiPutSource(id, LOGICAL_ADDRESS(APL_DEVICE,1));
Return values:
0 : OK
-5 : Unknown Message ID
54
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
The ACP message can be filled with the process data by using the following functions.
Table 5.9: Data filling functions
Function Description
cpiPutData Puts data to the ACP message.
cpiPutRtuData Puts the process data with status to the ACP
message.
cpiPutRtuDataWithoutStatus Puts the process data without status to the ACP
message.
cpiPutRtuDataWithTS Puts the process data with timestamp to the
ACP message.
The object type determines also the type of the value. If the
object type is 0=NO_OBJECT_TYPE, the type of the value
is free.
cpiPutData
Puts data to the ACP message (See Table 5.1 and file cpi.h).
int cpiPutData(cpiMsgID id, cpiData *data)
cpiPutRtuData
This function adds the process data with status to the ACP message.
int cpiPutRtuData (cpiMsgID ID, cpiObjectType OT, int BLOCK, cpiData VAL, int
STATUS);
ID Identification number for message
OT Object type of RTU process object
BLOCK Object address of RTU process object
(1 ... 255)
VAL Value for process object
TS Time stamp
STATUS Status code
0 -> OK
Return values:
0 : OK
-2 : Invalid MsgID
-7 : Message buffer is full, adding the data has not suc-
ceeded
cpiPutRtuDataWithoutStatus
This function adds the process data without status to the ACP message.
int cpiPutRtuDataWithoutStatus(cpiMsgID ID, cpiObjectType OT, int BLOCK, cpiData
VAL);
55
SYS600 9.4 MicroSCADA Pro 1MRS758104
Return values:
0 : OK
-2 : Invalid MsgID
-7 : Message buffer is full, adding the data has not suc-
ceeded
cpiPutRtuDataWithTS
This function adds the process data with timestamp to the ACP message.
int cpiPutRtuDataWithTS (cpiMsgID ID, cpiObjectType OT, int BLOCK, cpiData VAL,
cpiTime TS, int STATUS);
ID Identification number for message
OT Object type of RTU process object
BLOCK Object address of RTU process object
(1 ... 255)
VAL Value for process object
TS Time stamp
STATUS Status code
0 -> OK
Return values:
0 : OK
-2 : Invalid MsgID
-7 : Message buffer is full, adding the data has not suc-
ceeded
cpiPutReplyStatus
The following function adds the status of the reply to the reply message. If the reply
status is OK, there is no need to use this function.
int cpiPutReplyStatus (cpiMsgID ID, int STATUS);
ID Identification number for message
STATUS Status code
56
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-2 : invalid MsgID
The following functions are used to read the header information of the received message.
See also Section 3.4 Application Communication Protocol (ACP).
Table 5.11: Message header information
Function Description
cpiGetDestination Reads the station address of the destination node from
the message (CPI application node).
cpiGetSource Reads the station address of the source node from the
message (SYS600 node).
cpiGetRtuNo Reads the station number from the message.
cpiGetAttribute Reads the attribute from the message.
cpiGetIndex Reads the index from the message.
cpiGetReplyStatus Reads the reply status of the message.
cpiGetReplyDefinition Reads the reply definition of the message.
cpiGetMessageType Reads the type of the incoming message.
cpiGetMessageLength Reads the length of the received message.
cpiGetDeviceType Retrieves the logical device type message.
cpiGetDeviceNumber Retrieves the logical device number message.
cpiGetDestination
This function reads the station address of the destination node from the message (CPI
application node).
int cpiGetDestination( cpiMsgID ID, int *DESTIN);
ID Identification number for the message
DESTIN The CPI application node station address
Return values:
0 : OK
-5 : Invalid message buffer
57
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiGetSource
This function reads the station address of the source node from the message (SYS600
node).
int cpiGetSource( cpiMsgID ID, int *SOURCE);
ID Identification number for the message
SOURCE Station address of the source
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetRtuNo
This function checks which RTU station the message is meant to.
int cpiGetRtuNo(cpiMsgID ID, int *RTU);
ID Identification number for the message
RTU number
RTU RTU number
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetAttribute
This function reads the attribute of the message.
int cpiGetAttribute( cpiMsgID ID, char *ATTRIBUTE);
ID Identification number for the message
ATTRIBUTE Attribute of the message
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetIndex
This function reads the index of the message.
int cpiGetIndex( cpiMsgID ID, int *FIRST, int *LAST);
ID Identification number for the message
FIRST First index of the message
LAST Last index of the message
Return values:
0 : OK
-5 : Invalid message buffer
58
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
cpiGetReplyStatus
This function reads the reply status of the message.
int cpiGetReplyStatus( cpiMsgID ID, cpiMsgID *REPLYID, int *STATUS);
ID Identification number for the message
REPLYID Id of the reply message, which is a response for the
sent message
STATUS Status of the reply
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetReplyDefinition
This function reads the reply definition of the message.
int cpiGetReplyDefinition(cpiMsgID ID, cpiMsgHeader *HEADER);
ID Identification number for the message
HEADER Header information of the message
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetMessageType
This function reads the type of the message.
int cpiGetMessageType (cpiMsgID ID, int *MSGTYPE); 1=write, 2=read, 3=reply, 4=
notification
ID Identification number for the message
MSGTYPE Type of the incoming message
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetMessageLength
This function reads the length of the message.
int cpiGetMessageLength (cpiMsgID ID, int *LENGTH);
ID identification number for the message
LENGTH Length of the received message (the whole ACP message)
Return values:
0 : OK
-5 : Invalid message buffer
cpiGetDeviceType
A new function will be implemented to retrieve the logical device type message.
59
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiGetDeviceNumber
A new function will be implemented to retrieve the logical number message.
int cpiGetDeviceNumber(cpiMsgID *msg, int *deviceNumber)
Return values:
0 : OK
-1 : If fails
The data part of the message can be read with the following functions.
Table 5.12: Data scanning functions
Function Description
cpiGetNextData Reads the next data item from the received
message.
cpiGetNextDataType Reads the type of the next item in the message.
cpiGetNextS32Data Reads the next item from the message.
cpiGetTimeData Retrieves the time information from the message
written in RTU_ATIME format.
cpiGetNextData
The following function reads the next data item from the received message. The function
is used to read items one by one from the message to the cpiData structure. The function
returns the value of the same type as the values in the message. Because the type of data
may vary between messages, the type information of cpiData must be used when the
data of the message is used by the CPI application program.
int cpiGetNextData (cpiMsgID ID, cpiData *VAL);
VAL Value (structure!)
Return values:
0 : OK
-1 : Connection error, the reading of the next item from
the message has failed.
More detailed information can be read from the global
variable cpi_errno. The explanations for cpi_errno values
can be read from the Status Codes manual.
-2 :Invalid MsgID
60
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
cpiGetNextDataType
This function reads the type of the next item in the message. The function does not
remove the item from the message.
int cpiGetNextDataType (cpiMsgID ID, cpiDataType *VAL);
VAL Value
Return values:
0 : OK
-1 : Connection error, the reading of the next item from
the message has failed for some reason.
More detailed information can be read from the global
variable cpi_errno. The explanation for cpi_errno values
can be read from the Status Codes manual.
-2 : Invalid MsgID
-10 : No data items left in the buffer
cpiGetNextS32Data
The following function reads the next item from the message. The item is converted to
the long type. The items of the binary type cannot be read by using this function.
int cpiGetNextS32Data (cpiMsgID ID, long *VAL);
VAL VAL Value
Return values:
0 : OK
-1 : Connection error, the reading of the next item from
the message has failed for some reason.
More detailed information can be read from the global
variable cpi_errno. The explanation for cpi_errno values
can be read from the Status Codes manual.
-2 : Invalid MsgID
-10 : No data items left in the buffer
cpiGetTimeData
This function can be used to retrieve time information from the message written in
RTU_ATIME format.
int cpiGetTimeData(cpiMsg *msg, cpiTime *time);
Return values:
0 if ok
-1 if fails
61
SYS600 9.4 MicroSCADA Pro 1MRS758104
This function can be used to read command data from the message.
Table 5.13: Data scanning functions
Function Description
cpiGetNextAddrData Reads the next Address Type item from the
message
cpiGetNextAddrData
The following function reads the next Address Type item from the message. This can
be used for unpacking the process commands from SYS600, which are sent via the
process database. All of the commands that are sent via the SYS600 process database
use the DA attribute and the Address Type data item. The data is divided into three parts:
object type, object address and object value.
int cpiGetNextAddrData (cpiMsgID ID, cpiData *VAL);
VAL Value (structure!)
Return values:
0 : OK : OK
-1 : : Connection error, the reading of the next item from
the message has failed.
More detailed information can be read from the global
variable cpi_errno. The explanations for cpi_errno values
can be read from the Status Codes manual.
-2 : Invalid MsgID
-10 : No data items left in the buffer
Example of use:
cpiGetAttribute(id, AT);
if (!strcmp(AT,"DA"))
/* compare AT to see if it is DA = command via process database*/
{
i = 0;
printf("DA message received \n");
while(cpiGetNextAddrData (id, &data) == 0) {
printf(" OT = %d", data.value.ADDR.ObjectType );
printf(" OA = %d", data.value.ADDR.ObjectAddress);
printf(" OV = %d\n", data.value.ADDR.ObjectValue);
switch(data.value.ADDR.ObjectType) {
case cpiOBJECT_COMMAND:
printf("Object Command received\n");
switch(data.value.ADDR.ObjectValue) {
case 0: printf("IMMEDIATE COMMAND OFF \n"); break;
case 1: printf("IMMEDIATE COMMAND ON \n"); break;
case 16: printf("INHIBIT COMMAND \n"); break;
case 17: printf("CHECK BACK COMMAND \n"); break;
case 32: printf("EXECUTE COMMAND OFF \n"); break;
62
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
The (byte) value received when a command is activated is byte coded as shown in
Table 5.14 (see also the example of use in Section 5.6.3.1 General handling):
Table 5.14: The received values and descriptions
Object Command Status High Nibble Value Low Nibble Value
IMMEDIATE COMMAND 0
ON 1
OFF 0
CHECK BACK COMMAND 1
INHIBIT 0
CHECK 1
BACK
EXECUTE COMMAND 2
ON 1
OFF 0
The value of the analog setpoint is stored into the ObjectValue field of the cpiData
structure.
63
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiConnectionStatus
This function checks the status of an application connection. It also returns the status
code of the last reply message, if it is rejected by the base system.
int cpiConnectionStatus (int DESTIN);
DESTIN Connection number of the destination
Return values:
0 : OK
1 : Waiting connection
others : Refer to the Status Codes manual
cpiGetTransmissionBuffer
This function reserves a buffer for transmission. The function returns with an error status
if the transmission queue is full or if the failed transmission queue contains messages.
The length of the transmission queue is 1 in this version, so the previously sent message
must get a reply from the base system before a new buffer can be reserved.
int cpiGetTransmissionBuffer(int CON, cpiMsgID *ID);
CON Connection number of the destination
ID Id for a message buffer
Return values:
0 : OK
-13 : No buffers left
-20 : Connection is still waiting for a reply for the previ-
ously sent message
cpiGetReplyBuffer
This function reserves a buffer for a reply message transmission. It is used when it is
possible to send the reply message back to the base system immediately.
int cpiGetReplyBuffer(cpiMsgID RQ, cpiMsgID *ID);
RQ Id of the message which is a response for the sent mes-
sage
64
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-13 : No buffers left
-15 : Invalid source ID
cpiGetDefinedReplyBuffer
This function reserves a buffer for a reply message. It is used when the reply message
cannot immediately be sent back to the base system.
int cpiGetDefinedReplyBuffer(cpiMsgHeader *HEADER, cpiMsgID *ID);
HEADER Header data of the message to which this message is a
reply
ID Id for a reply message
Return values:
0 : OK
-13 : no buffers left
cpiGetNotificationBuffer
This function reserves a buffer for a notification message. It is used to send system status
messages to the base system.
int cpiGetNotificationBuffer(int CON, cpiMsgID *ID);
CON Destination connection
ID Id for reply message
Return values:
0 : OK
-13 : No buffers left
5.9 Initializations
Table 5.18: Initializations
Function Description
cpiInitThisNode Initialises data of this node.
cpiInitRemoteNode Gives information of the SYS600 node to CPI.
cpiCreateConnection Creates a connection and starts the communic-
ation between CPI and SYS600.
cpiCloseConnection Removes the connection between CPI and
SYS600.
These functions initialize the TCP/IP connections between the SYS600 applications and
the CPI application program. Figure 5.1 explains what kind of initialization is needed
when connecting CPI to SYS600.
65
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiInitThisNode(202, 2);
cpiInitRemoteNode(basesystem, 209, 9);
cpiCreateConnection(9, 1, &con1);
cpiCreateConnection(9, 5, &con2);
CPI sends an analog value from RTU2 to application 1 by using the following function:
cpiSendAnalogValue(con1, 2, block, val, status, &ID);
cpiInitThisNode
This function initializes the data of this node.
int cpiInitThisNode(cpiNodeAddress SA, cpiNodeNumber NA);
SA Node address of this socket (1...254).
NA Node number of this socket (1...250)
Return values:
0 : OK
-26 : Invalid data
cpiInitRemoteNode
This function gives information of the SYS600 node to CPI.
int cpiInitRemoteNode(cpiTCPIPAddress TA, cpiNodeAddress NA, cpiNodeNumber NN);
TA SYS600 TCP/IP address
66
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Return values:
0 : OK
-1 : Connection error
-8 : Invalid address
-14 : Invalid node
-17 : Invalid tcp address
cpiCreateConnection
This function creates a connection and starts the communication between CPI and
SYS600.
int cpiCreateConnection( cpiNodeNumber NN, int AN, int *CN,);
NN Node number of SYS600
AN Application number in SYS600, where this connection is
created.
CN Connection number. This return value is used as a destin-
ation number when sending messages to SYS600.
Return values:
0 : OK
-1 : Connection error
-14 : Invalid node number
cpiCloseConnection
This function removes the connection between CPI and SYS600.
int cpiCloseConnection(int CN);
CN Connection number
Return values:
0 : OK
-1 : Connection error, invalid connection number
67
SYS600 9.4 MicroSCADA Pro 1MRS758104
cpiSET
This function sets one bit in the bit set.
int cpiSET(int BIT, cpiBitSet *BITSET)
BIT A number of bit which is set to 1, (0 = first bit)
BITSET Bitmask to use with cpiSelect
Return values:
0 : If the tested bit does not belong to the bitset
1 : If the tested bit belongs to the bitset
cpiCLR
This function clears one bit from the bit set.
int cpiCLR(int BIT, cpiBitSet *BITSET)
BIT A number of bit which is cleared to 0, (0 = first bit)
BITSET Bitmask to use with cpiSelect
Return values:
0 : If the tested bit does not belong to the bitset
1 : If the tested bit belongs to the bitset
cpiISSET
This function checks the value of one bit and then returns it.
int cpiISSET(int BIT, cpiBitSet *BITSET)
BIT A number of bit whose state is tested
BITSET Tested bit mask
Return values:
0 : If the tested bit does not belong to the bitset
1 : If the tested bit belongs to the bitset
68
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
This chapter provides instructions on how to provide support for the CPI communication
protocol configuration in the System Configuration Tool.
Definitions:
• Configuration attribute: a value that is stored into the permanent protocol
configuration file by the System Configuration Tool. This value is later utilised
when the CPI application protocol is started in SYS600.
• Attribute definitions: the information about all the CPI configuration attributes. It
includes names, data types, data structures, description texts, help texts and
description texts for different attribute values of all CPI configuration attributes to
be used by the System Configuration Tool.
6.1 Functionality
The included CPI protocols are recognised from the SYS600 computer in System
Configuration Tool based on following requirement:
Under \sc\prog folder, each sub-folder is assumed to be named according to the CPI
application program, if
• it includes the permanent protocol configuration file named Config.ini.
• it includes the attribute definitions file named Attr_Def.scl.
• it includes the attribute mappings file named Attr_Map.ini.
The station type to be attached into the CPI protocol communication line is either RTU
or SPA.
The CPI application program, i.e. the executable file, may either exist in the same
computer where the System Configuration Tool is running or on an external computer.
However, the permanent protocol configuration file, attribute definitions and mappings
files need to exist in a sub-folder under the \sc\prog folder on the same computer where
the System Configuration Tool is being used. If the CPI application program is running
on an external computer, one of its drives can be mapped through LAN to the computer
69
SYS600 9.4 MicroSCADA Pro 1MRS758104
in which SYS600 is running. Through this kind of drive mapping, the files for configuring
CPI application program are located only in the SYS600 computer. The protocol to be
used for the CPI application program is concluded from the sub-folder name under the
\sc\prog folder.
Figure 6.1 shows the MODBUS SLAVE communication protocol included in system
configuration. The folder \sc\prog\modbus_slave exists in SYS600 computer, where the
System Configuration Tool is located. The name of the protocol is displayed as MODBUS
SLAVE in the object tree (the included underscore character is removed and the sub-folder
name is uppercased).
Figure 6.1: The CPI protocol in the Object Tree of the System Configuration Tool
The permanent protocol configuration file must be named Config.ini. This file contains
the configuration parameters to be used by the CPI application program. The format of
this file follows the Windows Initialisation File Format specification. Those parameters,
which are shown and configured in the System Configuration Tool as a property of the
CPI communication line, should be included under the section name Configuration.
The attribute definitions file must be named Attr_Def.scl. This file contains e.g. limit
values and descriptions for the configuration parameters to be used by the System
Configuration Tool. The format of the file follows the SCIL syntax.
70
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
[Section_name_m]
key_name_1=key value 1
key_name_2=key value 2
…
key_name_n=key name n
The key name is the same as the attribute name in the Attribute definitions file
Attr_Def.scl.
Example of Config.ini
[Configuration]
own_node_number=4
own_station_number=204
base_system_node_number=9
base_system_station_number=209
tcp_ip_address=194.142.148.36
application_number=1
communication_port_name=COM1
baud_rate=9600
parity=0
stop_bit_count=0
data_bit_count=8
flow_control=0
The name of the attribute is unique for all the CPI configuration attributes. All spaces
must be replaced with the underscore character. For example, the attribute TCP/IP
Address is presented as TCP_IP_ADDRESS as valid CPI attribute name for the System
Configuration Tool.
Possible data types for the attributes are:
• Integer
• Real
• Text
• Time
• Boolean
If an attribute is modifiable, the value is TRUE. Otherwise the attribute value is FALSE.
If the attribute is defined to be modifiable, its value can be edited in the edit area of the
System Configuration Tool. If the attribute is non-modifiable, the editing of the attribute
is disabled in the edit area of the System Configuration Tool. Figure 6.2 shows the
71
SYS600 9.4 MicroSCADA Pro 1MRS758104
Attribute Tree of the System Configuration Tool, where all the CPI attributes are included
in the View named All Attributes and under a group name CPI Configuration Attributes.
Figure 6.2: The Attribute Tree and Edit area of the System Configuration Tool
The Attribute Tree uses descriptive text. When a CPI attribute has been selected in the
object tree, the Status bar (in Figure 6.3) displays the help text at the bottom of the System
Configuration Tool.
A default value is utilised for an attribute, when the CPI application protocol is added
into the System Configuration Tool. It is possible for to change the attribute value
according to its attribute definitions by using the edit area.
72
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Default_value INTEGER 3
Help_text TEXT "This is an example of an integer attrib-
ute."
73
SYS600 9.4 MicroSCADA Pro 1MRS758104
* The VECTOR data type can be recognised from the parentheses around the enumerated
INTEGER or TEXT values. If only one item is included in the VECTOR, there is a need
to specifically use the VECTOR statement around the attribute value, VECTOR(1)
** The PACK_STR is a SCIL function, which can be used to convert the year/month/day
and hour/minute/seconds representation to the TIME data type format of SCIL. E.g.
PACK_STR(YEAR, MONTH, DAY,HOUR,MINUTE,SECOND).
Example of Attr_Def.scl
#create GL_ATTRIBUTES:V = LIST(-
OWN_NODE_NUMBER = LIST(-
data_type=”INTEGER”,-
min_value=1,-
max_value=99,-
modifiable=TRUE,-
descriptive_text=”Own Node Number”,-
default_value=4,-
help_text=”Specifies the own node number to be
used in CPI application program.”),-
OWN_STATION_NUMBER = LIST(-
data_type=”INTEGER”,-
min_value=1,-
max_value=255,-
modifiable=TRUE,-
descriptive_text=”Own Station Number”,-
default_value=204,-
help_text=”Specifies the own station number to
be used in CPI application program.”),-
BASE_SYSTEM_NODE_NUMBER = LIST(-
data_type=”INTEGER”,-
min_value=1,-
max_value=99,-
modifiable=TRUE,-
descriptive_text=”Base System Node Number”,-
default_value=9,-
help_text=”Specifies the base system node number
to be used in CPI application program.”),-
BASE_SYSTEM_STATION_NUMBER = LIST(-
data_type=”INTEGER”,-
min_value=1,-
max_value=255,-
modifiable=TRUE,-
descriptive_text=”Base System Station Number”,-
74
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
default_value=209,-
help_text=”Specifies the base system station
number to be used in CPI application program.”),-
TCP_IP_ADDRESS = LIST(-
data_type=”TEXT”,-
min_length=7,-
max_length=15,-
modifiable=TRUE,-
descriptive_text=”TCP/IP Address”,-
default_value=”192.142.148.36”,-
help_text=”Specifies the TCP/IP address to be
used in CPI application program.”),-
APPLICATION_NUMBER = LIST(-
data_type=”INTEGER”,-
min_value=1,-
max_value=99,-
modifiable=TRUE,-
descriptive_text=”Application Number”,-
default_value=1,-
help_text=”Specifies the application number,
where CPI application program is running.”),-
COMMUNICATION_PORT_NAME = LIST(-
data_type=”TEXT”,-
min_length=4,-
max_length=5,-
modifiable=TRUE,-
descriptive_text=”Communication Port Name”,-
default_value=”COM1”,-
help_text=”Specifies the communication port
name, which CPI application program is
utilising.”))
#return %GL_ATTRIBUTES
The format of this file needs to follow the SCIL syntax. There
is always a risk that due to a typing error the Attr_Def.scl file
is not applicable to the SCIL syntax. In the SCIL Editor, it is
possible to define the Syntax Check mechanism into use
automatically during the saving operation by selecting Options
– Check Syntax at Save. Therefore, the editing this file should
be done by using the SCIL Editor.
75
SYS600 9.4 MicroSCADA Pro 1MRS758104
The key name in this file is the same as the attribute name in the attribute definitions
file, as well as the key name in the permanent protocol configuration file. The key value
in this file represents the two-char attribute name to be used for defining the property to
the SYS600 object.
For example, if a key name own_station_number with a key value SA exists inside the
NODE section, it means that the configuration attribute is referenced to the NOD’n’:BSA
attribute in SYS600, where ’n’ equals the node number object.
Example Attr_Map.ini
[NODE]
own_station_number=SA
[NODE_LINK]
communication_port_name=SD
baud_rate=BR
stop_bit_count=SB
[STATION]
in_use=IU
76
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
7 Terminology
Term Description
Application Communic- An internal protocol of SYS600 that is generally used in communication
ation Protocol (ACP) between the SYS600 nodes.
ACP Message Communication between the SYS600 nodes is implemented by using
ACP. It supports three types of message dialogs: write commands, read
commands and notifications.
Attribute Individual data items that form a part of an object are called attributes.
Each object has a set of attributes that store information and describe
the qualities of the object. Attributes contain, for example measured
values, texts, program lines, time stamps etc. depending on the object
type.
Base System The Base System offers services to the applications. It provides database
structures, database handling mechanisms and file handling functionality.
The Base System also offers an application programming interface for
attaching functions as separate programs.
BSD Socket Socket interface defined in the Unix version developed by Berkeley
Software.
Communication Pro- Protocol environment software that is used for externally implemented
gramming Interface protocol converters. The CPI Library is a collection of functions for
(CPI) and CPI Library sending and receiving message to or from the SYS600 base system, as
well as functions for packing and unpacking data of messages.
CPI Application Pro- In some cases called a Gateway program.
gram An application program made by using the CPI interface exchanges data
between SYS600 and a foreign system. It emulates the NET containing
stations of the RTU, SPA or SPI device type.
Communication Sys- Handles the data transmission in the SYS600 system as well as between
tem the devices. The communication can be divided into upper level commu-
nication and process communication.
Local Area Network Used for upper level communication between the base system and
workplaces. It has a large capacity for data transmission.
Message Buffer A place in the memory to store the ACP messages to or from the SYS600
base system. The CPI Buffer Management functions reserve buffers for
different message types.
NET SYS600 communication unit.
NET Emulation A CPI application program that resembles the behaviour of the NET unit.
Node Communication object in SYS600, for example, the SYS600 base system
or a CPI application program.
Node Number A unique identifier of a node.
Open System Connec- A model for network architecture standardised by ISO.
tion (OSI)
Protocol A protocol is a set of rules and conventions for transmitting information
in the network. They govern the content, format, timing, sequencing and
error control of messages.
RTU Remote Terminal Unit
77
SYS600 9.4 MicroSCADA Pro 1MRS758104
78
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
8 Abbreviations
Abbreviation Description
ACP Application Communication Protocol
Communication Pro- Communication Programming Interface, a protocol environment software
gramming Interface that is used for externally implemented protocol converters. The CPI
(CPI) and CPI Library Library is a collection of functions for sending and receiving message to
or from the SYS600 base system, as well as functions for packing and
unpacking data of messages.
ISO International Standards Organization
LAN Local Area Network
OSI Open System Interconnection
RTU Remote Terminal Unit
SCIL Supervisory Control Implementation Language
TCP/IP Transmission Control Protocol/Internet Protocol
79
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
Index
A
ACP .................................................... 13, 28, 77, 79
ACP-OSI ................................................... 15, 77, 79
ACP protocol messages ........................... 14–15, 77
Analog setpoint ..................................................... 23
Application Communication Protocol .................... 13
Application Programming ............................... 22, 24
Attr_Def.scl ........................................................... 70
Attr_Map.ini .......................................................... 69
Attribute definitions ............................................... 69
Attributes ........................................................ 17, 77
Attribute Tree ........................................................ 72
B
Base system ......................................................... 77
Base System Configuration ...................... 18, 22, 24
Base System Node Object ................................... 75
Bit position ............................................................ 29
Boolean ................................................................ 72
BSD socket ....................................................... 8, 77
C
Cause of exception ............................................... 29
Communication
attributes ........................................................... 15
system .............................................................. 77
Communication Line Object ................................. 75
Communication Station Object ............................. 75
Config.ini ............................................................... 70
Configuration attributes .................................. 14, 69
Connections
CPI application program as a master ............... 22
CPI application program as a slave .................. 24
Connection status ................................................. 29
Converting messages ..................................... 23, 25
CPI ........................................................................ 79
CPI_EXAMPLE .............................................. 23, 25
CPI application program ....................................... 77
81
SYS600 9.4 MicroSCADA Pro 1MRS758104
82
1MRS758104 MicroSCADA Pro SYS600 9.4
Issued: 16.5.2014 Communication Programming Interface (CPI)
Version: A/16.5.2014
User’s Guide
G P
Gateway program ............................................. 7, 77 Packet
General persistent output ..................................... 23 building ............................................................. 53
GetDeviceNumber ................................................ 60 unpacking ......................................................... 57
Program files ........................................................ 27
I Protocol .......................................................... 21, 77
Protocol Converter ............................................... 21
Implementation of the foreign protocol ................. 23 Protocol Implementation ....................................... 25
Infinite loop ........................................................... 11
Integer .................................................................. 72 R
K RD connection ...................................................... 29
Read commands .................................................. 14
Key name ....................................................... 71, 76 Real ...................................................................... 72
Regulation command ........................................... 23
L Reserved attributes .............................................. 17
Revision ................................................................ 69
LAN ................................................................... 8, 77 Routing ................................................................. 15
Location of files ..................................................... 70 RP 570 slave device ............................................. 23
Low level message routing ................................... 15 RTU Object Model ................................................ 37
RTU station ......................................... 18, 69, 77, 79
M
S
Memory management .......................................... 13
Message SCIL .......................................................... 14, 78–79
buffers ........................................................ 13, 77 SPA device ..................................................... 69, 78
conversion .................................................. 23, 25 Status Bar ............................................................. 72
dialogues .......................................................... 14 Status codes
failure types ...................................................... 17 RTU .................................................................. 38
Modbus Slave ....................................................... 70 SPA ................................................................... 50
SYS_BASCON.COM ............................................ 18
N System Configuration Tool ............................. 69, 78
System Start-Up ................................................... 69
Naming of files ...................................................... 70
NET ................................................................. 11, 77 T
NET emulation ................................................ 11, 77
Node ................................................... 13, 22, 57, 77 TCP/IP .................................................. 8, 29, 78–79
Node number ........................................................ 77 Text ....................................................................... 72
Notifications .......................................................... 14 Thread ............................................................ 23, 78
Time ...................................................................... 72
O Transmission error handling ................................. 17
Type definitions .................................................... 27
Object command .................................................. 23
Object type of command ...................................... 23 W
OSI ....................................................................... 15
WR connection ..................................................... 29
Write commands ................................................... 14
83
Contact us
www.abb.com/substationautomation