1. Select "DDE Server" from WinWedge "Mode" menu.
When the dialog box appears asking for a DDE Command Destination
Application, enter: "EXCEL" as the Application
Name and then enter: "SYSTEM" as the DDE
topic.
2. Select "Input Record Structure" in the "Define" menu
and define the structure of the input record(s) to WinWedge.
When you get to the final Window with the caption "Input
Record Definition Editor", enter the string: [RUN("GetSWDataAbove")] as
the Field Postamble DDE Command after the last data
field that you have defined. This is a DDE command that will
be sent to EXCEL after each data record is received by the
Wedge.
3. Set up the rest of WinWedge parameters and then
activate it.
1. Create or edit a macro
module and enter the following code in the module:
(To create a new module click on Insert > Module from the Menus in the Visual
Basic Editor Window.)
| |
Sub GetSWDataAbove()
Dim X As Long ' Dim all variables
Dim MyVar As Variant
Dim MyString As String
On Error Resume Next ' ignore errors
Application.DisplayAlerts = False '
turn off DDE warning messages
Sheets("Sheet1").Rows("1:1").Insert '
insert a row above row 1
X = DDEInitiate("WinWedge", "COM1") '
connect to WinWedge
MyVar = DDERequest(X, "Field(1)") '
get Field(1)
DDETerminate X ' terminate the DDE link
MyString = MyVar(1) ' convert to a string
Cells(1, 1).Value = MyString ' put value
in A1
End Sub
|
The example above sets up WinWedge to issue a DDE command
consisting of the Excel "RUN" command forcing
Excel to run the subroutine "GetSWDataAbove()" after
each data record is received from your serial device. The "GetSWDataAbove" subroutine
performs a DDERequest to WinWedge that returns the contents
of FIELD(1) to a variable named "WedgeData". Data
is inserted at the top of a row and moves all previous readings
down in the sheet sort of like a strip chart recorder. The
latest data is always in Cell A1 with all previous readings
below it scrolling down as each new reading is inputted.
The example above assumes that the open workbook contains
a worksheet named Sheet1.
The following example subroutine for Excel shows how to
insert data from
WinWedge at the bottom of a row. The code figures out where the bottom cell
is each time it is called so the spreadsheet does not have to keep track of
the bottom row with a memory variable. To use it enter the string: [RUN("GetSWDataBelow")] as
the Field Postamble DDE Command after the last data field that you have
defined.
| |
Sub
GetSWDataBelow()
Dim X As Long ' Dim all variables
Dim MyVar As Variant
Dim MyString As String
On Error Resume Next ' ignore errors
Application.DisplayAlerts = False ' turn off DDE warning
messages
X = DDEInitiate("WinWedge", "COM1") '
connect to WinWedge
MyVar = DDERequest(X, "Field(1)") ' get Field(1)
DDETerminate X ' terminate the DDE link
MyString = MyVar(1) ' convert to a string
' find the row number of the last empty cell at the bottom
of Column 1
X = Sheets("Sheet1").Cells(65000, 1).End(xlUp).Row + 1
Cells(X, 1).Value = MyString ' put value in the last row
End Sub |
|