Sample06: UI-C#-ADS client uploading the symbolic from module
This article describes the implementation of an ADS client to
- connect to an ADS server that provides a process image (data area); the connection can be established locally or remotely via a network,
- upload symbol information,
- read / write data synchronously,
- subscribe to symbols, in order to obtain values on change as callback.
Download
Here you can access the source code for this client sample.
- This code requires .NET Framework 3.5 or higher!
- 1. Unpack the downloaded ZIP file.
- 2. Open the sln file contained in it with Visual Studio.
- 3. Create the sample on your local machine (right-click on the project and click on "Build").
- 4. Start the program with a right-click on Project, Debug->Start new instance.
The client sample should be used with sample 03 "C++ as ADS server".
Open Sample 03 before you begin with this client-side sample!
Description
The possibilities of the ADS are described on the basis of this sample.
The details of the implementation are described in Form1.cs, which is included in the download. The connection via ADS with the target system is established in the btnLoad_Click method, which is called on clicking on the Load Symbols button. From there you can explore the different GUI functions.
Background information:
For this ADS client it is irrelevant whether the ADS server is based on TwinCAT 2 or TwinCAT 3. It also doesn't matter if the server is a C++ module, a PLC module or an IO task without any logic.
The ADS client UI
On starting of the sample the user interface (UI) is displayed.
Selecting a communication partner
After starting the client, enter the two ADS parameters, in order to determine your ADS communication partner.
- NetID:
127.0.0.1.1.1 (for ADS partner also linked with local ADS message router).
Enter another NetID, if you want to communicate with an ADS partner connected to another ADS router via the network.
First you have to create an ADS route between your device and the remote device. - AdsPort
Enter the AdsPort of your communication partner: 350 (in this sample).
Do not confuse the ADS server port with the regular ADS port. Do not confuse the ADS server port (which was explicitly implemented in sample 03 for providing your own message handler) with the regular ADS port for the purpose of access to symbols (this is provided automatically, without the need for user intervention): The regular ADS port is required to access symbols. You can find the AdsPort for the IO task of your instance or the module instance yourself (since the module is executed in the context of the IO task). |
Navigate to IO task Task1 and note the value of the port: 350.
Since the C++ module instance is executed in the context of Task1, the ADS port is also 350.
Enabled symbols for access available via ADS
Individual symbols or whole data areas can be provided for access via ADS, or they can be deliberately not provided.
Navigate to the Data Area tab of your instance and activate/deactivate the C/S column.
In this sample all symbols are marked and therefore available for ADS access.
After making the changes, click on Activate configuration.
Load symbols
Once the NetID and the ADS port have been set up, click on the Load Symbols button to make a connection with the target system and load the symbols.
All available symbols are then visible. You can then:
- Write a new value:
select a symbol in the left-hand tree, e.g. Counter.
enter a new value in the edit box Value on the right-hand side and click on Write using WriteSymbol.
The new value is written to the ADS server.
After writing a new value with Write using WriteSymbol, the C# application is assigned a callback with the new value. - Subscribe in order to obtain callback when the value changes:
select a symbol in the left-hand tree, e.g. Counter.
click on Watch Current Symbol.