.net Platform Sample Code
The following is an complete example of how to use all of the functionality of Zeus API in .NET Framework (C# / VB.net) and .NET 7 (C#).
VB .net Sample Code
' Notes: You can obtain your authaccount and authpass, '
' when you have made login on ZeusWeb, going to URL: api_credentials.html '
' - IP should have this format "192.168.1.1", or the domain name '
' - If you want the client connect to a secure server (SSL), the SSL parameter must be True '
Dim client As ZeusAPI.Client = Nothing
Try
' Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html '
client = New ZeusAPI.Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass")
Catch ex As Exception
Console.WriteLine(ex.ToString)
Return
End Try
' Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now '
Dim myHistorical As List(Of ZeusAPI.Historical) = client.GetHistorical("MyStation", Date.Now.AddDays(-1), Date.Now, New List(Of Integer)({0, 1}))
If (IsNothing(myHistorical)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.Historical In myHistorical
Console.WriteLine("DATE: " & element.DateOfRecord.ToString() & " REASON: " & element.Reason & " CHANNEL_ID: " & element.ChannelID.ToString() & " VALUE: " & element.Value.ToString)
Next
End If
' Gets the real time values / last known values of the station "MyStation" '
Dim mylastknownvalues As ZeusAPI.LastKnownValues = client.GetLastKnownValues("MyStation")
If IsNothing(mylastknownvalues) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
mylastknownvalues.values("0") = 52.5 ' Set last known value for channel Analog 0 = 52.5 '
mylastknownvalues.values("1") = 40.3 ' Set last known value for channel Analog 1 = 40.3 '
' Uploads the changed values to the Server '
If (client.SetLastKnownValues("MyStation", mylastknownvalues) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
End If
' Gets alarms of all stations that user can see, since yesterday until now '
Dim myAlarm As List(Of ZeusAPI.Alarms) = client.GetAlarm(Date.Now.AddDays(-1), Date.Now)
If IsNothing(myAlarm) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.Alarms In myAlarm
Console.WriteLine("DATE: " & element.DateOfRecord & " STATION: " & element.StationID & " REASON: " & element.Reason & " CHANNEL_ID: " & element.ChannelID & " TEXT: " & element.AlarmText)
Next
End If
' Upload historians for station "MyStation" '
If (client.SetHistorical("MyStation", New List(Of ZeusAPI.Historical)({New ZeusAPI.Historical(Date.Now, 0, "0", 10.2), New ZeusAPI.Historical(Date.Now, 1, "0", 15.5)})) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Upload alarms for station "MyStation" '
If (client.SetAlarms(New List(Of ZeusAPI.Alarms)({New ZeusAPI.Alarms("MyStation", Date.Now, 1, 21, "This is my high level alarm", ""), New ZeusAPI.Alarms("MyStation", Date.Now, 3, 22, "This is my restored alarm", "")})) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Send a message to the station "Microcom" '
If (client.SendMessage("Microcom", "my message") = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Gets enqueued messages pending of execution on server '
Dim myMessages As List(Of ZeusAPI.KeyValue) = client.PendingMessages()
If (IsNothing(myMessages)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each message As ZeusAPI.KeyValue In myMessages
Console.WriteLine("KEY: " + message.Key + " VALUE: " + message.Value)
Next
End If
' Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation" '
Dim myConfigurationRelay As List(Of ZeusAPI.ProgrammableRelayPeriod) = client.GetConfigurationRelay("MyStation", 0)
If (IsNothing(myConfigurationRelay)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.ProgrammableRelayPeriod In myConfigurationRelay
Console.WriteLine("WEEKDAYS: " & element.Weekdays.ToString() & " ACTIVATIONTIME: " & element.ActivationTime & " DURATION: " & element.Duration.ToString())
Next
End If
' Send a Relay Configuration to the station "Microcom" to output 0 '
Dim myFrameTime As New List(Of ZeusAPI.ProgrammableRelayPeriod)
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "M", "X"}), Date.Now, 5))
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "J", "V"}), Date.Now, 20))
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "M", "X", "J", "V", "S", "D"}), Date.Now, 120))
If (client.SetConfigurationRelay("Microcom", 0, myFrameTime) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
C# Sample Code
// Notes: You can obtain your authaccount and authpass,
// when you have made login on ZeusWeb, going to URL: api_credentials.html
// - IP should have this format "192.168.1.1", or the domain name
// - If you want the client connect to a secure server (SSL), the SSL parameter must be True
ZeusAPI.Client client = new ZeusAPI.Client();
try
{
client = new ZeusAPI.Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Environment.Exit(0);
}
// Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now
List channels = new List() { 0, 1 };
List myHistorical = client.GetHistorical("MyStation", DateTime.Now.AddDays(-1), DateTime.Now, ref channels);
if (myHistorical == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach(ZeusAPI.Historical element in myHistorical){
Console.WriteLine("DATE: " + element.DateOfRecord.ToString() + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID.ToString() + " VALUE: " + element.Value.ToString());
}
}
// Gets the last known value of the station "MyStation" '
ZeusAPI.LastKnownValues mylastknownvalues = new ZeusAPI.LastKnownValues();
mylastknownvalues = client.GetLastKnownValues("MyStation");
if (mylastknownvalues == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
mylastknownvalues.values["0"] = 52.5f; // Set last known value for channel Analog 0 = 52.5 '
mylastknownvalues.values["1"] = 40.3f; // Set last known value for channel Analog 1 = 40.3 '
// Uploads the changed values to the Server
if (client.SetLastKnownValues("MyStation", ref mylastknownvalues) == false)
Console.WriteLine(client.GetZeusApiLastError());
}
// Gets alarms of all stations that user can see, since yesterday until now
List myAlarms = client.GetAlarm(DateTime.Now.AddDays(-1), DateTime.Now);
if (myAlarms == null)
Console.WriteLine(client.GetZeusApiLastError());
else
{
foreach (ZeusAPI.Alarms element in myAlarms)
{
Console.WriteLine("DATE: " + element.DateOfRecord.ToString() + " STATION: " + element.StationID + " REASON: " + element.Reason.ToString() + " CHANNEL_ID: " + element.ChannelID.ToString() + " TEXT: " + element.AlarmText);
}
}
// Upload historians for station "MyStation"
List myListHistorical = new List() { (new ZeusAPI.Historical(DateTime.Now, 0, "0", 10.2f)), new ZeusAPI.Historical(DateTime.Now, 1, "0", 15.5f) };
if (client.SetHistorical("MyStation", myListHistorical) == false)
Console.WriteLine(client.GetZeusApiLastError());
// Upload alarms for station "MyStation"
List myListAlarms = new List() { (new ZeusAPI.Alarms("MyStation", DateTime.Now, 1, 21, "This is my high level alarm", "")), (new ZeusAPI.Alarms("MyStation", DateTime.Now, 3, 22, "This is my restored alarm", "")) };
if (client.SetAlarms(ref myListAlarms) == false)
Console.WriteLine(client.GetZeusApiLastError());
// Send a message to the station "Microcom"
if (client.SendMessage("Microcom", "my message") == false)
Console.WriteLine(client.GetZeusApiLastError());
// Gets enqueued messages pending of execution on server
List myMessages = client.PendingMessages();
if (myMessages == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach (ZeusAPI.KeyValue element in myMessages)
{
Console.WriteLine("KEY: " + element.Key + " VALUE: " + element.Value);
}
}
// Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation"
List myConfigurationRelay = client.GetConfigurationRelay("MyStation", 0);
if (myConfigurationRelay == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach (ZeusAPI.ProgrammableRelayPeriod element in myConfigurationRelay)
Console.WriteLine("WEEKDAYS: " + element.Weekdays.ToString() + " ACTIVATIONTIME: " + element.ActivationTime + " DURATION: " + element.Duration.ToString());
}
// Send a Relay Configuration to the station "Microcom" to output 0 '
List myFrameTime = new List();
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "M", "X" }, DateTime.Now, 5));
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "J", "V" }, DateTime.Now, 20));
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "M", "X", "J", "V", "S", "D" }, DateTime.Now, 120));
if (client.SetConfigurationRelay("Microcom", 0, myFrameTime) == false)
Console.WriteLine(client.GetZeusApiLastError());
' Notes: You can obtain your authaccount and authpass, '
' when you have made login on ZeusWeb, going to URL: api_credentials.html '
' - IP should have this format "192.168.1.1", or the domain name '
' - If you want the client connect to a secure server (SSL), the SSL parameter must be True '
Dim client As ZeusAPI.Client = Nothing
Try
' Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html '
client = New ZeusAPI.Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass")
Catch ex As Exception
Console.WriteLine(ex.ToString)
Return
End Try
' Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now '
Dim myHistorical As List(Of ZeusAPI.Historical) = client.GetHistorical("MyStation", Date.Now.AddDays(-1), Date.Now, New List(Of Integer)({0, 1}))
If (IsNothing(myHistorical)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.Historical In myHistorical
Console.WriteLine("DATE: " & element.DateOfRecord.ToString() & " REASON: " & element.Reason & " CHANNEL_ID: " & element.ChannelID.ToString() & " VALUE: " & element.Value.ToString)
Next
End If
' Gets the real time values / last known values of the station "MyStation" '
Dim mylastknownvalues As ZeusAPI.LastKnownValues = client.GetLastKnownValues("MyStation")
If IsNothing(mylastknownvalues) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
mylastknownvalues.values("0") = 52.5 ' Set last known value for channel Analog 0 = 52.5 '
mylastknownvalues.values("1") = 40.3 ' Set last known value for channel Analog 1 = 40.3 '
' Uploads the changed values to the Server '
If (client.SetLastKnownValues("MyStation", mylastknownvalues) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
End If
' Gets alarms of all stations that user can see, since yesterday until now '
Dim myAlarm As List(Of ZeusAPI.Alarms) = client.GetAlarm(Date.Now.AddDays(-1), Date.Now)
If IsNothing(myAlarm) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.Alarms In myAlarm
Console.WriteLine("DATE: " & element.DateOfRecord & " STATION: " & element.StationID & " REASON: " & element.Reason & " CHANNEL_ID: " & element.ChannelID & " TEXT: " & element.AlarmText)
Next
End If
' Upload historians for station "MyStation" '
If (client.SetHistorical("MyStation", New List(Of ZeusAPI.Historical)({New ZeusAPI.Historical(Date.Now, 0, "0", 10.2), New ZeusAPI.Historical(Date.Now, 1, "0", 15.5)})) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Upload alarms for station "MyStation" '
If (client.SetAlarms(New List(Of ZeusAPI.Alarms)({New ZeusAPI.Alarms("MyStation", Date.Now, 1, 21, "This is my high level alarm", ""), New ZeusAPI.Alarms("MyStation", Date.Now, 3, 22, "This is my restored alarm", "")})) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Send a message to the station "Microcom" '
If (client.SendMessage("Microcom", "my message") = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
' Gets enqueued messages pending of execution on server '
Dim myMessages As List(Of ZeusAPI.KeyValue) = client.PendingMessages()
If (IsNothing(myMessages)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each message As ZeusAPI.KeyValue In myMessages
Console.WriteLine("KEY: " + message.Key + " VALUE: " + message.Value)
Next
End If
' Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation" '
Dim myConfigurationRelay As List(Of ZeusAPI.ProgrammableRelayPeriod) = client.GetConfigurationRelay("MyStation", 0)
If (IsNothing(myConfigurationRelay)) Then
Console.WriteLine(client.GetZeusApiLastError())
Else
For Each element As ZeusAPI.ProgrammableRelayPeriod In myConfigurationRelay
Console.WriteLine("WEEKDAYS: " & element.Weekdays.ToString() & " ACTIVATIONTIME: " & element.ActivationTime & " DURATION: " & element.Duration.ToString())
Next
End If
' Send a Relay Configuration to the station "Microcom" to output 0 '
Dim myFrameTime As New List(Of ZeusAPI.ProgrammableRelayPeriod)
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "M", "X"}), Date.Now, 5))
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "J", "V"}), Date.Now, 20))
myFrameTime.Add(New ZeusAPI.ProgrammableRelayPeriod(New List(Of String)({"L", "M", "X", "J", "V", "S", "D"}), Date.Now, 120))
If (client.SetConfigurationRelay("Microcom", 0, myFrameTime) = False) Then
Console.WriteLine(client.GetZeusApiLastError())
End If
// Notes: You can obtain your authaccount and authpass,
// when you have made login on ZeusWeb, going to URL: api_credentials.html
// - IP should have this format "192.168.1.1", or the domain name
// - If you want the client connect to a secure server (SSL), the SSL parameter must be True
ZeusAPI.Client client = new ZeusAPI.Client();
try
{
client = new ZeusAPI.Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Environment.Exit(0);
}
// Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now
List channels = new List() { 0, 1 };
List myHistorical = client.GetHistorical("MyStation", DateTime.Now.AddDays(-1), DateTime.Now, ref channels);
if (myHistorical == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach(ZeusAPI.Historical element in myHistorical){
Console.WriteLine("DATE: " + element.DateOfRecord.ToString() + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID.ToString() + " VALUE: " + element.Value.ToString());
}
}
// Gets the last known value of the station "MyStation" '
ZeusAPI.LastKnownValues mylastknownvalues = new ZeusAPI.LastKnownValues();
mylastknownvalues = client.GetLastKnownValues("MyStation");
if (mylastknownvalues == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
mylastknownvalues.values["0"] = 52.5f; // Set last known value for channel Analog 0 = 52.5 '
mylastknownvalues.values["1"] = 40.3f; // Set last known value for channel Analog 1 = 40.3 '
// Uploads the changed values to the Server
if (client.SetLastKnownValues("MyStation", ref mylastknownvalues) == false)
Console.WriteLine(client.GetZeusApiLastError());
}
// Gets alarms of all stations that user can see, since yesterday until now
List myAlarms = client.GetAlarm(DateTime.Now.AddDays(-1), DateTime.Now);
if (myAlarms == null)
Console.WriteLine(client.GetZeusApiLastError());
else
{
foreach (ZeusAPI.Alarms element in myAlarms)
{
Console.WriteLine("DATE: " + element.DateOfRecord.ToString() + " STATION: " + element.StationID + " REASON: " + element.Reason.ToString() + " CHANNEL_ID: " + element.ChannelID.ToString() + " TEXT: " + element.AlarmText);
}
}
// Upload historians for station "MyStation"
List myListHistorical = new List() { (new ZeusAPI.Historical(DateTime.Now, 0, "0", 10.2f)), new ZeusAPI.Historical(DateTime.Now, 1, "0", 15.5f) };
if (client.SetHistorical("MyStation", myListHistorical) == false)
Console.WriteLine(client.GetZeusApiLastError());
// Upload alarms for station "MyStation"
List myListAlarms = new List() { (new ZeusAPI.Alarms("MyStation", DateTime.Now, 1, 21, "This is my high level alarm", "")), (new ZeusAPI.Alarms("MyStation", DateTime.Now, 3, 22, "This is my restored alarm", "")) };
if (client.SetAlarms(ref myListAlarms) == false)
Console.WriteLine(client.GetZeusApiLastError());
// Send a message to the station "Microcom"
if (client.SendMessage("Microcom", "my message") == false)
Console.WriteLine(client.GetZeusApiLastError());
// Gets enqueued messages pending of execution on server
List myMessages = client.PendingMessages();
if (myMessages == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach (ZeusAPI.KeyValue element in myMessages)
{
Console.WriteLine("KEY: " + element.Key + " VALUE: " + element.Value);
}
}
// Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation"
List myConfigurationRelay = client.GetConfigurationRelay("MyStation", 0);
if (myConfigurationRelay == null)
Console.WriteLine(client.GetZeusApiLastError());
else{
foreach (ZeusAPI.ProgrammableRelayPeriod element in myConfigurationRelay)
Console.WriteLine("WEEKDAYS: " + element.Weekdays.ToString() + " ACTIVATIONTIME: " + element.ActivationTime + " DURATION: " + element.Duration.ToString());
}
// Send a Relay Configuration to the station "Microcom" to output 0 '
List myFrameTime = new List();
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "M", "X" }, DateTime.Now, 5));
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "J", "V" }, DateTime.Now, 20));
myFrameTime.Add(new ZeusAPI.ProgrammableRelayPeriod(new List() { "L", "M", "X", "J", "V", "S", "D" }, DateTime.Now, 120));
if (client.SetConfigurationRelay("Microcom", 0, myFrameTime) == false)
Console.WriteLine(client.GetZeusApiLastError());