TMW .NETProtocol Components User Manual
TMW .NETProtocol Components User Manual
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Property of Triangle MicroWorks, Inc. This Documentation and its associated distribution media contain proprietary information of Triangle MicroWorks, Inc. and may not be copied or distributed in any form without the written permission of Triangle MicroWorks, Inc. Copies of the source code may be made only for backup purposes.
Page ii
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Chapter 1 Introduction .........................................................................................................1 1.1 Supported Protocols ...................................................................................................1 1.2 Manual Overview.......................................................................................................2 1.3 Manual Conventions and Abbreviations....................................................................3 Chapter 2 Quick Start Guide................................................................................................5 2.1 Quick Start Guide for TMW .NET Protocol Components ........................................5 2.2 Install the TMW .NET Protocol Components ...........................................................5 2.2.1 Included Samples ................................................................................................6 2.3 Create Interoperability Guide ....................................................................................8 2.4 Build the TMW .NET Protocol Components and Samples .......................................9 2.5 Common TMW .NET Protocol Components Setup ..................................................9 2.5.1 Licensing.............................................................................................................9 2.5.2 Application Initialization ..................................................................................10 2.5.3 Database Initialization ......................................................................................11 2.6 TMW .NET Protocol Components Target...............................................................11 2.7 Manage Channels, Sessions, and Sectors ................................................................11 2.8 Install the TMW .NET Protocol Components .........................................................11 2.9 The TMW .NET Protocol Components Database ...................................................12 2.10 Issue Commands (Master Sessions).......................................................................14 2.11 Add Support for Change Events (Slave Sessions).................................................15 2.12 Test your Implementation ......................................................................................15 Chapter 3 Overview ...........................................................................................................19 3.1 Coding Conventions.................................................................................................19 3.2 Architecture..............................................................................................................19 3.2.1 Layers................................................................................................................19 3.2.2 Data Model........................................................................................................21 3.2.3 Channels............................................................................................................21 3.2.4 Sessions.............................................................................................................22 3.2.5 Sectors...............................................................................................................22 3.2.6 Data Points ........................................................................................................23 3.2.7 Target Interface.................................................................................................27 3.2.8 Database Interface.............................................................................................27 3.2.9 Application Interface ........................................................................................27 3.2.10 Diagnostics......................................................................................................29 3.2.11 Condition Notification and Statistics ..............................................................31 3.2.12 Asynchronous Database Updates....................................................................31 3.3 Master Overview......................................................................................................32 3.3.1 Architecture.......................................................................................................32 3.3.2 Supporting Redundant Communication Paths ..................................................33 3.4 Slave Overview........................................................................................................35 3.4.1 Architecture.......................................................................................................35 3.4.2 Supporting Redundant Communication Paths ..................................................35 Chapter 4 TMW .NET Protocol Components Source Code Version ................................37 4.1 Unpacking and Installing .........................................................................................37 4.1.1 Installation.........................................................................................................37 TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011 Page iii
4.2 Building....................................................................................................................37 4.3 Channels, Sessions, and Sectors ..............................................................................37 4.4 Database...................................................................................................................38 4.5 Master Libraries .......................................................................................................38 4.5.1 Issuing Commands............................................................................................38 4.6 Slave Libraries .........................................................................................................38 4.6.1 Supporting Change Events................................................................................38 4.7 Testing your Implementation...................................................................................38 Chapter 5 Advanced Topics...............................................................................................39 5.1 Supporting Multiple Protocols.................................................................................39 5.2 60870-5-104 Redundancy........................................................................................39 5.3 DNP3 Data Sets .......................................................................................................40 5.4 IEC 60870-5-101/4 Control Points ..........................................................................41 5.5 60870-5-101/4 Time Stamps....................................................................................41 5.6 SSL or TLS over TCP/IP .........................................................................................42 5.7 Installation on Target PCs........................................................................................46 Chapter 6 Debugging and Testing your Implementation...................................................49 6.1 Testing Basic Communications ...............................................................................49 6.2 Testing Multiple Channels, Sessions, and Sectors...................................................50 6.3 Testing the Database Interface.................................................................................50 6.4 Testing Event Generation ........................................................................................50 6.5 Testing Commands ..................................................................................................50 6.6 Regression Testing...................................................................................................50
Page iv
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Chapter 1 Introduction
Congratulations on your purchase of a Triangle MicroWorks, Inc. (TMW) .NET Communications Protocol Component (.NET.SCL). This product is a member of a family of communication protocol libraries supported by Triangle MicroWorks, Inc. This library was designed to be flexible, easy to use, and is available for the development of communications applications on the Microsoft .NET framework. For these reasons, the Triangle MicroWorks, Inc. .NET Communications Protocol Components will provide an excellent solution to your communication protocol requirements. This document is the user manual for all of the TMW .NET Communications Protocol Components. The manual begins with generic information pertinent to all of the TMW .NET Communications Protocol Components and gets more specific in later chapters. In addition, a help file documenting the classes available in the components and a Configuration and Interoperability (C-I) guide is included for each purchased protocol. This manual also contains sections specific to the Source Code versions of the TMW.NET Communications Protocol Components. The source code versions are available for purchase for each of the Protocol Components.
Please Note
Your license agreement limits the installation of this component to specific products. Before installing this component in a new target application, check your license agreement to verify that it allows use on that target application. Contact Triangle MicroWorks, Inc. for information about extending the number of target applications that may use this component.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
DNP3 MODBUS
dnp modbus
Each of the protocols listed above is available as a Master (Controlling Station), or Slave (Controlled Station) implementation. As shown in Figure 1, a typical substation topology consists of an off-site central station computer that polls one or more Remote Terminal Units (RTU) in the substation. In turn, each Master polls one or more Intelligent Electronic Devices (IED) that monitors and controls the substation. Figure 1 illustrates how Master and Slave Components might be used in a typical substation.
Central Station
Master Component
Slave Component
All of the TMW .NET Protocol Components share a common architecture, allowing them to be installed in any combination required. For example, it is straightforward to implement a device that supports DNP3 and IEC 60870-5-101. Combining protocols is discussed in detail in Section 5.1.
Chapter 3 provides an overview of the TMW .NET Protocol Components. Separate subsections describe Master-, Slave-, and Peer-specific details. Chapter 4 describes the specifics related to the Source Code version of TMW .NET Protocol Components. Separate subsections describe implementation issues for Master, Slave, and Peer libraries. Chapter 5 provides information on advanced topics. These topics are often library dependent. Chapter 6 provides guidelines and suggestions on debugging and testing your implementation. These guidelines are techniques that have proven useful in previous porting and development efforts.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 3
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 5
Page 6
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
2.2.1.2 I101
I101MasterGUI a Windows Forms application that implements a simple IEC 60870-5101 master I101SlaveGUI a Windows Forms application that implements a simple IEC 60870-5101 slave I101MasterDatabaseEvents shows how to use the event based model for an IEC 608705-101 master. I101SlaveDatabaseEvents shows how to use the event based model for an IEC 608705-101 slave.
2.2.1.3 I102
I102SlaveGUI a Windows Forms application that implements a simple IEC 60870-5102 slave I102MasterGUI a Windows Forms application that implements a simple IEC 60870-5102 master I102DatabaseEvents shows how to use the event based model for an IEC 60870-5-102 master and slave I102MasterDatabaseEvents shows how to use the event based model for an IEC 608705-102 master. I102SlaveDatabaseEvents shows how to use the event based model for an IEC 608705-102 slave. I103 I103SlaveGUI a Windows Forms application that implements a simple IEC 60870-5103 slave. I103MasterGUI a Windows Forms application that implements a simple IEC 60870-5103 master. I103DatabaseEvents shows how to use the event based model for an IEC 60870-5-103 master and slave. I103MasterDatabaseEvents shows how to use the event based model for an IEC 608705-103 master. I103SlaveDatabaseEvents shows how to use the event based model for an IEC 608705-103 slave. I104 TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011 Page 7
I104MasterGUI a Windows Forms application that implements a simple IEC 60870-5104 master I1104SlaveGUI a Windows Forms application that implements a simple IEC 60870-5104 slave I104RedundantMasterGUI a Windows Forms application that implements a simple IEC 60870-5-104 master with redundancy enabled. I104RedundantSlaveGUI a Windows Forms application that implements a simple IEC 60870-5-104 slave with redundancy enabled. I104MasterDatabaseEvents shows how to use the event based model for an IEC 608705-104 master. I104SlaveDatabaseEvents shows how to use the event based model for an IEC 608705-104 slave.
2.2.1.4 Modbus
MMBWebService a web service application that wraps a Modbus master as a web service. SMBSimulator a Windows Forms application that implements a simple Modbus slave that can be used with the MMBWebService sample. MBDatabaseEvents shows how to use the event based model for a Modbus master and slave. MBMasterDatabaseEvents shows how to use the event based model for a Modbus master. MBSlaveDatabaseEvents shows how to use the event based model for a Modbus slave
2.5.1 Licensing
When the TMW .NET Protocol Components are first installed on your machine they come with an initial Trial License. This license provides full functionality for a period of 21 days to evaluate the Protocol Components for purchase. During this trial period an application will only be allowed to run for 1 hour. Triangle MicroWorks provides three TMW .NET Protocol Components Licensing options beyond the free trial license. 1. Single Use License This is a license that is tied to a specific computer. 2. Redistributable License This form gives the developer the right to re-distribute the TMW .NET Protocol Components with a single application to run on an unlimited number of computers. 3. Redistributable with Source Code License This is similar to the Redistributable License except that Source code is provided to the developer.
from Triangle MicroWorks Inc. it is then installed on the target machine using this same tool. The tool is accessible from the Start menu under the Licensing item. No licensing changes need to be made to the startup code in the example files or in your own application. The software will detect the single use license and functionality based on that license will be allowed.
license
Page 10
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
TMWApplicationBuilder applBuilder = new TMWApplicationBuilder(); TMWApplication pAppl = TMWApplicationBuilder.getAppl(); pAppl.InitEventProcessor(); pAppl.EnableEventProcessor = true;
The property TMWApplication.LoopPeriod is used to specify the rate in milliseconds at which checks for data on a channel are performed.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 11
... masterChan = new DNPChannel(TMW_CHANNEL_OR_SESSION_TYPE.MASTER); masterChan.Type = WINIO_TYPE.TCP; masterChan.Name = ".NET DNP Master"; // name displayed in analyzer window masterChan.WinTCPipAddress = "127.0.0.1"; masterChan.WinTCPipPort = 20000; masterChan.WinTCPmode = TCP_MODE.CLIENT; masterChan.OpenChannel(); masterSesn = new MDNPSession(masterChan); masterSesn.AuthenticationEnabled = false; masterSesn.OpenSession(); ...
After opening the session it should be possible to test communications with a remote device. Note that the TMWApplication initialization code is not shown in this code segment, but should be performed as shown above.
Page 12
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
case 1: // Binary Input updateBinaryInput(simPoint); break; case 10: // Binary Output (CROB) updateBinaryOutput(simPoint); break; case 20: // Binary Counters updateBinCntr(simPoint); break; case 30: // Analog Inputs updateAnalogInput(simPoint); break; case 40: // Analog Output updateAnalogOutput(simPoint); break; default: protocolBuffer.Insert("Unknown point type in database update routine"); break; } } } ...
The 2nd database model disables the built in database and utilizes .NET events on the TMWSimDatabase and its derivations to notify the application of various protocol events. This mechanism provides a tighter integration to the protocol and leaves the management of protocol data to the application developer. This model is more appropriate when developing an application that provides its own database.
private static void OpenSlave() { slaveChan = new DNPChannel(TMW_CHANNEL_OR_SESSION_TYPE.SLAVE); slaveChan.Type = WINIO_TYPE.TCP; slaveChan.Name = ".NET DNP Slave"; /* name displayed in analyzer window */ slaveChan.WinTCPipAddress = "127.0.0.1"; slaveChan.WinTCPipPort = 20000; slaveChan.WinTCPmode = TCP_MODE.SERVER; slaveChan.OpenChannel(); slaveSesn = new SDNPSession(slaveChan); slaveSesn.UnsolAllowed = true; slaveSesn.OpenSession(); sdb = (SDNPDatabase)slaveSesn.SimDatabase; SDNPDatabase.UseSimDatabase = false; SDNPDatabase.UseSimControlDatabase = false; // binary inputs
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 13
sdb.BinInQuantityEvent += new SDNPDatabase.BinInQuantityDelegate(SlaveBinInQuantityEvent); sdb.BinInGetPointEvent += new SDNPDatabase.BinInGetPointDelegate(SlaveBinInGetPointEvent); SDNPDatabase.BinInReadEvent += new SDNPDatabase.BinInReadDelegate(SlaveBinInReadEvent); // analog inputs sdb.AnlgInQuantityEvent += new SDNPDatabase.AnlgInQuantityDelegate(SlaveAnlgInQuantityEvent); sdb.AnlgInGetPointEvent += new SDNPDatabase.AnlgInGetPointDelegate(SlaveAnlgInGetPointEvent); SDNPDatabase.AnlgInReadEvent += new SDNPDatabase.AnlgInReadDelegate(SlaveAnlgInReadEvent); // binary outputs sdb.BinOutQuantityEvent += new SDNPDatabase.BinOutQuantityDelegate(SlaveBinOutQuantityEvent); sdb.BinOutGetPointEvent += new SDNPDatabase.BinOutGetPointDelegate(SlaveBinOutGetPointEvent); SDNPDatabase.BinOutReadEvent += new SDNPDatabase.BinOutReadDelegate(SlaveBinOutReadEvent); SDNPDatabase.BinOutSelectEvent += new SDNPDatabase.BinOutSelectDelegate(SlaveBinOutSelectEvent); SDNPDatabase.BinOutOperateEvent += new SDNPDatabase.BinOutOperateDelegate(SlaveBinOutOperateEvent); // analog outputs sdb.AnlgOutQuantityEvent += new SDNPDatabase.AnlgOutQuantityDelegate(SlaveAnlgOutQuantityEvent); sdb.AnlgOutGetPointEvent += new SDNPDatabase.AnlgOutGetPointDelegate(SlaveAnlgOutGetPointEvent); SDNPDatabase.AnlgOutReadEvent += new SDNPDatabase.AnlgOutReadDelegate(SlaveAnlgOutReadEvent); SDNPDatabase.AnlgOutSelectEvent += new SDNPDatabase.AnlgOutSelectDelegate(SlaveAnlgOutSelectEvent); SDNPDatabase.AnlgOutOperateEvent += new SDNPDatabase.AnlgOutOperateDelegate(SlaveAnlgOutOperateEvent); }
The UseSimDatabase and UseSimControlDatabase properties on the TMWSimDatabase switches between these two modes. Note that in the above example they are set to false. Note also that the event handlers are registered with the database so that your application can process the requests through the protocol.
Page 14
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
// Determine which point this request is for ushort pointNumber = Convert.ToUInt16((sender as Control).Tag); // Build and send the request CROBInfo crobData = new CROBInfo(pointNumber, CROBInfo[] crobArray = { crobData };
CROB_CTRL.LOFF, 1, 0, 0);
MDNPSimBinOut point = db.LookupBinOut(pointNumber); MDNPRequest request = new MDNPRequest(masterSesn); request.BinaryCommand(MDNPRequest.DNP_FUNCTION_CODE.SELECT, true, true, 100, (byte)MDNPRequest.DNP_QUALIFIER.Q_8BIT_INDEX, crobArray); }
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 15
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 17
Chapter 3 Overview
This section provides an overview of the TMW .NET Protocol Components architecture. This information will be of interest to all TMW .NET Protocol Components users. Unless otherwise noted, the information in this section pertains to all of the TMW .NET Protocol Components. Note that parts of this section only apply to the source code version of TMW .NET Protocol Components.
3.2 Architecture
This section describes the overall architecture of a TMW .NET Protocol Components. All of the TMW .NET Protocol Components share a common architecture and leverage common code. They are built on top of the Source Code Library. Not all of the information in this section is required to successfully integrate a TMW .NET Protocol Components. However, the information in this section is useful in understanding how the component behaves.
3.2.1 Layers
The TMW .NET Protocol Components architecture is broken into four layers: Physical, Link, Transport, and Application. Each of these layers provides different functionality and is designed to work completely independent of the layers above and below it in the protocol stack. While a thorough understanding of the different layers is not essential, a basic knowledge will help in implementing, tuning, and debugging a TMW .NET Protocol Components implementation. It is important to note that although the TMW .NET Protocol Components architecture is designed to support four layers, not all protocols require or use all of the layers. In a typical device, the user will not interface directly with the different layers. The Physical, Link, and Transport layers are all managed as a single channel, and the Application layer is managed by Sessions and Sectors. The typical implementation does not require direct management of the Physical, Link, and Transport layers. Typically, the configuration parameters for the Physical, Link, and Transport layers are specified as part of the channel configuration.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 19
3.2.1.1Physical Layer
The physical layer manages the target input/output (I/O) device. It accesses the actual physical device through the appropriate routines in WinIoTarg.dll. The physical layer is responsible for: 1) Opening and closing the physical device 2) Transmitting and receiving data on the physical channel 3) Handling low level I/O errors when transmitting or receiving data The physical layer manages the target input/output device by opening and closing the device as required, configuring the device, etc. The physical layer optionally manages parameters related to the transmission and reception of bytes, such as inter-character timeouts, transmission delays, etc.
Page 20
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Sectors
(ASDU address)
Points
Controlling Station
slave 1
slave-n
point (data item 4) point (data item 3) point (data item 2) point (data item 1)
COM1 COM2
3.2.3 Channels
As mentioned above, the TMW .NET Protocol Components encapsulate the physical, link, and transport layers into a single entity called a channel. Most implementations deal with channels rather than dealing directly with a specific physical, link, or transport layer implementation. Figure 3 below illustrates communications channels in a typical implementation.
Controlling Station
COM1 COM2
Figure 3: Illustration of Communication Channels TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011 Page 21
The TMW .NET Protocol Components exchange data with remote devices through one or more Communication Channels. The communication channels illustrated in Figure 3 are COM1 and COM2. The communication channels may be physically discrete channels or logically discrete channels that share a physical connection. An example of a logical communication channel is a TCP/IP serial pipe, which may share a physical 10BaseT interface with other TCP/IP serial pipes.
3.2.4 Sessions
Each channel can have one or more sessions. A session is a communication connection between the master device and one remote slave device. The total number of sessions is the total number of remote slave devices over all communication channels with which the master communicates. Figure 4 below illustrates multiple sessions in a multi-channel setup.
slave 1
Controlling Station
slave 2
slave-n
COM1 COM2
session 1
session 2
session n
Figure 4: Illustration of Communication Sessions When multiple sessions use the same communication channel (a multi-drop topology), the link address for the session must be unique among all sessions using that channel. In messages transmitted or received on a communication channel, the link address identifies the remote Slave device as either the destination of requests or the source of data. Communication protocol specifications supported by the TMW .NET Protocol Components use the ISO protocol standards for the Application (7), Data Link (2), and Physical (1) Layers. It should be noted that session in this product and document does NOT refer to the defined ISO Session(5) Layer.
3.2.5 Sectors
In IEC 60870-5 protocols, remote Slave devices may contain collections of data, called sectors. DNP3 and Modbus do not support sectors. Figure 5 below illustrates a slave device that collects data into three sectors. An example of a remote Slave device with multiple sectors is a data concentrator device that uses sectors to image downstream devices; i.e., each sector represents a single downstream device. The data within a sector represents data collected from the corresponding downstream device. Also, command requests sent by the library to a sector within the data concentrator may also result in commands being transmitted to the corresponding downstream device. Page 22 TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Sector 0
Controlling Station
slave 1
slave 2
data
Sector 1 Sector 2
COM1 COM2
Figure 5: Illustration of Multiple Sectors The Common Address of ASDU field may be either a single-octet or a two-octet field. It is configured for each session when the session is opened. Although it is possible for the size of the field to be different for each device (even on the same communication channel), the IEC 60870-5 protocol specifications dictate that the field size must be the same for all devices in the system (across all communication channels). A Common Address of ASDU value of zero is not used. The value 255 (or 0xFF) for a single-octet address or 65535 (or 0xFFFF) for a two-octet address is used as a broadcast or global address in messages sent by a controlling station. A slave receiving such a message should process the message as if it were addressed to each sector (each different Common Address of ASDU) in the slave.
addition, a remote device can define the same information number for different protective relay Function Types. Therefore, in the IEC 60870-5-103 protocol, three fields are required to identify each data point: Information Number, Element Index, and Function Type. In the IEC 60870-5-102 protocol, the Record Address defines a collection of related data, so an Information Object Address is required to uniquely identify each data point. Therefore, in the IEC 60870-5-102 protocol, two fields are required to identify each data point: Record Address and Information Number. The IEC 60870-5 protocols categorize every data point in a device into a data type. For example, in IEC 60870-5-101, single-point information is a 1-bit binary value, and Measured value, normalized value is a 16-bit integer value. Monitored inputs and controlled outputs are considered to be separate types. Hence, if a data entity could be both set (controlled) and monitored, it must be assigned two data points: a control point and a monitor point, which must have different Information Object Address values.
Page 24
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Table 2: Example IEC 60870-5 Address Map Data Object CB Status Bus Isolator Feeder isolator Bus Earth Switch Feeder Earth Switch Battery Fault Control Supply Auto Reclose In Progress Bus A-Phase KV Bus B-Phase KV Bus C-Phase KV Feeder A-Phase KV Feeder B-Phase KV Feeder C-Phase KV A-Phase Amps B-Phase Amps C-Phase Amps CB Control Bus Isolator Control Feeder Isolator Control Bus Earth Switch Control Feeder Earth Switch Control Auto Reclose Enable Trip Current Note from this example mapping: Each Information Object Address value is unique. The values may be assigned in any order, and do not need to form a contiguous numeric sequence. In an IEC 60870-5 protocol, message efficiency is maximized if objects with the same object type are assigned consecutive Information Object Address values. If an association is to be established between a controllable object and a monitored object, they must have corresponding object types (e.g., Single Command corresponds to Single Information; Set Point Command, Scaled Value corresponds to Measured Value, Scaled Value; etc.). For instance, in the example mapping, the CB Status (Double-Point Information, Information Object Address 1) and CB Control (Double Command, Information Object Address 128) could be associated. When the Page 25 Object type Double-Point Information Double-Point Information Double-Point Information Single-Point Information Single-Point Information Single-Point Information Single-Point Information Single-Point Information Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Measured Value, Scaled Double Command Double Command Double Command Single Command Single Command Single Command Set Point Command, Scaled Information Object Address 1 2 3 4 5 6 7 8 75 76 77 78 79 80 81 82 83 128 129 130 171 172 173 190
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Master issues a command to Information Object Address 128, it would expect to see a corresponding change in the value of Information Object Address 1. If the CB Control had been defined as a single command, this association would not be possible because the control object type would not match the monitored object type. For a master to operate with this slave device, both master and slave must be configured to use the same Data Link Address and Common Address of ASDU, and the data object types and Information object Address values of the slave device must be configured in the Master. The master is also configured to associate any controlled objects and their corresponding indications, as appropriate. If two identical devices of this type were to be used in a system, they must be assigned different Common Address of ASDU values, to conform to the requirement that the combination of Common Address of ASDU and Information Object Address is unique across the whole system.
Page 26
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
In some implementations, it may be desirable to have small gaps in point numbers. Such gaps are easily accommodated by the TMW .NET Protocol Components.
3.2.9.1 Events
The TMW .NET Protocol Components supports a number of events defined in the Application, Channel, Session, Sector, Request and Database classes to allow the TMW .NET Protocol Components to tell the users application that certain events have occurred. Some examples are: 1. Opening, closing, modifying Channels, Sessions, and Sectors. TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011 Page 27
2. Communications and Statistics 3. Database changes 4. Request completion Although the sections below describe the class of events supported by the TMW .NET Protocol Components it is recommended that you refer to the Help files for details.
Page 28
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
3.2.9.1.4
The master database interface is designed to support the storage of values returned from slave devices. In some cases, the data points will be known by the master, in other cases the master database should support the dynamic creation of points returned from the slave device. A separate database is maintained per session for DNP and Modbus or per sector for the IEC 60870-5 protocols. When the Session or Sector is opened the TMW .NET Protocol Components call a database initialization event to allow the target application to initialize its database. The target application may then set the Tag property of the TMW .NET Protocol Components database to something meaningful to the application, such as a pointer, index or other reference. The TMW .NET Protocol Components will provide this Tag property through the TMW .NET Protocol Components database with all future events on the database. The TMW .NET Protocol Components provide an individual data store event for each type of data point object. The input parameters to these events include the Database, the Information Object Address that identifies the data point, and the data values that need to be stored. A database close event is called by the TMW .NET Protocol Components so that the target application can perform whatever actions are required by its database when the session or sector is closed.
3.2.10 Diagnostics
The TMW .NET Protocol Components support the generation of diagnostic information that can be used to analyze the protocol message traffic. All TMW .NET Protocol Components diagnostic information is passed to the user application through the ProtocolBuffer class. This class manages a list of ProtocolDataObjects that contain the diagnostic message and a structure that identifies the source of the message. This message source can be used to filter or redirect the diagnostic information.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 29
The above code registers an event that provides the diagnostic data to the user application. The ProtocolEvent handler will be called periodically as protocol diagnostic data becomes available. Note that this utilizes a windows forms timer (i.e. System.Windows.Forms.Timer) as a result this mechanism only works in a windows forms application. To use the Protocol Buffer in a non windows forms application (i.e. console or windows service) do the following.
static private bool bProtocolMode; static ProtocolBuffer protocolBuffer; static System.Threading.Timer protocolTimer; static void OnUpdateProtocolBufferTimer(object obj) { protocolTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); protocolBuffer.DoForceUpdate(); protocolTimer.Change(500, 500); } static void OnNewProtocolData(ProtocolBuffer buf) { buf.Lock(); for (int i = buf.LastProvidedIndex; i < buf.LastAddedIndex; i++) { string text = protocolBuffer.getPdoAtIndex(i).ProtocolText; Console.Write(string.Format(">>>Protocol: {0}", text)); } buf.UnLock(); } if (bProtocolMode) { protocolTimer = new System.Threading.Timer(OnUpdateProtocolBufferTimer, null, 500, 500); protocolBuffer = TMWApplicationBuilder.getProtocolBuffer(); protocolBuffer.ProtocolDataReadyEvent += OnNewProtocolData; }
In the above code instead of letting the ProtocolBuffer fire the event indicating new protocol data is available. It is up to the user application to perform this through the Page 30 TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
To reduce the number of messages that are buffered you can set the MaxSize property on the ProtocolBuffer object.
protocolBuffer.MaxSize = 100;
To cause the buffered message objects to be deallocated you can call the Clear methodon the ProtocolBuffer object.
protocolBuffer.Clear();
The TMW .NET Protocol Components ships configured for asynchronous database accesses. In this mode, the TMW .NET Protocol Components stores data on a database queue. Synchronous database accesses are not currently not supported in the binary versions of the TMW .NET Protocol Components.
3.3.1 Architecture
This section describes architectural details specific to a master implementation. In addition to the basic features and functionality available in all TMW .NET Protocol Components, each Master Library performs the following functions: 1) 2) Generate and send requests to remote devices as directed by the user application through the associated request objects. Monitor for messages from slave devices and process as follows: a. The message is first checked to see if it is in response to an outstanding request. If so, it processes the request, calling any user events and either closes the request or proceeds to the next step of the request. b. If the message was an unsolicited message it is processed and the appropriate action is taken.
Page 32
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 33
3.4.1 Architecture
This section describes architectural details specific to a slave implementation. In addition to the basic features and functionality available in all TMW .NET Protocol Components each slave TMW .NET Protocol Component performs the following functions: 1) Wait for and process requests from the remote master devices. 2) Optionally scan for change events. 3) Transmit events, either unsolicited or when requested.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 35
One way to implement this method is to write tmwtarg_receive() to accept data from both a primary and secondary communication port and record the last port on which data are received. The tmwtarg_transmit() function sends data on the last port from which data were received. With this scheme, the Library is only aware of one session on one channel; however, the target hardware is actually managing the two redundant serial ports transparently. This method can only be implemented in the Source code version of the TMW .NET Protocol Components by the end user and requires that WinIoTarg.dll be modified.
Page 36
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
4.1.1 Installation
To install the source code, simply run the self extracting executable to install in the desired directory.
4.2 Building
Once the component is installed, the first step should be to build the component as delivered using Visual Studio 2008. The TMW .NET Protocol Components are written using ANSI C, C++/CLI and C# so this is typically a straightforward process. All of the TMW .NET Protocol Component files will be installed under the directory specified during installation. The files will be installed in one or more subdirectories of the installation directory. The directories will include a number of Visual Studio project file as well as a single solution file for the entire component. This solution file can be found at <installdir>/tmwscl/tmw.scl.sln. Simply load this Visual Studio solution file into Visual Studio 2008 and perform a Rebuild All. This will build the samples as well as the TMW .NET Protocol Components. The source code versions contain ANSI C source code that implements the main protocol stack. Although rarely required please refer to the Source Code Library Manual for details on how to modify or debug the ANSI C source code. The source code versions also contain managed C++/CLI and C# source code for use in .NET environments. Your application should be written to make use of the interface provided by this managed code. The files that implement for the managed source code classes resides in <installdir>/tmwscl/.NET/tmw.scl
MBChannel, FT12Channell, I102Channel etc. provide the interface to the other protocols. Each protocol also has a master and slave session class derived from TMWSession. For example, M101Session provides the interface to the Master 101 session. Additionally, the IEC protocols have a master and slave sector class derived from TMWSector.
4.4 Database
Each master and slave session or sector contains a database interface and provides a simple database implementation. The <scl> SimDatabase classes (ie SDNPSimDatabase) provides the interface to the existing implementation. The event interface to provide your own database implementation is contained in <scl>Database (ie SDNPDatabase). See the sample code for examples of how to interface with the existing database or how to use .NET events to provide your own database implementation.
Page 38
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 39
Application Layer
Channel 1
Channel 2
Channel 3
Figure 6: 60870-5-104 Redundancy Software Architecture In this situation the physical and link layers still execute on the same processor as the application layer, but there are multiple physical/link layers or channels. A redundancy group or channel is implemented that manages multiple channels. When a request is received from the application layer it is dispatched to the current active link layer. When information is received on the active link layer it is passed through the redundancy group and forwarded to the application layer. See the I104RedundantMasterGUI or I104RedundantSlaveGUI examples for more details.
and store Data Set information from/to the database. The existing request methods; ReadGroup and ReadPoints and AssignClass also apply to Data Sets. The SDNP TMW .NET Protocol Components SDNPSession class provides the AddEvent method to add Data Set Snapshot events. The sdnp database interface requires DatasetProtoxxx, DatasetDescrxxx and Datasetxxx events to read and write Data Set information from/to the database. Data Set Descriptor Object Group 86 supports 3 variations. The information transferred in these 3 variations is different. Variation 1 which can be read or written, describes the data contained in a Data Set. Variation 2, characteristics, which can be read but not written, indicates whether a Data Set can be read or written, if outstation maintains static and or event Data Sets and if the Data Set was defined by the master or outstation.
There are other .NET component methods that require a time stamp as an argument. You can pass any time that suits your application, but generally you should call S14Sector::GetTimeStamp() to get the time for that sector.
The above should create a directory out32dll that contains the 2 required DLLs. These DLLs should be copied to the correct executable directory.
Page 42
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
OpenSSL also requires parameters to initialize the Diffie-Helman key exchange algorithm. These are placed in a file named dh1024.pem. Examples of this file are available along with the OpenSSL distribution. The OpenSSL documentation says the risk in reusing DH parameters is that an attacker may specialize on a very often used DH group. Applications should generate their own DH parameters during the installation process using the openssl dhparam(1) application. The sample applications DNPMasterGUI and DNPSlaveGUI contain code required to configure and enable SSL/TLS over TCP. Note that this code is commented out in the samples. The names of files containing certificates and other data required by OpenSSL should be modified to use your actual values.
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 43
// SSL/TLS Enabled on this channel. // true requires ssleay32.dll and libeay32.dll from OpenSSL // Also requires Diffie-Helman dh1024.pem file and other files // which may be specified here. slaveChan.SslTlsEnabled = true; // file containing root certificate authority certificate slaveChan.SslTlsCertAuthFile = "root.pem"; // file containing server certificate slaveChan.SslTlsCredentialsFile = "key.pem"; // password for private key in credentials file slaveChan.SslTlsPassword = "yourPassword";
// // // // If false, even if SSL Credentials are not valid connection will be allowed. If true, if SSL Credentials are not valid if SslTlsCheckCertificateEvent is registered it will be fired. If this event is not registered or the event returns false the connection will be broken.
slaveChan.SslTlsVerifyCert = true; // true, if you want to verify the master's credentials slaveChan.SslTlsVerifyClient = false; // event to be fired if Credentials are not valid. slaveChan.SslTlsCheckCertificateEvent += new TMWChannel.SslTlsCheckCertificateEventDelegate(slaveChan_SslTlsCheckCer tificateEvent);
When you run your application, you should look at the diagnostics messages in the protocol log from the target layer to determine if things are working properly. You should see messages similar to the following for a DNP Slave (Outstation) indicating that SSL is configured.
### ### ### ### ### ### ### ### ### ### .NET .NET .NET .NET .NET .NET .NET .NET .NET .NET DNP DNP DNP DNP DNP DNP DNP DNP DNP DNP Slave Slave Slave Slave Slave Slave Slave Slave Slave Slave 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 127.0.0.1:20000 TCP TCP TCP TCP TCP TCP TCP TCP TCP TCP open SSL, Initialized library SSL, Created context SSL, Initialized Context SSL, Opened DH file SSL, Set DH parameters SSL, Read certificate file key.pem SSL, Read key file key.pem SSL, Read CA list root.pem Listen, successfully listening
Sometime later when a connection from the master arrives you should see messages similar to the following.
### TCP LISTENER: accept incoming connection ### .NET DNP Slave - 127.0.0.1:20000 - TCP LISTENER: SSL connection accepted ### TCP LISTENER: listenThread connection accepted from 127.0.0.1
If you see the following message, verify that the two required OpenSSl DLLs are present in the executable directory, or in a directory that can be found by the executable.
### .NET DNP Slave - 127.0.0.1:20000 - TCP SSL, load ssleay32.dll failed
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 45
If you see the following messages, verify the names and location of the files configured. They should normally be placed in the same directory as the executable.
### .NET DNP Slave - 127.0.0.1:20000 - TCP SSL, Can't read certificate file key.pem ### .NET DNP Slave - 127.0.0.1:20000 - TCP SSL, Can't read key file key.pem ### .NET DNP Slave - 127.0.0.1:20000 - TCP SSL, Can't read CA list root.pem
If you get an error similar to the following when you try to run your application, it means that the DLLs you are using are not compiled with the same configuration as the .NET Components. In particular you might be trying to use a debug version instead of a release version of the DLLs. OPENSSL_Uplink(0AA69000,08): no OPENSSL_Applink When the TCP connection is made and SslTlsEnabled is true, the OpenSSL library will try to verify the credentials. By default if this verification fails, the SslTlsCheckCertificateEvent will be fired if it is registered, or if not the connection will be broken. The event if registered can decide whether to allow the connection anyway based on the OpenSSL error such as X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN, passed to it or by further evaluating the OpenSSL structure that is passed to it. The second parameter contains a pointer to a SSL structure. You may choose to call OpenSSL functions to get information about what is contained in that structure. If SslTlsVerifyCert is set to false, the connection will be allowed even if the credential check fails. If the SSL/TLS connection is made between two hosts it is possible to view the data being exchanged using WireShark or a similar TCP analyzer program. Using port 443 allows WireShark to provide a more detailed SSL/TLS interpretation.
Page 46
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Visual C++ 9.0 CRT (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.1) Visual C++ 9.0 ATL (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.1) Visual C++ 9.0 MFC Policy (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.1) Visual C++ 9.0 CRT Policy (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.1) Visual C++ 9.0 ATL Poilicy (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.1) Visual C++ 9.0 MFC (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.4148) Visual C++ 9.0 CRT (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.4148) Visual C++ 9.0 ATL (x86) WinSXS MSM 9.0 Merge Module (9.0.30729.4148) Microsoft .NET Framwork 2.0 SP1 InstallShield Prerequisite You would need to also provide the following libraries from TMW or you may build them if you have purchased Source Code from TMW. TMW.SCL.dll WinIoTarg.dll TMW.BugReporter.dll TMW.SCL.XMLParser.dll SCLLicenseManager.dll (only if redistributable or single use. Not required for Source Code Library executables) The following two libraries are also required if OpenSSL is enabled in TH and .NET 3.9.5 and later. ssleay32.dll Libeay32.dll DNPMaster.exe (for example, whatever the executable is named.)
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 47
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011
Page 49
You may download a full 21-day evaluation version of the Communication Protocol Test Harness (including documentation) from the Triangle MicroWorks, Inc. website at: http://www.TriangleMicroworks.com/downloads.htm.
Page 50
TMW .NET Protocol Components User Manual Version 3.00 Last Modified: 30 June 2011