Issue 13: Feeding Laboratory Instrument Data into Excel, VB Programs, etc
WINDMILL NEWS: MORE FREE TECHNICAL SUPPORT ON THE WEB
We are striving to offer the best possible technical support for our free Windmill software. To this end we have improved our web-based support offerings.
We've created a library of serial instrument setup files at
http://www.windmill.co.uk/serial_driver.html. You can download a setup file and send it directly to your
instrument: saving time otherwise spent filling in dialogue boxes.
We hope to expand this library. If your instrument is not yet represented, and you would like to contribute to our library project, please e-mail your *.aid file and details of your instrument to [email protected]. (If your instrument plugs into your computer's COM port and communicates using ASCII messages, you can control it with the free Windmill software and use the library files.)
- We've extended our technical support page. When people ask for help we've been adding the questions and answers to http://www.windmill.co.uk/techsupp.html
- We've added more information to our DDE (dynamic data exchange)
Help. Go to http://www.windmill.co.uk/help.html
and select wmdde.zip.
Incidentally, we're interested to hear your comments on the Help files - if you can think of any improvements or anything we've left out please fill in the form on the Help web page.
We hope you find the new and improved pages useful. Don't forget that you can also obtain the full, printed, manuals from our shop.
Finally, if you can't find what you're looking for on the web or in the manual, please fill in our technical support form or telephone us on +44 (0)161 833 2782.
Windmill software reads data from instruments and devices connected to your PC. You could use it, for instance, to monitor and control temperatures. We have a range of drivers for many types of hardware, and our RS232 instrument driver is now free to our newsletter subscribers.
You may want to use the data you get through Windmill in other applications - perhaps to average readings over time or a number of sampling points; to calculate control outputs; or to put data directly into reports and databases. You can either collect data with the Windmill Logger, and after collection has finished import it into your spreadsheet or database. Alternatively you can transfer data as it arrives, using dynamic data exchange. The simplest way to do this is to use the free Windmill DDE Panel to act as a gateway to get and send data values from your application. This works well for Office programs such as Microsoft Excel, Access or Word.
You can also use DDE if you are writing your own application code, in say Visual Basic, C, or another application generator. Alternatively you may wish to use Windmill's IML Toolkit to send and get data values from the hardware directly. Details of the IML Toolkit are at http://www.windmill.co.uk/tools.html
Using dynamic data exchange to communicate between applications, the Windmill DDE Panel lets you copy and paste live data into Excel, Access or Word. For more sophisticated tasks, you can use macros.
Analysis and control with an Excel spreadsheet
Using Microsoft Excel to handle incoming values from data acquisition instruments is beneficial because of the spreadsheets analytical capabilities - for statistical analysis, graphing functions including X-Y plotting, and for calculating control values to send back to the hardware.
To try out data acquisition into Excel
- Load Windmill DDE Panel and select the hardware setup (your *.ims file).
- Load Excel with a clean sheet, and then select menu item Insert.Macro.Module (Excel 5 and 95) or Tools.Macro.Visual Basic Editor (Excel 97) to get to the VBA editor.
- To read data from one channel connected to the Windmill DDE
Panel and place it into a cell in the spreadsheet, create the
following VBA code.
Sub DDEread() 'Read data value from channel "Chan_00" in Windmill DDE 'Panel and write the result in cell A1 'Opens a DDE conversation with the Windmill DDE 'Panel using the Service Name "Windmill" and the 'Topic Name "Data" ddeChan = Excel.DDEInitiate("Windmill", "data") 'Requests data from a channel called Chan00. myData = Excel.DDERequest(ddeChan, "Chan_00") Sheets("sheet1").Select Cells(1,1).Value = myData 'Closes the DDE conversation. Excel.DDETerminate (ddeChan) End Sub
To send data to an analogue or digital output channel, create
the following VBA code.
Sub DDEpoke() 'Send data in Sheet1.Cell.A1 to channel "Blackb_1" in 'Windmill DDE Panel 'Opens a DDE conversation with the Windmill 'DDE Panel using the Service Name "Windmill" 'and the Topic Name "Data" ddeChan = Excel.DDEInitiate("Windmill", "data") 'Now send the data. 'Note the 3rd parameter MUST be a cell or range of 'cells which contain the data Excel.DDEpoke ddeChan, "Blackb_1", Range("a1") 'Closes the DDE conversation. Excel.DDETerminate (ddeChan) End Sub
Issue 16 of Monitor gives details of charting data from Excel.
Over the next few months we're including a "VB Corner". This section will give you hints, tips and code samples for using Windmill applications and data from Visual Basic programs. (You don't need to do any programming to use Windmill, but if you want to create your own Visual Basic applications you will find this section useful.)
Using DDE to get Data from your Instrument into your VB Program
This month we discuss how to get data from your instruments, via the Windmill software and dynamic data exchange, into your VB program for analysis, processing and so on.
Hint: When you're trying out communication between your software and Windmill - use the free Software Signal Generator. This generates data quickly and without the need for additional hardware. The Software Signal Generator (the SIGGEN device) is supplied with all versions of Windmill.
You can download the project and code for this month's VB corner.
We use a label control on the VB form with the following properties:
Name laDDEmessage Visible False
The subroutines that do the work are as follows.
When the VB application loads, we need to open the DDE conversation with the DDE Panel application. You should open the conversation once, when you load, because repeatedly opening and closing the conversation causes a memory leak which will eventually crash your application
Private Sub Form_Load() ' the default DDE name for the Windmill DDE Panel is Windmill laDDEMessage.LinkTopic = "Windmill|Data" laDDEMessage.LinkMode = 2 End Sub
Here Windmill is the default name given to the Windmill DDE Panel for its DDE conversations. You can change this in the Panel by selecting the DDE item from the File menu.
When the VB application terminates we can tidy up by resetting the LinkMode to close the DDE conversation.
Private Sub Form_Unload(Cancel As Integer) laDDEMessage.LinkMode = 0 End Sub
The Receiving and Sending of data values is done as follows:
Private Function GetIMLdde(IMLChanName$, ReplyMessage$) GetIMLdde = False laDDEMessage.LinkItem = IMLChanName$ On Error GoTo GetIML_Error laDDEMessage.LinkRequest DoEvents GetIMLdde = True ReplyMessage$ = laDDEMessage.Caption GetIML_Exit: Exit Function GetIML_Error: Resume GetIML_Exit End FunctionAnd:
Private Function SendIMLdde(IMLChanName$, DataMessage$) As Integer SendIMLdde = False laDDEMessage.LinkItem = IMLChanName$ laDDEMessage.Caption = DataMessage$ On Error GoTo SendIML_Error laDDEMessage.LinkPoke DoEvents SendIMLdde = True SendIML_Exit: Exit Function SendIML_Error: Resume SendIML_Exit End Function
Note that the routine to get data from an IML input channel uses the .LinkRequest method, while the routine to send a data string to an IML output channel uses the .LinkPoke method.
That's the end of this month's VB Corner. Our other Visual Basic articles are in:
- Monitor # 14, VB Programming Tools
- Monitor # 15, Controlling Windmill programs from Visual Basic code
- Monitor # 16, Using an HTML page to generate the user interface for your Visual Basic application
- Monitor # 18, Displaying data from Windmill in an HTML page
- Monitor # 21, Other Visual Basic resources
Do you have a comment or suggestion for this newsletter? E-mail the editor - Jill - at [email protected]
Copyright 1999 Windmill Software Ltd. All rights reserved. This newsletter may be distributed in its entirety. However, individual sections may not be reproduced without the prior written agreement of Windmill Software Ltd.
To receive Monitor every month please fill in your email address below. We will not pass your address to any third parties.