In the DM2000 framework, ActiveX - based applications typically are special HTML documents running in the Minibrowser window. These applications are compact and may be created by end users since they do not require complex development environments like Delphi or Visual Studio. The only essential issue is instrument interface drivers: if your device has no standard interface or ready-for-use driver, this means that you have to create driver yourself. Fortunately, the most of measurement instruments equipped with standard RS-232C interface, and appropriate ActiveX control (cportlib.ocx) may be downloaded from this website.
Notice: at present, cportlib.ocx control is beta version! Although it works well in my applications, it was not properly tested on different platforms and may have bugs. I plan that next official release of DM2000 will include full-featured set of ActiveX components for RS232 interface and other applications (check news page for more information about latest updates). Besides, you may use third-party RS232 ActiveX controls with DM2000.
To illustrate the process of the creation of sample ActiveX - based applications, this page discusses detailed step-by-step instructions how to write simple applet for real-time data acquisition (Keithley 2182 nanovoltmeter used as an example of typical measurement instrument with RS-232C port). Make a study of these code snippets to familiarize with ActiveX scripting, use them as a template for your own applications and you will see that with DM2000 data acquisition is as easy as 1-2-3!
Step 1 - initial preparations
To begin with, you should properly install DM2000 application and CPortLib.ocx control as described in the "readme" files and other online instructions (don't forget to register ActiveX control). Since DM2000 shares security zone settings with Microsoft Internet Explorer, please ensure that execution of ActiveX controls is enabled. Use following HTML page template for your applications:
<html> <head> <title>Keithley 2182 test</title> <script language="VBScript"> </script> </head> <body onunload="Port.Active=false"> <h3>Keithley 2182 test</h3> <form name="Frm"> </form> <object classid="clsid:A9F50D64-52CD-4002-AA48-CF459297034D" id="Port" width="200" height="100" style="visibility: hidden"> <param name="Visible" value="false"> </object> </body> </html>
Step 2 - planning user interface
In order to control data acquisition process, you may require following set of elements:
Every button has a name and associated event handler (which is actually script procedure). Following HTML tags that define UI controls should be placed between <form> and </form> tags as shown below:
<form name="Frm"> <input language="VBScript" type="button" value="Show" name="ShowHideBtn" onclick="ShowHide()"> <input language="VBScript" type="button" value="Open" name="OpenCloseBtn" onclick="OpenClose()"> <input language="VBScript" type="button" value="Trigger" name="TriggerBtn" onclick="Trigger()"> <br><input type="checkbox" name="AutoCb">Trigger automatically </form>
In addition, you should insert some container tag (e.g. <h3>) after form which will display current instrument readout:
<h3 id="Display"> </h3>
Step 3 - writing script code
Now it's time to animate your application! Place following script code between <script> and </script> tags:
<script language="VBScript"> dim Win set Win=window.external.CreateDocument("") Win.WindowCaption="Data Window" Win.IsRecording=true Win.Worksheet.ColumnLabels(1)="Time, S" Win.Worksheet.ColumnLabels(2)="Voltage" Win.Plot.XAxis.AutoScale=false Win.Plot.XAxis.Min=0 Win.Plot.XAxis.Max=1000 Win.Plot.YAxis.AutoScale=true Win.Plot.Series(0).XColumn=1 Win.Plot.Series(0).YColumn=2 sub ShowHide() Port.Visible=not Port.Visible if Port.Visible then Port.style.visibility="visible" Frm.ShowHideBtn.value="Hide" else Port.style.visibility="hidden" Frm.ShowHideBtn.value="Show" end if end sub sub OpenClose() if Port.Active then Frm.OpenCloseBtn.value="Open" Port.Active=false else Frm.OpenCloseBtn.value="Close" call Port.Open(3,9600,0,8,0) call Port.Write(":INIT:CONT OFF;:ABORT;:TRIG:COUN 1;" & vbCr) call Port.Write(":TRIG:DEL 0;:TRIG:SOUR IMM;:INIT;" & vbCr) end if end sub Buffer="" StartTime=Now sub Port_OnRead(Str) Buffer=Buffer+Str if InStr(buffer, vbCr)>0 then Display.innerHTML=Buffer if IsNumeric(Buffer) then Win.Container.AddItem(DateDiff("S",StartTime,Now) & " " & CDbl(Buffer)) Win.Container.Modified=true Win.Plot.Series(0).AddPoint end if Buffer="" if Frm.AutoCb.checked then call SetTimeout("Trigger", 300) end if end sub sub Trigger() call Port.Write(":SENSE:CHAN 1;:READ?" & vbCr) end sub </script>
Global statements used to create and reference data window required to accumulate and display voltmeter readouts (window.external always holds reference to the IDMApplication interface). Notice that this window is created and configured when page is loaded without any user action! Code within "sub".."end sub" keywords are procedures. Procedures ShowHide(), OpenClose() and Trigger() are invoked by appropriate buttons (notice that procedure Trigger() also called by timer). Port_OnRead(Str) called implicitly by ActiveX control when data arrived from the RS232 port. Since data string may be broken at arbitrary position, some kind of bufferization used to determine actual termination of the transmission. IsNumeric(Buffer) call used to ensure data integrity since usually there's no any validation in the device communication protocol and sometimes data may be corrupted.
Of course, you need to know logical number of the COM port and communication settings used in Port.Open(...) call, and, in addition, consult instrument manual for details about device initialization, trigger and output data format (probably you will have to parse output string to extract data). Port.Open() parameters listed below (see also cportlib sources for more information):
The result: working data acquisition application (see photo)
If you are interested in more details about ActiveX scripting, use DHTML authoring guides and VBScript references from Microsoft (bundled with MS products or available online at their website as a part of MSDN or downloadable archives).