Questions? Search our site or call us at 1-800-722-6004

Collecting data from Multiple Devices Simultaneously

WinWedge and TCPWedge can easily be used to collect data from multiple devices simultaneously. There are several ways to do this, but perhaps the easiest is to run two instances of WinWedge (or TCPWedge) and also have two VBA macros defined in Excel where you have each instance of WinWedge call it's own macro:

When configuring WinWedge or TCPWedge, you would select "DDE Server" from the Mode menu and then use the following settings in the Window that appears:

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode. For further assistance Click here.

For the first instance of WinWedge, you would configure it using the following parameters after you select the "DDE Server" option from the Mode menu,

DDE Application Name: Excel
DDE Topic: System
DDE Command: [RUN("GetDevice1Data")]

For the second instance of WinWedge, you would use the following parameters:

DDE Application Name: Excel
DDE Topic: System
DDE Command: [RUN("GetDevice2Data")]

Note: If you are running WinWedge Professional Edition, the "DDE Command" option will not appear in the "DDE Server" options window and instead, it will appear as "Field Postamble DDE Command" entries in the last window of the "Input Record Definition Editor" window. To get to this window, you select Define - Input Data Record Structure and then click the Continue button in each window that appears until you get to the last window with the window caption "Input Record Definition Editor". If you have more than one data field defined, you would click the "Next Field" button until you get to the last defined data field and enter the command in the Field Postamble DDE Command textbox. You only need to enter the command in the Field Postamble DDE Command textbox for the very last data field that you have defined. All other Field Postamble DDE commands should be left blank.

Excel Instructions

*Important Note: Because we are collecting data from multiple devices, each device will have its own Excel macro and it's own instance of WinWedge. When following this guide for setting up WinWedge, be sure to first map out each Excel macro to a specific WinWedge Instance (active COM port). The DDE Command in WinWedge and the target COM port in the Excel macro will need to be customized for each device.

Create or edit a macro module in Excel 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 GetDevice1Data()
' This subroutine retrieves Field(1) from the first device running on COM1 and logs it to Column A

    Dim R As Long, Chan As Long, vDat As Variant, sDat As String

    R = ThisWorkbook.Sheets("Sheet1").Cells(65000, 1).End(xlUp).Row + 1 ' Find the next empty row in Column A

    Chan = DDEInitiate("WinWedge", "COM1")     ' Establish DDE link to WinWedge on COM1
   
    ' The following 3 lines of code can be duplicated to collect additional fields of data into different columns.
   
    vDat = DDERequest(Chan, "Field(1)")                 ' Request the data from Field(1) in WinWedge
    sDat = vDat(1)                                      ' Convert the data into a string
    ThisWorkbook.Sheets(1).Cells(R, 1).Value = sDat     ' Put data in cell at Row = R, Column = 1
   
    DDETerminate Chan                                   ' Terminate the DDE link

End Sub

The following code is almost identical, but it opens up com 2 and writes to the next column over.

Sub GetDevice2Data()
' This subroutine retrieves Field(1) from the first device running on COM2 and logs it to Column B

    Dim R As Long, Chan As Long, vDat As Variant, sDat As String

    R = ThisWorkbook.Sheets("Sheet1").Cells(65000, 2).End(xlUp).Row + 1 ' Find the next empty row in Column B

    Chan = DDEInitiate("WinWedge", "COM2")     ' Establish DDE link to WinWedge on COM2
   
    ' The following 3 lines of code can be duplicated to collect additional fields of data into different columns.
   
    vDat = DDERequest(Chan, "Field(1)")                 ' Request the data from Field(1) in WinWedge
    sDat = vDat(1)                                      ' Convert the data into a string
    ThisWorkbook.Sheets(1).Cells(R, 2).Value = sDat     ' Put data in cell at Row = R, Column = 2
   
    DDETerminate Chan                                   ' Terminate the DDE link

End Sub

Basically what happens is that when the first instance of WinWedge receives data, it triggers the macro GetDevice1Data which writes the data to column A. The second instance of WinWedge will trigger the macro GetDevice2Data which will write that data to column B.


Categories: Macro / Code Sample, Microsoft Excel, Data Collection, Serial (RS232), WinWedge

Last Updated: 2013.08.30

Need more help?

Don't hesitate to call or email us with your questions

Our office is open 9AM - 5PM Monday Through Friday (E.S.T.)

Technical Support: 215-496-0202

Toll-Free: 1 (800) 722-6004
Skype: taltech1 (Voice only)
Email: support@TALtech.com