C++ Example for Opt. 003 COM Command

#include "stdafx.h"

#include <atlstr.h>

#import "C:\\Program Files (x86)\\Keysight\\Materials Measurement Suite 2020\\MaterialsMeas.dll"

 

int _tmain(int argc, _TCHAR* argv[])

{

            //Test COM interface of N1500A option 003

            CoInitialize(NULL);

            MaterialsMeasLib::IResonantCavityPtr pp(__uuidof(MaterialsMeasLib::ResonantCavity));          

            try

            {

                        HRESULT r = pp->Init();

                        if(r != S_OK)

                                    return 0;          

                        pp->Show();

                        //

                        //Measurement setting

                        double startFreq = 1.9e10;//unit Hz

                        double stopFreq = 2.1e10;

                        float power = -5;

                        float ifbw = 100;

                        int num = 101;

                        int average = 3;

                        pp->SetRange(startFreq, stopFreq, power, ifbw, num, average);

                        //

                        //Measure resonant frequency

                        double cavityFreq = 20.1e8, cavityQ = 7500; //resonant freq(Hz) and Q of empty cavity

                        double sampleFreq = 20.1e8, sampleQ = 7500; //resonant freq(Hz) and Q with samples

                        //Remove sample and measure empty cavity.

                        pp->MeasureFandQ(&cavityFreq, &cavityQ);

                        pp->Zoom();

                        pp->MeasureFandQ(&cavityFreq, &cavityQ);

                        //Insert sample and measure sample.

                        pp->MeasureFandQ(&sampleFreq, &sampleQ);

                        //

                        //Split Post method calculation

                        BSTR bstr;

                        bstr=SysAllocString(L"C:\\R1914\\RR1914.exe"); //location of exe file.

                        double thickness = 0.1;//unit mm

                        double er = 1.0, ei = 1.0;

                        pp->CalculateSPDR(thickness, cavityFreq, cavityQ, sampleFreq, sampleQ, bstr, &er, &ei);

                        SysFreeString(bstr);

                        //

                        //ASTM 2520 method calculation

                        double cavityVolume = 6.2832, sampleVolume = 0.7854; //unit mm3

                        pp->SetASTMCavityType(MaterialsMeasLib::ROUND);

                        pp->CalculateASTM(cavityVolume, cavityFreq, cavityQ, sampleVolume, sampleFreq, sampleQ, &er, &ei);

            }

            catch(_com_error e)

            {

            }         

            return 0;

}