TALtech Logo
search
Products Support Resources Free Software
TALtech Home:  Support:  WinWedge Support:  DDE and the WinWedge:  WinWedge DDE Examples:



Using the Wedge with Multiple Serial Ports Simultaniously

There are several ways to do this, but perhaps the easiest is simply to create two macros and have each instance of WinWedge call it's own macro:

Steps for setting up the first instance of WinWedge:

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("GetSWData1")] 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.

Steps for setting up the second instance of WinWedge:

Exactly the same as above except that you should enter the string: [RUN("GetSWData2")] as the Field Postamble DDE Command after the last data field that you have defined.

Steps for setting up EXCEL:

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 GetSWData1()
Dim RowPointer1 As Long
 
' The following code finds the next available empty row in Column A
RowPointer1 = cells(65000,1).end(xlup).row + 1


' Establish DDE link to WinWedge on Com1
Chan1 = DDEInitiate("WinWedge", "Com1")

' Request the data from the wedge
F1 = DDERequest(Chan1, "Field(1)")

' Convert the data from a variant array data type to a string
WedgeData1$ = F1(1)       

' Place the data in cell location Row = RowPointer, Column = 1 (A)

Sheets("Sheet1").Cells(RowPointer1, 1).Value = WedgeData1$

DDETerminate Chan1 ' Close the DDE channel

End Sub

' The following code is almost identical, but it opens up com 2 and writes to the next column over. As a precaution, the variable names have also been changed (e.g. Rowpointer1 became rowpointer2). This shouldn't be necessary, but it is a good habit to get into as having the same variable names in different subroutines can lead to mistakes and errors.

Sub GetSWData2()
Dim RowPointer2 As Long
 
' The following code finds the next available empty row in Column B
RowPointer2 = cells(65000,2).end(xlup).row + 1

' Establish DDE link to WinWedge on Com2
Chan2 = DDEInitiate("WinWedge", "Com2")

' Request the data from the wedge
F2 = DDERequest(Chan2, "Field(1)")

' Convert the data from a variant array data type to a string
WedgeData2$ = F2(1) 
      
' Place the data in cell location Row = RowPointer, Column = 2 (B)

Sheets("Sheet1").Cells(RowPointer2, 2).Value = WedgeData2$

DDETerminate Chan2 ' Close the DDE channel

End Sub

Basically what happens is that when the first instance of WinWedge receives data it triggers the macro GetSWData1 which writes the data to column A, the second instance of WinWedge will trigger the macro GetSWData2 which will write that data to column B. This should work even if both devices send their data at the same time.

Back to Top

TALtech Home  |  Products  |  Resources  |  Free Software  |  Support  |  Buy Now  |  Register Your Products  | 
Site Map  |  Contact TALtech  |  News