AnsweredAssumed Answered

How do I create a global NationalInstruments::NI4882::Device

Question asked by jmcguidwin on Nov 20, 2007
Latest reply on Nov 20, 2007 by dnt
I have a VS2005 C++ programming question hopefully someone will be able to send me in the right direction.

I want to create a global NationalInstruments::NI4882::Device. however i have not been able to. I can create one locally within  a function but i want to be able to share the device throughout the class.

NationalInstruments::NI4882::Device NIdevice((int)0,(byte)19,(byte)0); //Create a new NI4882 Device

when i try and create one in the header file i get an error:
Jammer.cpp(22) : error C2512: 'NationalInstruments::NI4882::Device::Device' : no appropriate default constructor available

also i was able to get it to build but I was not able to set the connection setting to talk to my E4438C.

Thanks and sorry if the code is messy.

jammer.cpp

#include "StdAfx.h"
#include "stdio.h"
#include "Jammer.h"
#include "windows.h"  // WINDOWS.H contains definitions used by NI488.H
#include "ni488.h"       //NI488.H contains prototypes for the GPIB routines and constants.

using namespace System;                         //used for String^
using namespace NationalInstruments::NI4882;    //GPIB device interaction

CJammer::CJammer(void)
{
}
String^ CJammer::continuousWave()
{
  OutputDebugString (L"continuousWave\n");  
  NationalInstruments::NI4882::Device NIdevice((int)0,(byte)19,(byte)0); //Create a new NI4882 Device
  //NIdevice.ReaddressingEnabled; 
  String^ gpib_data = "*idn?\n";
  NIdevice.Write(this->ReplaceCommonEscapeSequences(gpib_data));                  // Query the signal generator
  String^ gpib_read = this->InsertCommonEscapeSequences(NIdevice.ReadString());   // Read the response
  //String^ gpib_read = NIdevice.ReadString();   // Read the response

  //Set the frequency, amplitude and turn on the RF
// char rdBuffer [256];                        // Declare variable to hold string data
  String^ num;                                // Declare variable to hold integer data
  NIdevice.Write("*RST\n");                   // Reset the signal generator
  NIdevice.Write( "FREQ 1575.42 MHz\n");      // Set the source CW frequency for 1575.42 MHz
  NIdevice.Write( "FREQ:CW?\n");              // Query the CW frequency
  gpib_read += NIdevice.ReadString();         // Read signal generator response
  //OutputDebugString (L"Source CW frequency is : %s\n", rdBuffer); // Print the frequency
  NIdevice.Write( "POW:AMPL 15 dBm\n");       // Set the power level to 15 dBm
  NIdevice.Write("POW:AMPL?\n");              // Query the power level
  gpib_read += NIdevice.ReadString();         // Read the response into rdBuffer
  //printf("Source power (dBm) is : %s\n", rdBuffer); // Print the power level
  NIdevice.Write("OUTP:STAT ON\n");           // Turn source RF state on
  NIdevice.Write("OUTP?\n");                  // Query the signal generator's RF state
  num = NIdevice.ReadString();                // Read the response (integer value)
  //NIdevice.Clear();
  //NIdevice.Reset();
  //NIdevice.Write("*RST\n");
  return (gpib_read + num);          
}
String^ CJammer::pulsedWave()
{
  NationalInstruments::NI4882::Device NIdevice((int)0,(byte)19,(byte)0); //Create a new NI4882 Device
  //NIdevice.ReaddressingEnabled; 
  String^ gpib_data = "*idn?\n";
  NIdevice.Write(this->ReplaceCommonEscapeSequences(gpib_data));                  // Query the signal generator
  String^ gpib_read = this->InsertCommonEscapeSequences(NIdevice.ReadString());   // Read the response

  //Set the frequency, amplitude and turn on the RF
  char rdBuffer [256];                        // Declare variable to hold string data
  String^ num;                                // Declare variable to hold integer data
  NIdevice.Write("*RST\n");                  // Reset the signal generator
  NIdevice.Write( "FREQ 1575.42 MHz\n");          // Set the source CW frequency for 1575.42 MHz
  NIdevice.Write( "FREQ:CW?\n");              // Query the CW frequency
  gpib_read += NIdevice.ReadString();         // Read signal generator response
  printf("Source CW frequency is : %s\n", rdBuffer); // Print the frequency
  NIdevice.Write( "POW:AMPL 15 dBm\n");     // Set the power level to 15 dBm
  NIdevice.Write("POW:AMPL?\n");              // Query the power level
  gpib_read += NIdevice.ReadString();         // Read the response into rdBuffer
  printf("Source power (dBm) is : %s\n", rdBuffer); // Print the power level
  //NIdevice.Write("PULM:INT:FREQ 1575.42 MHz\n");
  //PULM:INTernal[1]:FREQuency?
  NIdevice.Write("PULM:INT:PER 1000.0 msec\n");
  //PULM::PER?
  NIdevice.Write("PULM:INT:PWID 500.0 msec\n");
  //PULM::PWIDth?
  NIdevice.Write("PULM:SOUR INT\n");
  //PULM::SOUR?
  NIdevice.Write("PULM:STAT ON\n");
  NIdevice.Write("OUTP:STAT ON\n");           // Turn source RF state on
  NIdevice.Write("OUTP?\n");                  // Query the signal generator's RF state
  num = NIdevice.ReadString();                // Read the response (integer value)

  return (gpib_read + num); 
}


jammer.h

#pragma once


ref class CJammer
{

public:
     CJammer(void);
     System::String^ continuousWave();
     System::String^ pulsedWave();
private:

 

};
[/code]  

Outcomes