DDE Example
Microsoft Excel 7.0 DDE Module Example:
(Limit testing - runs THD test and checks against spec.)
Sub LimitTest()
'Start a DDE connection with SpectraPLUS-SC- You should already have opened the program.
ch = DDEInitiate("Specplus", "Data")
DDEExecute ch, "[File Open c:\spectraplus\config\thd_test.cfg]"
DDEExecute ch, "[Run]"
'wait 10 seconds
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
newTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait newTime
DDEExecute ch, "[Stop]"
'retrieve the results from the analyzer
Data = DDERequest(ch, "THD")
thd_value = Data(1)
'Check result against specification
If thd_value < 0.05 Then
MsgBox("Test PASSED")
Else
MsgBox("Test FAILED")
End If
DDETerminate ch
End Sub
Microsoft Excel 7.0 DDE Module Example:
(Statistics - Acquires 20 sets of averaged 1/3 Octave data)
Sub ThirdOctaveTest()
'Start a DDE connection with SpectraPLUS-SC- You should already have opened the program.
ch = DDEInitiate("Specplus", "Data")
'Control variables. Change these as needed.
MaxAverages = 20
AverageTimeMinutes = 1
CurrentAverage = 0
Do
'Start the analyzer
DDEExecute ch, "[Run]"
'wait N minutes from now
newHour = Hour(Now())
newMinute = Minute(Now()) + AverageTimeMinutes
newSecond = Second(Now())
newTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait newTime
' Stop the analyzer
DDEExecute ch, "[Stop]"
'Request the spectrum data from the analyzer, it will be placed in an array.
DataArray = DDERequest(ch, "Spectrum")
'Find the total number of bands in the spectrum - we will have one row per band
num_bands = UBound(DataArray)
'Place the spectral data in the worksheet starting from right to left. 'Since two
'columns of numbers are sent to us (freq, amplitude) we will simply overwrite
'the frequency column with the next column of amplitude data.
'Statistical calculations can then be performed in Sheet1
Worksheets("Sheet1").Range(Cells(2,
MaxAverages - CurrentAverage), Cells(1 + num_bands, MaxAverages -
CurrentAverage + 1)).Formula = DataArray
CurrentAverage = CurrentAverage + 1
If CurrentAverage >= MaxAverages Then Exit Do
Loop
DDEExecute ch, "[Stop]"
DDETerminate ch
End Sub