Visual Basic Script Sample Code

The following is an complete example of how to use all of the functionality of Zeus API in Visual Basic Script.

Let's start:

  • download the helper.
  • unzip it.
  • Open a command line and go to C:\Windows\Microsoft.NET\Framework\[your-net-version].
  • Execute RegAsm.exe [path-to-ZeusAPI.dll] /codebase.
  • Once created your script, you can launch it with C:\Windows\SysWOW64\cscript [path-to-your-script].

Visual Basic Script 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 result
	Dim client
	SET client = CreateObject("ZeusAPI.Client")

	' Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html'
	client.Create "IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass"

	' Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now '
	set channels = CreateObject("ZeusAPI.ListInteger")
	channels.Add(0)
	channels.Add(1)
	set myHistorical = client.GetHistorical("MyStation", DateAdd("d", -1, Now()), Now(), channels)
	if myHistorical is Nothing Then
		MsgBox(client.GetZeusApiLastError())
	Else
		if myHistorical.Count() <> 0 Then
			for i=0 to myHistorical.Count() - 1 step 1
				MsgBox("DATE: " & myHistorical.Item(i).DateOfRecord & " REASON: " & myHistorical.Item(i).Reason & " CHANNEL_ID: " & myHistorical.Item(i).ChannelID & " VALUE: " & myHistorical.Item(i).Value)
			next
		Else
			MsgBox("There is not Historical with this parameters.")
		End if
	End if

	' Gets the real time values / last known values of the station "MyStation" '
	set myLastKnowValues = client.GetLastKnownValues("MyStation")
	if myLastKnowValues is Nothing Then
		MsgBox(client.GetZeusApiLastError())
	Else
		myLastKnowValues.values.Item("0") = 52.5 ' Set last known value for channel Analog 0 = 52.5 '
		myLastKnowValues.values.Item("1") = 40.3 ' Set last known value for channel Analog 1 = 40.3 '
		' Uploads the changed values to the Server '
		result = client.SetLastKnownValues("MyStation", myLastKnowValues)
		If (result = False) Then
			MsgBox(client.GetZeusApiLastError())
		End If
	End if

	' Gets alarms of all stations that user can see, since yesterday until now '
	set myAlarms = client.GetAlarm(DateAdd("d", -1, Now()), Now())
	if myAlarms is Nothing Then
		MsgBox(client.GetZeusApiLastError())
	Else
		if myAlarms.Count() <> 0 Then
			for i=0 to myAlarms.Count() - 1 step 1
				MsgBox("DATE: " & myAlarms.Item(i).DateOfRecord & " STATION: " & myAlarms.Item(i).StationID & " REASON: " & myAlarms.Item(i).Reason & " CHANNEL_ID: " & myAlarms.Item(i).ChannelID & " TEXT: " & myAlarms.Item(i).AlarmText)
			next
		Else
			MsgBox("There is not Alarms with this parameters.")
		End if
	End if


	' Upload historians for station "MyStation" '
	set myHistorical1 = CreateObject("ZeusAPI.Historical")
	myHistorical1.DateOfRecord = Now()
	myHistorical1.ChannelID = 0
	myHistorical1.Reason = "0"
	myHistorical1.Value =  10.2

	set myHistorical2 = CreateObject("ZeusAPI.Historical")
	myHistorical2.DateOfRecord = Now()
	myHistorical2.ChannelID = 1
	myHistorical2.Reason = "0"
	myHistorical2.Value =  15.5

	set myListHistorical = CreateObject("ZeusAPI.ListHistorical")
	myListHistorical.Add(myHistorical1)
	myListHistorical.Add(myHistorical2)
	result = client.SetHistorical("MyStation", myListHistorical)
	If (result = False) Then
		MsgBox(client.GetZeusApiLastError())
	End If


	' Upload alarms for station "MyStation" '
	set myAlarm1 = CreateObject("ZeusAPI.Alarms")
	myAlarm1.StationID = "MyStation"
	myAlarm1.DateOfRecord = Now()
	myAlarm1.Reason = 1
	myAlarm1.ChannelID = 21
	myAlarm1.AlarmText =  "This is my high level alarm"

	set myAlarm2 = CreateObject("ZeusAPI.Alarms")
	myAlarm2.StationID = "MyStation"
	myAlarm2.DateOfRecord = Now()
	myAlarm2.Reason = 3
	myAlarm2.ChannelID = 22
	myAlarm2.AlarmText =  "This is my restored alarm"

	set myListAlarms = CreateObject("ZeusAPI.ListAlarms")
	myListAlarms.Add(myAlarm1)
	myListAlarms.Add(myAlarm2)
	result = client.SetAlarms(myListAlarms)
	If (result = False) Then
		MsgBox(client.GetZeusApiLastError())
	End If

	' Send a message to the station "Microcom" '
	result = client.SendMessage("Microcom", "my message")
	If (result = False) Then
		MsgBox(client.GetZeusApiLastError())
	End If

	' Gets enqueued messages pending of execution on server '
	set pendingMsg = client.PendingMessages()
	if pendingMsg is Nothing Then
		MsgBox(client.GetZeusApiLastError())
	Else
		if pendingMsg.Count() <> 0 Then
			for i=0 to pendingMsg.Count() - 1 step 1
				MsgBox("KEY: " & pendingMsg.Item(i).Key & " VALUE: " & pendingMsg.Item(i).Value)
			next
		Else
			MsgBox("There is not Messages.")
		End if
	End if