Software Support

Collecting data from Multiple Serial Ports Simultaneously

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:

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode! Click here.

DDE Application Name: Excel
DDE Topic: System
DDE Command: [RUN("GetSWData1")] and [RUN("GetSWData2")]

Excel Instructions

*Important Note: Because we are collecting data from multiple devices, each device will have its own Excel macro and 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 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.

Categories: Macro / Code Sample, Microsoft Excel, WinWedge
Last Updated: 2012.04.26
Need more help?

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

Technical Support: 215-496-0222

Toll-Free: 1 (800) 722-6004
Skype: taltech1
Email: support@TALtech.com
Our office is open 9AM - 5PM Monday Through Friday (E.S.T.)