Simple example of using .Net to read two attributes of a Metasys site.
- dotnet 6 or greater
- NewtonSoft.Json
- Flurl.Http
Clone the repos
git clone https://github.com/metasys-server/csharp-read-attribute-exampleOpen Program.cs and locate and modify the following
hostSet this to your server host name (for example:ADX25)usernameSet this to an api user on your system (for example:api)passwordSet this to a valid password. (Note this is for test purposes only. You should never hard-code passwords for a production system into source code.)object1IdThe identifier of an object you want to read thepresentValueof.object2IdThe identifier of another object you want to read thepresentValueof.
When you are dong the values will look something like this:
var host = "ADX25";
var username = "api-user";
// For test systems only. Never embed passwords for production systems in your code.
var password = "my-password";
// Object IDs are available within MUI or using GET /objectIdentifiers?fqr={fqr}
var object1Id = "960534d2-7df5-5ed8-884c-164e7a2f280a";
var object2Id = "c82d160b-884c-5eac-bad4-89754f0069e0";Now you can run the app
> dotnet run
Value 1: 72.5
Value 2: 18.23For Windows/Release (for Debug, drop the -c switch)
dotnet publish -r win-x64 -p:PublishSingleFile=True --self-contained -c ReleaseFor macOS/Release (for Debug, drop the -c switch)
dotnet publish -r osx-x64 -p:PublishSingleFile=True --self-contained -c Release