![]() |
|||||||||||||||||
|
|
|||||||||||||||||
|
This document is a continuation of the Charting in Web Pages paper. Do you have a need for several web-pages each containing charts of different tag data? If the answer is yes, then you might not need to create any more than 1 page! Let's look at an example: Lets assume that we have a page named/located: yourcomputer.com/myChartPage.asp We are going to pass-in an array of tagnames, for examples: yourcomputer.com/myChartPage.asp?tags=simulation.random|simulation.register_i4|simulation.register_r8 Our Webpage will then need to dynamically subscribe to these tags, as well as log them to the Chart. What needs to be dynamically created in our web-page? Lets look at how this can be accomplished. First, copy the file you created above and give the new file the same name but with the ".ASP" file extension instead. This will be file you now work from. Step 1 - Defining Global Variables and Parsing the Querystring At the top of the web-page, above the HTML code, insert the following lines of ASP Code: <%@ Language="vbscript" %> This will create essentially 2 variables: Step 2 - Subscribing to these Tags and handling their values changing Begin by locating the "fnInit()" function and replacing it with the following: function fnInit() The above code will iterate through the Tags array, creating a line of Javascript code that will subscribe to the Tag as defined in the array. Now to change the event handler. Locate the "fnRefreshResult()" function and replace it with the following function fnRefreshResult() Step 3 - Modifying the Chart ActiveX control to make it more dynamic This part is not quite as easy as the previous changes, but is still not too difficult. First of all, the ActiveX properties etc. are stored in a LOT of HTML code which is downloaded to the Browser. We need to specifically modify these lines so that they are dynamically created and sent to
the browser. First Step - Removing unwanted Channels Look in your HTML code and you will find a LOT of lines of code that start with the following: <param name="Channel0. ... and the line continues... Essentially this is where each channel is being configured. Each line starting out like this is configuring a specific property for this specific channel. So we need to first find all the
"channel0" lines and keep them safe... any lines that begin with "channel1" or higher, we need to delete. Essentially we want to keep all the "channel" lines of code and delete all the others. Once all of the duplicate Channel information is removed, proceed to the second step. Second Step - Creating the Chart's Channels dynamically Removing the duplicate channnel information was the hard part, from here on it is much easier. First we need to tell the ActiveX control HOW MANY channels the chart will have. Locate the following line of code: <param name="ChannelCount" value="4"> ... and modify it as follows: <param name="ChannelCount" value="<%=UBound(Tags)%>"> Next, we need to configure the channels. We will insert the following ASP code ABOVE the first <param name="Channel0. line: <%For i = 0 To UBound(Tags) - 1 %> Now scroll to the last <param name="Channel0 line and add a line beneath it containing the following code: <%Next %> You now need to go in to all the lines in between the "FOR..NEXT" loop and modify each one so that the <param name="Channel0 is replaced with <param name="Channel<%=i%>. A simple Search & Replace is adequate here. All of these changes will now dynamically configure a Channel for each Tag in our Array, but
with the channels sharing the same settings! As you scroll through the HTML code for the Channel settings, you will notice a variety of settings that you might wish to modify. This is up to you. Feel free to experiment!
However this example is now complete. Last Step - Testing Assuming that there are no typo's or errors in your webpage, you should be able to test it by
passing in a number of arguments to specify that Tags to subscribe to, and possibly the OPC Server too. You could of course pass-in much more information too such as a chart title and other information - feel free to explore.
The following examples use the webpage we created: Link: http://temp.softwaretoolbox.com/opcwebclient3demo/plotpack.asp?
Link: http://temp.softwaretoolbox.com/opcwebclient3demo/plotpack.asp?
Link: http://temp.softwaretoolbox.com/opcwebclient3demo/plotpack.asp?
Downloads
|
|||||||||||||||||
|
Copyright Software Toolbox, Inc., 1996-2004, All Rights Reserved Worldwide. |
|||||||||||||||||