W&T Interfaces
for TCP/IP, Ethernet, RS-232, RS-485, USB, 20mA
Glass and plastic fiber optic, http, SNMP, OPC, I/O digital, I/O analog, ISA, PCI, ...?
      Products
Home Contact   Distributors worldwide
Languages:
DE

US

ES

IT

RU
Web-IO Universal
Digital
Analog
Web-IO application-ready
Monitor climate
Alarm Reporting Center
Web-Count / S0 acquisition
IP monitoring
Data Server
Motherbox 2
pure.box 2
Network Memory
TCP/IP-Ethernet servers
Com-Server (serial)
USB Server
Serial interfaces
USB, RS232, RS485, 20mA
Isolators & fiber optics
USB, RS232, RS485, 20mA
PC cards
PCI Express, PCI and
ISA bus
...
Printer interfaces
Accessories
Downloads
Old
Shopping basket Your shopping basket

 
      Technical knowledge
Books, articles, glossaries...
Technical background info
Applications for Com-Server,
USB Server
, Web-IO,
Web Thermometer,
Motherbox and pure.box
 
Application for the Web-IO Digital:

Automated switching with VBScript and batch jobs




 Additional links: Product overview Application overview Print version


In many smaller switching tasks it is not worth the effort to create special application software or purchase expensive automation tools. Here it’s enough to initiate the desired switching operation by simply clicking on an incon or entering a command. By using the Web-IO Digital and short VBScripts you can implement such solutions with just a few lines of commands.

.

VBScript is an easy-to-program interpreter language supported by Windows 2000, XP and Vista. As the name (Visual Basic Script) implies, the syntax of VBScript is derived from Visual Basic. No special development environment is required to create VBScripts - all you need is a text editor. We recommend the free PSPAD editor (www.pspad.com), which has syntax coloring for VBScript. When saving VBScripts the file extension ".vbs" is used.

The examples below show how VBScript and the Web-IO interact.


You don’t have a Web-IO® yet but would like to try the example out sometime?

No problem: We will be glad to send you the Web-IO Digital 2xInput, 2xOutput at no charge for 30 days. Simply fill out a sample ordering form, and we will ship the Web-IO for testing on an open invoice. If you return the unit within 30 days, we will simply mark the invoice as paid.

To sample orders   To sample orders

Preparations
You have already provided your Web-IO Digital

1. Set an output using VBScript

When the following script is invoked, Output 0 on the Web-IO having IP address 10.40.22.101 is set.

' VB Script Document
option explicit

Dim objHttp
Set objHttp = WScript.CreateObject("WinHttp.WinHttpRequest.5.1")
If objHttp Is Nothing Then Set objHttp = WScript.CreateObject("WinHttp.WinHttpRequest")
objHttp.Option(4) = 256 + 512 + 4096 + 8192
objHttp.SetTimeouts 0, 5000, 10000, 10000
objHttp.Open "GET", "http://10.40.22.101/outputaccess0?PW=&State=ON&", FALSE
objHttp.setRequestHeader "User-Agent", WScript.ScriptName
objHttp.Send ""
If Not (objHttp.statusText = "OK") Then
  WScript.Echo "Error: " & objHttp.statusText
  WScript.Quit 1
Else
  WScript.Echo objHttp.ResponseText
End If

The core of this script is the WinHttp object, which is used to send commands to the Web-IO. The actual command is passed using objHttp.Open.

http://10.40.22.101/outputaccess0?PW=&State=ON&  specifies that Output 0 on Web-IO 10.40.22.101 is to assume the ON state

objHttp.ResponseText reads in the response from the Web-IO. For command outputaccess the Web-IO returns a string consisting of the word output, a semicolon and the output status.

Example output;1

A detailed description of the possible Web-IO commands can be found in the manual for the Web-IO starting on page 102.


2. Invoking VBScripts from batch jobs

Batch jobs under Windows were originally intended for automatically running Windows commands. A classic example is the Autoexec.bat in older DOS environments. A list of commands is entered in the batch file which are processed sequentially when the list is opened.

In Windows systems this means you can automate scripts and the opening of programs. If for example you want to switch outputs on different Web-IOs with a call, this can also be done using a batch job.

The corresponding names of the VBScripts need to be written below each other in the batch file. In the case of scripts like the one above, you need to create a separate script for each switching operation.

This is why in batch jobs it makes more sense to create a universally usable script which when it is invoked is told using additional parameters what the switching task consists of. In the following VBScript you can pass these parameters to it when invoked:

  • IP
: IP address of the Web-IO
  • PORT
: TCP port of the Web-IO
This parameter is optional; if it is not transmitted, the script uses Port 80
  • PW
: Administrator or operator password for the Web-IO
This parameter is optional; if it is not transmitted, the script runs without a password
  • MASK
: indicates in hex format which outputs are supposed to be set
This parameter is optional; if it is not transmitted, the script runs using all outputs
  • STATE
: indicates in hex format to which state the outputs are supposed to be set

The script invocation looks as follows:

setoutput.vbs IP=<IP address> [PORT=<portno.>] [PASSWORD=<password>] [MASK=<hex value>] STATE=<hex value>

' VB Script Document
option explicit

Dim objArgs, strArg, strArgall
Dim IP, PORT, PASSWORD, MASK, STATE, URLStr
Dim objHttp
Set objArgs = WScript.Arguments

'# Make sure that script starts as console application (best way "cscript //h:cscript")
Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
If Right(WScript.FullName, Len(WScript.Fullname) - Len(WScript.Path) -1) _
     = "WScript.exe" Then
  For each strArg in objArgs
    strArgall = strArgall & " " & strArg
  next
  WshShell.Run "cmd /k cscript " & Chr(34) & WScript.ScriptFullName _
   & Chr(34) & strArgall
  WScript.Quit
End If

'# Check if there are Parameters
If  WScript.Arguments.count < 1 Then
  WScript.Echo "***********************************"
  WScript.Echo "* Not enough arguments *"
  WScript.Echo "***********************************"
  WScript.Echo ""
  WScript.Echo "Syntyx: setoutput.vbs IP=<IP address> [PORT=<portno.>] _
               [PASSWORD=<password>] [MASK=<hex value>] STATE=<hex value>"

  WScript.Quit
End If

'# Read the Parameters
for each
strArg in objArgs
  If Left(strArg,3) = "IP=" then
    IP = Mid(strArg, 4, Len(strArg) - 3)
  End If

  If Left(strArg,5) = "PORT=" then
    PORT = Mid(strArg, 6, Len(strArg) - 5)
  End If

  If Left(strArg,9) = "PASSWORD=" then
    PASSWORD = Mid(strArg, 10, Len(strArg) - 9)
  End If

  If Left(strArg,5) = "MASK=" then
    MASK = Mid(strArg, 6, Len(strArg) - 5)
  End If

  If Left(strArg,6) = "STATE=" then
    STATE = Mid(strArg, 7, Len(strArg) - 6)
  End If
Next

'# Mount the command String
If IP <> "" then
  URLStr = "http://" & IP
else
  WScript.Echo "***********************************"
  WScript.Echo "*    Not enough arguments : IP    *"
  WScript.Echo "***********************************"
End If

If PORT <> "" then
  URLStr = URLStr & ":" & PORT
End If

URLStr = URLStr & "/outputaccess?PW=" & PASSWORD & "&"

If MASK <> "" then
  URLStr = URLStr & "Mask=" & MASK & "&"
End If

If STATE <> "" then
  URLStr = URLStr & "State=" & STATE & "&"
else
  WScript.Echo "***********************************"
  WScript.Echo "*  Not enough arguments : STATE   *"
  WScript.Echo "***********************************"
End If

'# Send the Command String via HTTP object
Set
objHttp = WScript.CreateObject("WinHttp.WinHttpRequest.5.1")
If objHttp Is Nothing Then Set objHttp = WScript.CreateObject("WinHttp.WinHttpRequest")
objHttp.Option(4) = 256 + 512 + 4096 + 8192
objHttp.SetTimeouts 0, 5000, 10000, 10000
objHttp.Open "GET", URLStr, FALSE
objHttp.setRequestHeader "User-Agent", WScript.ScriptName
objHttp.Send ""
If Not (objHttp.statusText = "OK") Then
  WScript.Echo "Error: " & objHttp.statusText
  WScript.Quit 1
else
  WScript.Echo objHttp.ResponseText
End If

After the selected action has been performed, the script returns the status of the outputs.

e.g. output:0100

The status message consists of the word output, a semicolon and the output status in hex format.

TIP: The Windows Script Host (WSH) is responsible for running VBScripts; WSH is present in two variants on every Windows PC. The variants Wscript and Cscript differ mainly in how the data are output. Unless otherwise configured, the scripts are processed using Wscript, and text messages are output in a Windows dialog box. The disadvantage to this is that the user has to acknowledge each message in order for the script to continue. This type of processing is undesirable for use in batch jobs.

By entering the command wscrit //H:cscript, Cscript is defined as the standard Script Host. Cscript returns all messages in a DOSBOX and does not wait for confirmation.

The script shown above checks which Script Host is active, cancels if Wscript is active and restarts using Cscript.

Still, to ensure that the script can run faster, it is recommended that you switch to Cscript from the outset.


 

Additional programming examples for socket programming can be found on the Tool pages for the Web-IO. A detailed description for the socket interface of the Web-IO Digital models can be found in the reference manual.

To sample orders   To sample orders Download program example   To download area

 
    Additional application examples for Web-IO Digital
Web techniques
     
     
     
     
  Your own web pages
       
        PHP and AJAX - dynamic web pages also for multiple Web-IOs
        Mashup web pages - displaying values in Google Maps
        Java-Applet - use the integrated applet
        Java-Applet - Example: display in- and outputs
        Java-Applet: Example: display in- and outputs and control the outputs
        Java-Applet - Example: display counters
        Java-Applet - Example: Open doors and switch lights from the browser
        Web-IO with iPhone: visualize and control
        Web-IO with iPhone example: control shutter blinds
        Web-IO with iPhone example: monitor room climate
        Web-IO with iPhone example: display measurement values
System integration
     
     
     
     
     
      Box-to-Box
Data acquisition
     
      FTP data logger - example
Timer
     
      CRON timer (Linux)
      Task planner as timer
Individual programming
     
      Visual Basic.Net 2005/2008/2010
      Visual Basic.Net 2005/2008/2010 with WuTdevice.dll
      Visual C++
      Visual C#
      Visual C# with WuTdevice.dll
      Visual C++ (Linux with QT-Designer)
      Visual Delphi
      Visual Delphi.Net (2005)
      Lazarus / FreePascal
      Java
      control using VBScript
Web-IO system
     
     
      Motherbox - Access multiple Web-IOs
      Motherbox - Logically link Web-IOs
      Limit monitoring
  Web-IO - Options for network linking
       
        DSL
        UMTS/GPRS/mobile phone network
        Satellite radio

 
  • Mister Wong
  • Google Bookmarks
  • Twitter
  • Facebook
  • Digg
   Imprint
We are here for you personally! Wiesemann & Theis GmbH Tel.: +49 202/2680-110 (M-F 8:00 - 5:00)
Porschestr. 12 fax: +49 202/2680-265
42279 Wuppertal Individual e-mail

© Wiesemann & Theis GmbH, subject to error and alteration: Since we can make errors, none of our statements should be used without verification. Please report any mistakes or misunderstandings so that we can be aware of them and respond appropriately as quickly as possible.