Windows Scripting Host

Laden Sie das SPS-Programm in die lokale SPS auf Ihrem PC und starten Sie das SPS-Programm. Rufen Sie anschließend das Script auf.

Nachdem der Kommunikationskanal geöffnet wurde, wird überprüft, ob sich die SPS im RUN-Zustand befindet. Falls nicht, wird die SPS gestartet. Als nächstes werden alle SPS-Variablen ausgelesen und einzeln angezeigt. Anschließend werden alle Variablen erhöht und zur Kontrolle wieder ausgelesen und angezeigt. Zum Schluß wird die SPS wieder gestoppt.

VBScript:

Dim TcClientSync
Dim VarBool, VarInt8, VarInt16, VarInt32, VarReal32, VarReal64

'create TcScript-Object
Set TcClientSync = CreateObject("TCSCRIPT.TcScriptSync")
Call TcClientSync.ConnectTo("", 801)

if (TcClientSync.ReadAdsState() <> 5) then
  WScript.echo("PLC is not running!" & vbCrLf & "Start PLC.")
  Call TcClientSync.WriteAdsState(5)
end if

'read from PLC
VarBool = TcClientSync.ReadBool(&H4020, 0)
WScript.echo "VarBool = ", VarBool

VarInt8 = TcClientSync.ReadInt8(&H4020, 2)
WScript.echo "VarInt8 = ", VarInt8

VarInt16 = TcClientSync.ReadInt16(&H4020, 4)
WScript.echo "VarInt16 = ", VarInt16

VarInt32 = TcClientSync.ReadInt32(&H4020, 6)
WScript.echo "VarInt32 = ", VarInt32

VarReal32 = TcClientSync.ReadReal32(&H4020, 10)
WScript.echo "VarReal32 = ", VarReal32

VarReal64 = TcClientSync.ReadReal64(&H4020, 14)
WScript.echo "VarReal64 = ", VarReal64

'write to PLC
Call TcClientSync.WriteBool(&H4020, 0, NOT VarBool)  
Call TcClientSync.WriteInt8(&H4020, 2, VarInt8 + 1) 
Call TcClientSync.WriteInt16(&H4020, 4, VarInt16 +1) 
Call TcClientSync.WriteInt32(&H4020, 6, VarInt32 + 1)
Call TcClientSync.WriteReal32(&H4020, 10, VarReal32 +1.1)
Call TcClientSync.WriteReal64(&H4020, 14, VarReal64 +1.11)

Call TcClientSync.WriteVar(".PLCBoolVar", VarBool)
Call TcClientSync.WriteVar(".PLCSIntVar", VarInt8 +2)
Call TcClientSync.WriteVar(".PLCIntVar", VarInt16 +2)
Call TcClientSync.WriteVar(".PLCDIntVar", VarInt32 +2)
Call TcClientSync.WriteVar(".PLCRealVar", VarReal32 +2.1)
Call TcClientSync.WriteVar(".PLCLRealVar", VarReal64 +2.11)

'read again from PLC
VarBool = TcClientSync.ReadVar(".PLCBoolVar")
WScript.echo "VarBool = ", VarBool

VarInt8 = TcClientSync.ReadVar(".PLCSIntVar")
WScript.echo "VarInt8 = ", VarInt8

VarInt16 = TcClientSync.ReadVar(".PLCIntVar")
WScript.echo "VarInt16 = ", VarInt16

VarInt32 = TcClientSync.ReadVar(".PLCDIntVar")
WScript.echo "VarInt32 = ", VarInt32

VarReal32 = TcClientSync.ReadVar(".PLCRealVar")
WScript.echo "VarReal32 = ", VarReal32

VarReal64 = TcClientSync.ReadVar(".PLCLRealVar")
WScript.echo "VarReal64 = ", VarReal64

if (TcClientSync.ReadAdsState() = 5) then
  WScript.echo("PLC is running!" & vbCrLf & "Stop PLC.")
  Call TcClientSync.WriteAdsState(6)
end if

JScript:

var TcClientSync;
var VarBool, VarInt8, VarInt16, VarInt32, VarReal32, VarReal64;

// create TcScript-Object
TcClientSync = new ActiveXObject("TCSCRIPT.TcScriptSync");
TcClientSync.ConnectTo("", 801);

if (TcClientSync.ReadAdsState() != 5)
{
  WScript.echo("PLC is not running!\nStart PLC.");
  TcClientSync.WriteAdsState(5);
}
// read from PLC
VarBool = TcClientSync.ReadBool(0x4020, 0);
WScript.echo("VarBool = ", VarBool);

VarInt8 = TcClientSync.ReadInt8(0x4020, 2);
WScript.echo("VarInt8 = ", VarInt8);

VarInt16 = TcClientSync.ReadInt16(0x4020, 4);
WScript.echo("VarInt16 = ", VarInt16);

VarInt32 = TcClientSync.ReadInt32(0x4020, 6);
WScript.echo("VarInt32 = ", VarInt32);

VarReal32 = TcClientSync.ReadReal32(0x4020, 10);
WScript.echo("VarReal32 = ", VarReal32);


VarReal64 = TcClientSync.ReadReal64(0x4020, 14);
WScript.echo("VarReal64 = ", VarReal64);

// write to PLC
TcClientSync.WriteBool(0x4020, 0, !VarBool);
TcClientSync.WriteInt8(0x4020, 2, VarInt8 + 1); 
TcClientSync.WriteInt16(0x4020, 4, VarInt16 + 1);
TcClientSync.WriteInt32(0x4020, 6, VarInt32 + 1);
TcClientSync.WriteReal32(0x4020, 10, VarReal32 + 1.1);
TcClientSync.WriteReal64(0x4020, 14, VarReal64 + 1.11);

TcClientSync.WriteVar(".PLCBoolVar", VarBool);
TcClientSync.WriteVar(".PLCSIntVar", VarInt8 +2); 
TcClientSync.WriteVar(".PLCIntVar", VarInt16 + 2);
TcClientSync.WriteVar(".PLCDIntVar", VarInt32 + 2);
TcClientSync.WriteVar(".PLCRealVar", VarReal32 +2.1);
TcClientSync.WriteVar(".PLCLRealVar", VarReal64 +2.11);

// read again from PLC
VarBool = TcClientSync.ReadVar(".PLCBoolVar");
WScript.echo("VarBool = ", VarBool);

VarInt8 = TcClientSync.ReadVar(".PLCSIntVar");
WScript.echo("VarInt8 = ", VarInt8);

VarInt16 = TcClientSync.ReadVar(".PLCIntVar");
WScript.echo("VarInt16 = ", VarInt16);

VarInt32 = TcClientSync.ReadVar(".PLCDIntVar");
WScript.echo("VarInt32 = ", VarInt32);

VarReal32 = TcClientSync.ReadVar(".PLCRealVar");
WScript.echo("VarReal32 = ", VarReal32);

VarReal64 = TcClientSync.ReadVar(".PLCLRealVar");
WScript.echo("VarReal64 = ", VarReal64);

if (TcClientSync.ReadAdsState() == 5)
{
  WScript.echo("PLC is running!\nStop PLC.");
  TcClientSync.WriteAdsState(6);
}

 

Beispielprogramm ADS-Script-DLLSample01.zip, 'Windows Scripting Host' entpacken.