Suppose that you had an instrument that provided some sort of data on a regular basis and you wanted to update an Active Server Page with new data each time it was transmitted from the instrument.
Unfortunately Active Server Pages do not support Dynamic Data Exchange, so we cannot simply add DDE Commands to our VBScript. Instead we will use a compiled Visual Basic Program to call our ASP code with the data.
How to Use this Program
- Download and install the Project files.
- Copy the ASP files onto your Web Server.
- Set up WinWedge.
- Change the Com port and URL information in the Setup.ini file.
- Launch WinWedge (Activated).
- Launch Wedge2URL.exe.
- Transmit data from your serial Device.
- Your Default Web browser should open displaying your data. If this does not happen check the troubleshooting section of this page.
- PC running Microsoft Windows 3x/9x/NT/2000/XP
- ASP compatible Webserver e.g, Personal WebServer 4.0 or IIS 4.0 or later
- An available RS-232 Serial Port
- WinWedge v1.2 or later from TALtech, Inc.
- Compatible RS-232 Serial device
- Microsoft Visual Basic 6.0 or later (to view, modify and recompile project files)
- Internet Explorer 4.0 or later (recommended) or other Windows compatible Web Browser
How it Works
The Visual Basic program Wedge2URL establishes a DDE Link to WinWedge. Every time the data in WinWedge changes, the change is reflected in the VB Program and the new data is appended to a string (representing a URL) that looks like:
This string is then passed as part of a Shell command to launch the default web browser with the Specified URL. The ASP Code retrives the "Wedgedata=..." part and displays it on the page.
Steps for Setting Up WinWedge
Simply configure WinWedge to work with your device (Follow the Quick Set Up Steps at the front of your WinWedge Manual). Don't worry about trying to parse and filter your data, this will be done in the ASP code.
Note: Because WinWedge always behaves as a DDE Server regardless of which mode you choose, you can use the example below in Keystrokes mode, DDE Mode or Log to disk mode (Pro version only). This means that not only can you update your ASP Page but at the same time you can record your data in Excel, or notepad, or a log file!
The Setup.ini File
The format described here is an implementation of the ".INI File Format", as defined in the Microsoft Windows for Workgroups Resource Kit. An INI file is a text file divided into sections, each containing zero or more keys. Each key contains zero or more values.
[SectionName] keyname=value ;comment keyname=value, value, value ;comment
Section names are enclosed in square brackets, and must begin at the beginning of a line. Section and key names are case-insensitive, and cannot contain spacing characters. The key name is followed by an equal sign ("="), optionally surrounded by spacing characters, which are ignored. If the same section appears more than once in the same file, or if the same key appears more than once in the same section, then the last occurrence prevails. Multiple values for a key are separated by a comma followed by at least one spacing character.
The Setup.ini file for Wedge2URL looks like:
The URL should include the full http path to your asp file, the asp filename followed by a question mark ("?"). If you have only one field you can specify a variable name like "Wedgedata" above to represent the value of that field. If your have defined more than 1 field in WinWedge, you can either hardcode the variable names in the Visual Basic program, or reconfigure WinWedge to send just a single field of data and parse it out in your ASP code. See the section on Dealing with Multiple Data Fields for more information.
The Visual Basic Program (WinWedge to URL)
The code for the visual basic program is based on the WinWedge DDE Example for Visual Basic - Linking a VB Text Box to a WinWedge Data Field. At its most basic the Project consists of a only a single form and a module but, to make our example more useful, instead of 'hard coding' variables like the selected com port and the URL to send the data to, we added code to read these parameters from a setup.ini file. This method allows you to easily add more of your own settings and change variables without needing to recompile the program each time. In addition we added code to allow the program to be minimized to the system tray, since no user interaction is required.
The extra features add many lines of code that make it appear to be more complex than it really is so lets take a look at the just the key elements of the Program:
Sub Main() ' *** This routine launches Default Browser with Custom URL 'Declare Variables Dim ExecPath As String, strStart, nResult, MyURL$ ' Get the directory Path where this code is executing ' (To retrieve values from setup.ini file stored in same ' directory) ExecPath = IIf("/" = Mid(App.Path, Len(App.Path)), App.Path, App.Path & "\") ' Read URL value from setup.ini into MyURL$ variable MyURL$ = mfncGetFromIni("Startup", "URL", ExecPath & "Setup.ini") ' Append Wedge data to a string representing a URL: strStart = "Start.exe " & MyURL$ & Form1.Text1.Text ' (Start.exe is a program that is part of the Windows ' Operating system that allows you to run a program by its ' associated extension. MyURL$ is the main part of the URL ' Specified in setup.ini: ' e.g., "Http://www.website.com/myfile.asp?Wedgedata=" ' Form1.Text1.Text is the data from WinWedge. ' By concatenating all of these elements together we can use ' them in a shell command to launch the browser and open the ' page. 'Launch the Browser with the URL - vbhide hides the dos window ' that appears when start.exe is run nResult = Shell(strStart, vbHide) End Sub
Essentially, the only line of code that matters is the last line - we could hardcode the base URL here and shorten the code to just that line with the same result:
Sub Main_b() Shell "Start.exe http://www.website.com/myfile.asp?Wedgedata=" & Form1.Text1.Text, vbHide End Sub
But in so doing we would need to recompile the program if we needed to point to a different URL.
Note: If your device sends multiple fields of data you should still set up WinWedge for a single data field and then parse and filter using your ASP code
The ASP Code
All we are doing in our ASP code is retrieve the Wedgedata variable and display the data on the page:
<% @Language = VBScript %> <% ' declare variables Dim strWedgeData ' retrieve wedgedata information strWedgeData = Trim(Request.QueryString("WedgeData")) %> <!-- Display Data on page --> <HTML><BODY><H1>Here is your Wedge Data:</H1> <%= strWedgeData %> </BODY></HTML>
Dealing with Multiple Data Fields
If you need to parse several comma delimited fields of data from the "WedgeData" variable in your ASP code then you could use:
<% @Language = VBScript %> <% ' declare variables Dim strWedgeData, i Dim StartPos, MyVar, DelimPos Dim Myarray(3) ' Specify the number of fields you need to parse between the parenthesis 'retrieve wedgedata information strWedgeData = Trim(Request.QueryString("WedgeData")) ' How to separate multiple comma delimited fields from the single strWedgeData variable: ' Add Terminating delimiter MyVar = strWedgeData & "," ' starting position in the string - start at 1st byte StartPos = 1 ' scan until we reach the end of the string While StartPos < Len(MyVar) ' find the next comma delimiter DelimPos = InStr(StartPos, MyVar, ",") ' pull out a data point between the starting position and the position of the delimiter DataPoint = Mid(MyVar, StartPos, DelimPos - StartPos) ' update the starting position (skip over the delimiter) StartPos = DelimPos + 1 ' Field counter fCount = fCount + 1 ' save the current data point Myarray(fCount) = DataPoint ' go get the next point Wend %> <HTML><BODY><H1>Here is your Wedge Data:</H1> <% 'Loop through each record in the array and display the data For i = 1 to Ubound(Myarray) Response.Write("Field " & i & " = " & Myarray(i) & "<br>") next 'i %> </BODY></HTML>
If you do not want every field to be displayed use an If Statement to test the field number currently being processed, if you do not want to display that field then do nothing, otherwise display the field. For Example if you want to filter out field 3 then you could use the following code:
'Loop through each record in the array and display the data 'Unless it is field 3 For i = 1 to Ubound(Myarray) If i <> 3 then Response.Write("Field " & i & " = " & Myarray(i) & "<br>") End if next 'i
- Is WinWedge Activated?
- If so, is there any data in WinWedge?
- If not, refer to the WInWedge manual or Online Support Pages for Help
- Is Wedge2URL running?
- So you see data in this program?
- Do you have a web browser?
- Did you upload the ASP files to your webserver?
Wedge2URL doesn't run!
This program requires the visual basic runtimes. Download them now.
Download Vbrun60.exe (size: 1.34 MB)
For additional information, please see the following article in the Microsoft Knowledge Base:
TITLE: File VBRUN60.EXE INstalls Visual Basic 6.0 Run-Time Files
I can't open some of the project files!
Do you have Visual Basic 6 installed on your PC?
I get "Error 404 - File Not Found" errors in my browser!
- Did you upload the ASP Files to your webserver?
- Did you Modify the Setup.ini file to point to the correct file in the correct location?