The Excel VBA macro language has a function
called "SetLinkOnData" that can be used to configure Excel to automatically
run a
subroutine whenever data from a DDE Server is updated. In the previous example
we showed
how to configure the Wedge to send a command to Excel to force it to run
a macro after
each data record is received from a device on a serial port. This example
shows how
to use the Excel SetLinkOnData method instead of having the Wedge send a
command to Excel
to trigger a macro to run.
The two techniques are similar in that the end result is
that after each data record is received by the Wedge, Excel automatically runs a macro
that grabs the data from the Wedge and does something with it. The difference between them
is simply that in the previous example the Wedge triggers the macro to run whereas in this
example Excel automatically runs the macro with no coaxing from the Wedge.
One of the benefits of the following method is that the
Wedge does not have to be in "DDE Server Mode" in order to have Excel run the
macro after each data record from the Wedge. Although the Wedge has an explicit "DDE
Server Mode", it is actually a DDE Server no matter what mode it is
in ("Send Keystrokes", "Log To Disk" or "DDE Server" modes). The
reason that the Wedge has a DDE Server Mode at all is so that you can configure it to send
a DDE command to another application after each input. Suppose that you wanted to log all
data from the Wedge to a disk file and pass the data to Excel via DDE in real time.
You could set up the Wedge in Log To Disk mode and use the SetLinkOnData method in Excel
to trigger a macro that would pull the data from the Wedge into a spreadsheet.
Another benefit of this method is that the data from the
Wedge will be transferred to Excel slightly faster than it would if the
Wedge were
sending a command to Excel after each input.
In addition to demonstrating the SetLinkOnData method in
Excel, the following macros also show how to launch and activate the Wedge automatically
when you open up your spreadsheet as well as how to quit the Wedge automatically when you
close your spreadsheet.
To use the following macros, set up WinWedge to
work with your instrument by choosing the correct serial communications parameters
and
defining the input data record structure to fit the data that is returned
from your serial
device. If you set up the Wedge in DDE Server mode, make sure that you do
not have any
"Field Postamble DDE Commands" defined. Next, activate the Wedge
in Test Mode,
switch to Excel and enter the following macros into a module in your Excel
spreadsheet.
(You may have to modify the values for some of the Global constants as described
in the
comments in the subroutines.) After you have entered the following subroutines,
save your
spreadsheet and close it. Finally, re-open your spreadsheet and start collecting
data. The
Wedge should automatically load and activate itself when you open the sheet. |