% Add folder into path that contains the Automation DLL
addpath(genpath('C:\Program Files (x86)\Texas Instruments\High Speed Data Converter Pro\HSDCPro Automation DLL\64Bit DLL'));
% Load the Automation DLL
if ~libisloaded('HSDCProAutomation_64Bit')
    [notfound,warnings]=loadlibrary('C:\Program Files (x86)\Texas Instruments\High Speed Data Converter Pro\HSDCPro Automation DLL\64Bit DLL\HSDCProAutomation_64Bit.dll', @HSDCProAutomationHeader);
    %[notfound,warnings] = loadlibrary(___) returns warning information, and can include any of the input arguments in previous syntaxes.loadlibrary(libname,hfile) loads functions from C shared library libname defined in header file hfile into MATLAB®. 
    % The loadlibrary function only supports calling functions that are callable from C and header files that can be parsed by a C compiler.
end

%****ADC SETTINGS****%

% Board Serial Number with board type separated by hyphen. Eg: TIVHIV9Z-TSW1400
BoardSerialNumber = 'T7521FSm-TSW14J56revD'; %slave
% Firmware file path which needs to be loaded to the board.
%FirmwareFilePath = 'C:/Program Files (x86)/Texas Instruments/High Speed Data Converter Pro/14J56revD Details/Firmware/TSW14J56REVD_FIRMWARE.rbf';
ADCDevice = 'ADS54J60_LMF_8224';
%WaitToCheck=1; % Wait to check if firmware is downloaded properly? 0 - No, 1 - Yes. If yes, timeout should be greater than 60sec.
TimeoutInMs = 30000;
ADCOutputDataRate = 983040000;
%ADCInputTargetFrequency = 0;
NumberOfSamplesPerChannel = 65536; % Smaller number of samples, faster execution time of script.
NumberOfSamplesForAnalysis = 65536;  %Keep smaller to reduce FFT time
%ChannelIndex=0; % Interested channel's index(0-based)

%Enable or Disable Capture to File Option
%EnableCaptureToFile = 1;

%Get Array of Capture Data
%Number_Of_Samples_Per_Channel = 4096;
%OffsetSamplePerChannel = 0;
%Capture_Data_Array_Len = 32768; % Number_of_Samples_per_channel * Number_of_Channels
%CaptureData_16bits = zeros(Capture_Data_Array_Len,1); %Initializing the array for the total number of samples

%Trigger Mode
TriggerModeEnable=1;
SoftwareTriggerEnable=0;
ArmOnNextCaptureButtonPress=0;
TriggerCLKDelays= 0;

% Selection Settings
%TestSelection = 0; % Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3
%PlotType = 0; % Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3

% File Save Settings. 
%CSVFilePathWithName = 'C:\Users\a0489979\Desktop\SS.csv'; 
%BinaryFilePathWithName = 'C:/Users/Public/Documents/Texas Instruments/High Speed Data Converter Pro/Example Files/MatLAB Files/ADCData.bin';

%The CSV file contains the time domain data of all channels with each channel as a separate column.
%The binary file contains the time domain data of all channels in interleaved format.

% ********************************************************************************//
% ********** The actual call to the function contained in the dll ****************//
% ********************************************************************************//
fprintf('\nPlease open the HSDCPro GUI before using these Automation DLL functions.');
input('\nPress ENTER to start...');

% Connecting to the board and selecting DAC device
fprintf('\n\nConnecting to board : %s',BoardSerialNumber);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Connect_Board',BoardSerialNumber,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 
% calllib(libname,funcname,arg1,...,argN) calls function funcname in C library libname, passing input arguments arg1,...,argN. 
% The calllib function returns output values obtained from funcname in x1,...,xN.


fprintf('\n\nSelecting ADC Device : %s',ADCDevice);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Select_ADC_Device',ADCDevice,120000);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Download Firmware(OPTIONAL). Selecting device itself(above function) will automatically download the firmware
% fprintf('\n\nDownloading Firmware : %s',FirmwareFilePath);
% [Error_Status] = calllib('HSDCProAutomation_64Bit','Download_Firmware',FirmwareFilePath,WaitToCheck,60000);
% fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nReloading Device INI...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Reload_Device_INI',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nConfiguration Settings:');
fprintf('\n\nPassing ADC Output Data Rate = %d',ADCOutputDataRate);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_ADC_Output_Data_Rate',ADCOutputDataRate,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

%fprintf('\n\nADC Input Target Frequency = %d',ADCInputTargetFrequency);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_ADC_Input_Target_Frequency',ADCInputTargetFrequency,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nNumber of Samples per Channel = %d',NumberOfSamplesPerChannel);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_Number_of_Samples',NumberOfSamplesPerChannel,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nAnalysis Window Length = %d',NumberOfSamplesForAnalysis);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Analysis_Window_Length',NumberOfSamplesForAnalysis,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nChecking if HSDCPro GUI has completed all its operations...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','HSDC_Ready',TimeoutInMs); % Waiting to check if HSDCPro has completed all its operations.
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));


fprintf('\n\nTrigger_Option = %d (Trigger Mode Enable)',TriggerModeEnable);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Trigger_Option',TriggerModeEnable,SoftwareTriggerEnable,ArmOnNextCaptureButtonPress,TriggerCLKDelays, TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

%fprintf('\n\nPass_Capture_Event');
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_Capture_Event',TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

%fprintf('\n\nGetting an array of Capture Data in 16 bits');
%[Error_Status, CaptureData_16bits] = calllib('HSDCProAutomation_64Bit','Get_Capture_Data_16bits',Number_Of_Samples_Per_Channel, OffsetSamplePerChannel, CaptureData_16bits, Capture_Data_Array_Len, TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

%fprintf('\n\nSaving ADC Raw Data as CSV file at %s', CSVFilePathWithName);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Save_Raw_Data_As_CSV',CSVFilePathWithName,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 


%fprintf('\n\nSaving ADC Raw Data as Binary file at %s', BinaryFilePathWithName);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Save_Raw_Data_As_Binary_File',BinaryFilePathWithName,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Applying FFT Settings, just for displaying 'Bit' and 'Time Domain' on the
% graph in HSDC

%fprintf('\n\nTest Selection Option = %d (Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3)',TestSelection);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Test_Selection',TestSelection,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

%fprintf('\n\nGraph Plot Type = %d (Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3)',PlotType);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Plot_Type',PlotType,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));



%data = csvread('SS.csv');
%x = data(:, 1); % Or wherever
%plot(x);
%grid on;
%title('Number of Samples vs ADC Code', 'FontSize', 10);
%xlabel('Number of samples', 'FontSize', 10);
%ylabel('ADC Code', 'FontSize', 10);

%Disconnecting from the board
fprintf('\n\nDisconnecting from the board');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Disconnect_Board',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% **************** MASTER *****************

% Board Serial Number with board type separated by hyphen. Eg: TIVHIV9Z-TSW1400
BoardSerialNumber = 'T751R8Z5-TSW14J56revD'; %master
% Firmware file path which needs to be loaded to the board.
%FirmwareFilePath = 'C:/Program Files (x86)/Texas Instruments/High Speed Data Converter Pro/14J56revD Details/Firmware/TSW14J56REVD_FIRMWARE.rbf';
ADCDevice = 'ADS54J60_LMF_8224';
%WaitToCheck=1; % Wait to check if firmware is downloaded properly? 0 - No, 1 - Yes. If yes, timeout should be greater than 60sec.
TimeoutInMs = 30000;
ADCOutputDataRate = 983040000;
%ADCInputTargetFrequency = 0;
NumberOfSamplesPerChannel = 65536; % Smaller number of samples, faster execution time of script.
NumberOfSamplesForAnalysis = 65536;  %Keep smaller to reduce FFT time
%ChannelIndex=0; % Interested channel's index(0-based)

%Enable or Disable Capture to File Option
EnableCaptureToFile = 1;

%Get Array of Capture Data
Number_Of_Samples_Per_Channel = 4096;
OffsetSamplePerChannel = 0;
Capture_Data_Array_Len = 32768; % Number_of_Samples_per_channel * Number_of_Channels
CaptureData_16bits = zeros(Capture_Data_Array_Len,1); %Initializing the array for the total number of samples

%Trigger Mode
TriggerModeEnable=1;
SoftwareTriggerEnable=0;
ArmOnNextCaptureButtonPress=1;
TriggerCLKDelays= 0;

% Selection Settings
TestSelection = 0; % Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3
PlotType = 0; % Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3

% File Save Settings. 
CSVFilePathWithName = 'C:\Users\a0489979\Desktop\Master.csv'; 
%BinaryFilePathWithName = 'C:/Users/Public/Documents/Texas Instruments/High Speed Data Converter Pro/Example Files/MatLAB Files/ADCData.bin';

%The CSV file contains the time domain data of all channels with each channel as a separate column.
%The binary file contains the time domain data of all channels in interleaved format.

% ********************************************************************************//
% ********** The actual call to the function contained in the dll ****************//
% ********************************************************************************//
fprintf('\n\nMaster functions.');

% Connecting to the board and selecting DAC device
fprintf('\n\nConnecting to board : %s',BoardSerialNumber);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Connect_Board',BoardSerialNumber,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 
% calllib(libname,funcname,arg1,...,argN) calls function funcname in C library libname, passing input arguments arg1,...,argN. 
% The calllib function returns output values obtained from funcname in x1,...,xN.


fprintf('\n\nSelecting ADC Device : %s',ADCDevice);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Select_ADC_Device',ADCDevice,120000);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Download Firmware(OPTIONAL). Selecting device itself(above function) will automatically download the firmware
% fprintf('\n\nDownloading Firmware : %s',FirmwareFilePath);
% [Error_Status] = calllib('HSDCProAutomation_64Bit','Download_Firmware',FirmwareFilePath,WaitToCheck,60000);
% fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nReloading Device INI...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Reload_Device_INI',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nConfiguration Settings:');
fprintf('\n\nPassing ADC Output Data Rate = %d',ADCOutputDataRate);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_ADC_Output_Data_Rate',ADCOutputDataRate,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

%fprintf('\n\nADC Input Target Frequency = %d',ADCInputTargetFrequency);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_ADC_Input_Target_Frequency',ADCInputTargetFrequency,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nNumber of Samples per Channel = %d',NumberOfSamplesPerChannel);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_Number_of_Samples',NumberOfSamplesPerChannel,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nAnalysis Window Length = %d',NumberOfSamplesForAnalysis);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Analysis_Window_Length',NumberOfSamplesForAnalysis,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nChecking if HSDCPro GUI has completed all its operations...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','HSDC_Ready',TimeoutInMs); % Waiting to check if HSDCPro has completed all its operations.
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));


fprintf('\n\nTrigger_Option = %d (Trigger Mode and Arm on next Capture Enable)',TriggerModeEnable);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Trigger_Option',TriggerModeEnable,SoftwareTriggerEnable,ArmOnNextCaptureButtonPress,TriggerCLKDelays, TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nPass_Capture_Event');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_Capture_Event',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nGetting an array of Capture Data in 16 bits');
[Error_Status, CaptureData_16bits] = calllib('HSDCProAutomation_64Bit','Get_Capture_Data_16bits',Number_Of_Samples_Per_Channel, OffsetSamplePerChannel, CaptureData_16bits, Capture_Data_Array_Len, TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nSaving ADC Raw Data as CSV file at %s', CSVFilePathWithName);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Save_Raw_Data_As_CSV',CSVFilePathWithName,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 


%fprintf('\n\nSaving ADC Raw Data as Binary file at %s', BinaryFilePathWithName);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Save_Raw_Data_As_Binary_File',BinaryFilePathWithName,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Applying FFT Settings, just for displaying 'Bit' and 'Time Domain' on the
% graph in HSDC

fprintf('\n\nTest Selection Option = %d (Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3)',TestSelection);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Test_Selection',TestSelection,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nGraph Plot Type = %d (Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3)',PlotType);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Plot_Type',PlotType,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));



%data = csvread('SS.csv');
%x = data(:, 1); % Or wherever
%plot(x);
%grid on;
%title('Number of Samples vs ADC Code', 'FontSize', 10);
%xlabel('Number of samples', 'FontSize', 10);
%ylabel('ADC Code', 'FontSize', 10);

% Disconnecting from the board
fprintf('\n\nDisconnecting from the board');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Disconnect_Board',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% ************** SLAVE *******************

% Board Serial Number with board type separated by hyphen. Eg: TIVHIV9Z-TSW1400
BoardSerialNumber = 'T7521FSm-TSW14J56revD'; %slave
% Firmware file path which needs to be loaded to the board.
FirmwareFilePath = 'C:/Program Files (x86)/Texas Instruments/High Speed Data Converter Pro/14J56revD Details/Firmware/TSW14J56REVD_FIRMWARE.rbf';
ADCDevice = 'ADS54J60_LMF_8224';
WaitToCheck=1; % Wait to check if firmware is downloaded properly? 0 - No, 1 - Yes. If yes, timeout should be greater than 60sec.
TimeoutInMs = 30000;
ADCOutputDataRate = 983040000;
%ADCInputTargetFrequency = 0;
NumberOfSamplesPerChannel = 65536; % Smaller number of samples, faster execution time of script.
NumberOfSamplesForAnalysis = 65536;  %Keep smaller to reduce FFT time
%ChannelIndex=0; % Interested channel's index(0-based)

%Enable or Disable Capture to File Option
%EnableCaptureToFile = 1;

%Get Array of Capture Data
Number_Of_Samples_Per_Channel = 4096;
OffsetSamplePerChannel = 0;
Capture_Data_Array_Len = 32768; % Number_of_Samples_per_channel * Number_of_Channels
CaptureData_16bits = zeros(Capture_Data_Array_Len,1); %Initializing the array for the total number of samples

% Selection Settings
TestSelection = 0; % Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3
PlotType = 0; % Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3

% File Save Settings. 
CSVFilePathWithName = 'C:\Users\a0489979\Desktop\Slave.csv'; 
%BinaryFilePathWithName = 'C:/Users/Public/Documents/Texas Instruments/High Speed Data Converter Pro/Example Files/MatLAB Files/ADCData.bin';

%The CSV file contains the time domain data of all channels with each channel as a separate column.
%The binary file contains the time domain data of all channels in interleaved format.

% ********************************************************************************//
% ********** The actual call to the function contained in the dll ****************//
% ********************************************************************************//
fprintf('\n\nSlave functions.');

% Connecting to the board and selecting DAC device
fprintf('\n\nConnecting to board : %s',BoardSerialNumber);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Connect_Board',BoardSerialNumber,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 
% calllib(libname,funcname,arg1,...,argN) calls function funcname in C library libname, passing input arguments arg1,...,argN. 
% The calllib function returns output values obtained from funcname in x1,...,xN.


fprintf('\n\nSelecting ADC Device : %s',ADCDevice);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Select_ADC_Device',ADCDevice,120000);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Download Firmware(OPTIONAL). Selecting device itself(above function) will automatically download the firmware
% fprintf('\n\nDownloading Firmware : %s',FirmwareFilePath);
% [Error_Status] = calllib('HSDCProAutomation_64Bit','Download_Firmware',FirmwareFilePath,WaitToCheck,60000);
% fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nReloading Device INI...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','Reload_Device_INI',TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nConfiguration Settings:');
fprintf('\n\nPassing ADC Output Data Rate = %d',ADCOutputDataRate);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_ADC_Output_Data_Rate',ADCOutputDataRate,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

%fprintf('\n\nADC Input Target Frequency = %d',ADCInputTargetFrequency);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_ADC_Input_Target_Frequency',ADCInputTargetFrequency,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nNumber of Samples per Channel = %d',NumberOfSamplesPerChannel);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Set_Number_of_Samples',NumberOfSamplesPerChannel,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nAnalysis Window Length = %d',NumberOfSamplesForAnalysis);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Analysis_Window_Length',NumberOfSamplesForAnalysis,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nChecking if HSDCPro GUI has completed all its operations...');
[Error_Status] = calllib('HSDCProAutomation_64Bit','HSDC_Ready',TimeoutInMs); % Waiting to check if HSDCPro has completed all its operations.
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

%fprintf('\n\nPass_Capture_Event');
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Pass_Capture_Event',TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nGetting an array of Capture Data in 16 bits');
[Error_Status, CaptureData_16bits] = calllib('HSDCProAutomation_64Bit','Get_Capture_Data_16bits',Number_Of_Samples_Per_Channel, OffsetSamplePerChannel, CaptureData_16bits, Capture_Data_Array_Len, TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));

fprintf('\n\nSaving ADC Raw Data as CSV file at %s', CSVFilePathWithName);
[Error_Status] = calllib('HSDCProAutomation_64Bit','Save_Raw_Data_As_CSV',CSVFilePathWithName,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 


%fprintf('\n\nSaving ADC Raw Data as Binary file at %s', BinaryFilePathWithName);
%[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Save_Raw_Data_As_Binary_File',BinaryFilePathWithName,TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

% Applying FFT Settings, just for displaying 'Bit' and 'Time Domain' on the
% graph in HSDC

fprintf('\n\nTest Selection Option = %d (Time Domain-0; Single Tone-1; Two Tone-2; Channel Power-3)',TestSelection);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Test_Selection',TestSelection,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

fprintf('\n\nGraph Plot Type = %d (Codes - 0; Bits - 1; Real FFT - 2; Complex FFT - 3)',PlotType);
[Error_Status] = calllib('HSDCProAutomation_64Bit','ADC_Plot_Type',PlotType,TimeoutInMs);
fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status));



%data = csvread('SS.csv');
%x = data(:, 1); % Or wherever
%plot(x);
%grid on;
%title('Number of Samples vs ADC Code', 'FontSize', 10);
%xlabel('Number of samples', 'FontSize', 10);
%ylabel('ADC Code', 'FontSize', 10);

%Disconnecting from the board
%fprintf('\n\nDisconnecting from the board');
%[Error_Status] = calllib('HSDCProAutomation_64Bit','Disconnect_Board',TimeoutInMs);
%fprintf('\nError Status = %d (%s)',Error_Status,HSDCPro_Automation_Error_to_String(Error_Status)); 

%input('\n\nPress ENTER to exit..');