Kepware.Api
Overview
The Kepware.Api library provides a robust client implementation to interact with the Kepware Configuration API. It supports managing channels, devices, tags, and other configurations programmatically while ensuring secure and efficient communication.
This package is designed to work with all versions of Kepware that support the Configuration API including Kepware Server (KS), and Kepware Edge (KE). For reference, Kepware Server in this documentation will also imply Thingworx Kepware Server and KEPServerEX versions prior to v7.0 when v6.x is referenced.
Features
- Connect to Kepware Configuration APIs securely with HTTPS and optional certificate validation.
- Perform CRUD operations for the following Kepware configuration objects:
| Features | KS | KE |
|---|---|---|
| Project Properties (Get Only) |
Y | Y |
| Connectivity (Channel, Devices, Tags, Tag Groups) |
Y | Y |
| Administration (User Groups, Users, UA Endpoints, Local License Server) |
Y[^1] | Y |
| Product Info and Health Status | Y[^4] | Y |
| Export Project | Y[^2] | Y |
| Import Project (via CompareAndApply)[^3] | Y | Y |
| Import Project (via JsonProjectLoad Service) | N[^2] | N |
[^1]: UA Endpoints and Local License Server supported for Kepware Edge only [^2]: JsonProjectLoad was added to Kepware Server v6.17 and later builds, the SDK detects the server version and uses the appropriate service or loads the project by multiple requests if using KepwareApiClient.LoadProject. [^3]: CompareAndApply is handled by the SDK, it compares the source project with the server project and applies the changes. The JsonProjectLoad service is a direct call to the server to load a project. [^4]: Added to Kepware Server v6.13 and later builds
- Configuration API Services implemented:
| Services | KS | KE |
|---|---|---|
| TagGeneration (for supported drivers) |
Y | Y |
| ReinitializeRuntime | Y* | Y |
| ProjectLoad and ProjectSave | N | N |
| JsonProjectLoad** (used for import project feature) |
Y | Y |
- Synchronize configurations between your application and Kepware server.
- Supports advanced operations like project comparison, entity synchronization, and driver property queries.
- Built-in support for Dependency Injection to simplify integration.
Installation
Kepware.Api NuGet package is available from NuGet repository.
Add the
Kepware.Apilibrary to your project as a reference.dotnet add package Kepware.ApiRegister the
KepwareApiClientin your application using Dependency Injection:services.AddKepwareApiClient( name: "default", baseUrl: "https://localhost:57512", apiUserName: "Administrator", apiPassword: "StrongAdminPassword2025!", disableCertificateValidation: true );
Key Methods
Connection and Status
Test Connection:
var isConnected = await api.TestConnectionAsync();Tests the connection to the Kepware server. Returns
trueif successful.Get Product Info:
var productInfo = await api.GetProductInfoAsync();Retrieves product information about the Kepware server.
Project Management
Load Project:
var project = await api.LoadProject(blnLoadFullProject:true);Loads the current project from the Kepware server.
Compare and Apply Project:
var result = await api.CompareAndApply(sourceProject);Compares a source project with the Kepware server's project and applies changes.
Entity Operations
Channels
- Get or Create Channel:
Retrieves an existing channel or creates a new one.var channel = await api.GetOrCreateChannelAsync("Channel1", "Simulator");
Devices
- Get or Create Device:
Retrieves an existing device or creates a new one under the specified channel.var device = await api.GetOrCreateDeviceAsync(channel, "Device1", "Simulator");
Tags
- Synchronize Tags:
var tags = new DeviceTagCollection(new[] { new Tag { Name = "Ramp", TagAddress = "RAMP (0, 100, 1)" }, new Tag { Name = "Sine", TagAddress = "SINE (0, 360, 0.1)" } }); await api.CompareAndApply(tags, device.Tags, device);
Driver Properties
- Supported Drivers:
Retrieves a list of supported drivers and their details.var drivers = await api.GetSupportedDriversAsync();
CRUD Operations
Update Item:
await api.UpdateItemAsync(device);Insert Item:
await api.InsertItemAsync<ChannelCollection,Channel>(channel);Delete Item:
await api.DeleteItemAsync(device);
Licensing
This SDK is provided "as is" under the MIT License. See the LICENSE file for details.
Support
For any issues, please open an Issue within the repository. For questions or feature requests, please open a Discussion thread within the repository.
See Repository Guidelines for more information.