Suppose that you had an instrument that can be controlled by sending commands to it via a serial port, but you need to be able to control that device from anywhere in the world through the internet simply by using an HTML form. The technique outlined below makes this possible and if you use it in conjunction with the Wedge2URL program you can even display any data that is returned by the device on the same web page.
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 and call it from our ASP code with the data to be transmitted.
- Download and install the Project files.
- Copy the ASP files onto your web server.
- Set up WinWedge
- Change the COM port information in the Setup.ini file
- Launch WinWedge (Activated) on the PC that has the Serial Device connected to it (This must be the web server*).
- Open Multi_Field.asp through HTTP in your web browser from any PC that has access to it.
- Type in the data to be sent out the serial port and click on send.
- If everything works as it should then the device will receive the command and respond appropriately. If this does not happen check the troubleshooting section of this page.
* You could attach the serial device to any PC on your network and use TCP-Com to share the serial port as a TCP/IP Port, then run TCP-Wedge on the web server instead of WinWedge. Minor changes to the VB Program would be required - the DDE Application Name and Topic would need to be changed to work with TCPWedge instead of WinWedge.
- PC running Microsoft Windows 9x/NT4/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.
- TCP-Wedge (optional) and FREE with WinWedge Pro.
- TCP-Com (optional) and FREE with WinWedge Pro.
How it Works
When the user opens the ASP page in their browser there is a text box (part of an HTML form) that allows you to enter the command to be sent to the device. Commands should be entered in the format:
Where x represents an ASCII control character such as ESC (ASCII 27) or Carriage Return (ASCII 13). for Example, you may need to send ESC P to a device asking it to print the current reading. You would use:
If you needed to send S<CR><LF> you would use:
When the form is submitted, the specified command is passed on the command line to the Visual basic program ASPSendOut. ASPSendOut establishes a DDE Link to WinWedge and uses the 'SendOut' DDE Command to pass that command to WinWedge. WinWedge sends the command out the serial port to the device. Assuming you are also running Wedge2URL then any returning data will be displayed in the web browser along with the form again which gives you the opportunity to send the next command to your device.
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.
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 ASPSendOut looks like:
You can also use the same Setup.ini file as ASPSendOut Program.
The Visual Basic Program (ASPSendOut)
The code for the visual basic program is based on the WinWedge DDE Example for Visual Basic Sending DDE Commands to WinWedge from a VB Application. 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 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.
There is no need to display a screen shot of the form as it is never displayed on screen. Instead all we run is the Main Subroutine.
'checks for command line arguments, if found it will send the passed ' value out the serial port, if not an error message is displayed 'Declare Variables Dim str2Send As String 'Get data inputted on the command line str2Send = Command$ If Len(str2Send) Then ' by referencing the form an instace of it is created in memory (though not ' on screen, the onload event of the form will fire and the DDE Link to WinWedge ' Will be opened and data transferred Form1.Text1.Text = str2Send Unload Form1 Else MsgBox "No command specified:" & vbCrLf & "e.g. ASPSendOut 'Print',13", vbExclamation + vbOKOnly, "Error" End If End Sub
The ASP Code
The ASP Code below is a modification of that used with Wedge2URL. Not only will it display wedge data submitted from Winwedge but it also displays an HTML Form that allows you to enter data to send to WinWedge through ASPSendOut. The New Code is presented in bold Text. It requires you to have the Windows Script Host installed on the web server.
<% @Language = VBScript %>
<% 'declare variables Dim strWedgeData, WshShell, str2Send Dim StartPos, MyVar, DelimPos Dim Myarray(3) 'Specify the number of fields you defined in WinWedge between the parenthesis 'retrieve wedgedata information strWedgeData = Trim(Request.QueryString("WedgeData")) 'retrieve data to send out the serial port, if any str2Send = Trim(Request.QueryString("strToSend")) 'How to separate multiple comma delimited fields from the single strWedgeData variable: 'Add Terminating comma 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 data point Wend 'set default values if str2Send = "" then str2Send = "'test',13" if str2send = "" then strWedgeData = "No Data available at this time" 'run ASPSendOut set WshShell = CreateObject("WScript.Shell") WshShell.Run("c:\ASPSendOut.exe " & str2Send) set WshShell = nothing %> <HTML><BODY><H1>Current Wedge Data:</H1> <% Dim i '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 %> <form Action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="GET"> <Input name="strToSend" value="<%= str2Send %>"> String to Send out the Serial Port <BR> <Input type="Submit" name="Submit" Value="Send"></form> </BODY></HTML>
- Is WinWedge Activated and set up correctly for your device on the right com port?
- Did you upload the ASP files to your wbserver?
- Did you specify a valid Command for your device?
- Try troubleshooting by Activating WinWedge in Virtual Instrument mode: any data submitted for sending out the serial port should appear in the WinWedge Window. Verify that it does and that the command appears correctly.
- Is the Windows Script Host installed.
- Did you modify the code to point to YOUR file locations?
- Did you setup permissions on your webserver for running executables?
- Did you modify the Setup.ini file to point to your com port?
- Can you get the code to run Notepad instead of ASPSendout?
Unfortunately this is not the sort of application that is likely to run "right out of the box" and a lot of tweaking may be required. If you cannot make it run after trying all of the above, then you may be able to use PERL instead of ASP. A similar program for Perl can be found here that would not take long to adapt for this application.
ASPSendout 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?