
//-- There is NO need for a header
//-- Simply use the reference in the Project::Properties::Common Properties::Reference
//-- to add Euvis_Module_V1p1.DLL (the API file) as reference
using	namespace	MOL;
using	namespace	MOL::AWG;
using	namespace	System::Threading;

//-- If you use the traditional unmanaged codes
//-- You can also include the header
//-- Unmanaged Header
#include <stdio.h>

//==============================================================================
//==============================================================================
//-- The following code is a simple example to:
//-- 1) setup the AWG801 continuous-mode ( infinite loop )
//-- 2) select the clock frequency at 4 GHz
//-- 3) enter parameters for the built-in pseudonoise PNS waveform
//-- 4) download the built-in pseudonoise waveform
//-- 5) run the waveform
	
int	main( )
{
	AWG_Group_API	awg_group;
	AWG_API			awg;

	//---- Check if there is at least one AWG module connected
	if( awg_group.number == 0 )
	{
		printf( "No Module Exists!!\n" );
		return 1;
	}

	//---- Get the module series number
	int	SeriesNumber = awg_group.get_sn(0);
	printf( "Found Device with SN: %d\n", SeriesNumber );

    //---- Initialize the AWG
	//---- If you use multiple modules of the same type
	//---- you need to qualify the module_series number for the specified module
	awg.ini( SeriesNumber );

	//---- Check if the module_id_number is AWG801
	//---- module_id_number is used to identify the selected module 
	//---- in case multiple modules of different types, like AWG252 or DSM302, coexist
	/*
	if( awg.module_id_number != (unsigned) MODULE_ID::AWG452 )
	{
		printf( "Wrong Module!!\n" );
		printf( "Expect %d but got %X\n", (unsigned) MODULE_ID::AWG452, awg.module_id_number );
		return 1;
	}
	*/

	printf( "Module model id: %X\n", awg.module_id_number );
	printf( "Module model name: %s\n", awg.module_name );
	
	//---- Specify the signature file location and initialize it
	awg.signature_ini_dir( "C:\\Program Files\\Euvis\\AWG" );
	if( !awg.is_signature_file_exist )
	{
		printf( "Signature file does not exist!!\n" );
		return 1;
	}

	//---- Select the clock frequency 
	awg.Clock_Frequency = 4e9;

	//---- Configure the memory and waveform control
	awg.memory_depth = 0x100000;
	awg.loop_count = 0;				// Infinite Loop



//==============================================================================
//==============================================================================
//==============================================================================
//======== The following section can be replaced with other waveforms ==========
//==============================================================================
//==============================================================================
//==============================================================================
	//---- Select user page 0
	awg.user_page = 0;

	//--------------------------------------------------------------------------
	//---- Set Common Parameters
	//---- Data Length
	awg.data_length = 0x2000;
	//---- Markers
	//---- Enable Markers 2 and 3 with positive polarity. 
	//---- Marker 1 is always enabled automatically, but you should set enable and polarity for the others
	awg.marker2_enabled		= true;
	awg.marker2_polarity	= true;
	awg.marker3_enabled		= true;
	awg.marker3_polarity	= true;
	awg.marker1_start = 0x10;
	awg.marker1_width = 0x100;
	awg.marker2_start = 0x200;
	awg.marker2_width = 0x100;
	awg.marker3_start = 0x100;
	awg.marker3_width = 0x100;

	//--------------------------------------------------------------------------
	//---- Using the Built-in Waveform PNS
	awg.code = (unsigned) WAVEFORM_CODE::PNS;

	//---- Set Waveform-specific Parameters
	//---- Note that the parameters are in the same order as they appear in the GUI
	//---- but they are enumerated starting from 0 for each type independently
	//---- u (integer or hexadecimal)
	//---- d (decimal)
	awg.waveform_parameter_u0 = 15;		// Order		in unsigned
	awg.waveform_parameter_u1 = 0x0;	// Seed			in unsigned
	awg.waveform_parameter_d0 = 0.5;	// Tr			in double
	awg.waveform_parameter_d1 = 0.5;	// Tf			in double
	awg.waveform_parameter_u2 = 10;		// To			in unsigned
	awg.waveform_parameter_d2 = 1;		// Amplitude	in double


	//---- Download the waveform
	awg.stop();
	printf( "Downloading ...\n" );
	awg.download();
	printf( "Download Done!!\n" );

//==============================================================================
//==============================================================================
//==============================================================================



	//---- Run the waveform
	//---- Set the user page to 0, in case you also used other pages
	awg.user_page = 0;

	//---- Restart the first waveform and output it for 5 seconds
	awg.stop();
	awg.flush();
	awg.restart();


}