Examples 4 Examples Also see about this 2 Reading and writing of PLC variables [ } 30] 4.1 Windows Scripting Host Load the PLC program into the local PLC on your PC and run the PLC program. Then call the script. After the communication channel has been opened, a check is made as to whether the PLC is in the RUN state. If not, the PLC is started. The next step is that all the PLC variables are read off and individually displayed. Then all the variables are incremented and are checked by reading off and displaying them again. The PLC is finally stopped. 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) TX1000 28 Version:
1.0 Description Source text Example 1: Windows Scripting Host [} 28] https://infosys.beckhoff.com/content/1033/ tcscriptdll/ Resources/12459716107/.zip Example 2: Visual Basic https://infosys.beckhoff.com/content/1033/ tcscriptdll/ Resources/12459720971/.zip Example 3: Active Server Pages [} 36] https://infosys.beckhoff.com/content/1033/ tcscriptdll/ Resources/12459711755/.zip