clear; clc; close all; % Define the VISA resource name for the oscilloscope visaResource = 'USB::0x0699::0x0528::C019090::INSTR'; % Create a VISA object scope = visa('TEK', visaResource); % Set timeout and input buffer size set(scope, 'Timeout', 30); % Increase timeout to 30 seconds set(scope, 'InputBufferSize', 1000000); % Adjust as necessary % Open the connection to the oscilloscope try fopen(scope); catch e disp(['Error opening connection: ', e.message]); return; end %------------ fprintf(scope, 'FILESYSTEM:CWD "P:\RESEARCH\PHD\2022-PFCA-MOHSEN-FEIZI\PhD\Experimental\Auto-tune"'); fprintf(scope, 'FILESYSTEM:CWD?'); cwd = fscanf(scope, '%s'); % Read the response as a string % Display or use the current working directory disp(['Current Working Directory (CWD): ' cwd]); destinationPath = 'P:\RESEARCH\PHD\2022-PFCA-MOHSEN-FEIZI\PhD\Experimental\Auto-tune'; try % Send command to set the destination path fprintf(scope, 'SAVEON:FILE:DEST "P:\RESEARCH\PHD\2022-PFCA-MOHSEN-FEIZI\PhD\Experimental\Auto-tune"'); % Query the current destination path to verify queryCommand = query(scope, 'SAVEON:FILE:DEST?'); disp(['Current destination path set to: ', queryCommand]); % Optionally, you can check the response for confirmation if contains(queryCommand, destinationPath) disp('Destination path set successfully.'); else error('Failed to set destination path.'); end catch ME % Handle any errors that may occur fprintf('Error: %s\n', ME.message); end %-------------------- % Verify connection by querying the instrument's identification string try idn = query(scope, '*IDN?'); disp(['Instrument Identification: ', idn]); catch e disp(['Error querying instrument: ', e.message]); fclose(scope); delete(scope); clear scope; return; end fprintf(scope, 'FILESystem:DELEte "C:/plot1.csv"'); %------Turn on, CH3 fprintf(scope, 'DISplay:GLObal:CH3:STATE ON'); pause(1); fprintf(scope, 'DISplay:GLObal:CH2:STATE ON'); %------Set vertical scaling fprintf(scope, 'DISplay:WAVEView1:CH1:VERTical:SCAle 1'); fprintf(scope, 'DISplay:WAVEView1:CH2:VERTical:SCAle 1'); fprintf(scope, 'DISplay:WAVEView1:CH3:VERTical:SCAle 1'); %------Trigger setting fprintf(scope, 'TRIGGER:A:EDGE:COUPLING DC'); fprintf(scope, 'TRIGGER:A:EDGE:SOURCE CH3'); fprintf(scope, 'TRIGGER:A:EDGE:SLOPE RISE'); fprintf(scope, 'TRIGGER:A:LEVEL:CH3 1'); pause(2); % Add a delay to ensure command is processed %------Set vhorizental scaling fprintf(scope, 'HORIZONTAL:SCALE 40e-9'); pause(1); fprintf(scope, 'DISplay:WAVEView1:VIEWStyle OVERLAY'); pause(1); %-------------------- pause(1); %---------------- fprintf(scope, ':MEASUrement:MEAS1:TYPE DELAY'); fprintf(scope, 'MEASUrement:MEAS1:DISPlaystat:ENABle ON'); fprintf(scope, ':MEASUrement:MEAS1:SOURCE1 CH1'); fprintf(scope, ':MEASUrement:MEAS1:SOURCE2 CH2'); fprintf(scope, ':MEASUREMENT:MEAS1:DELAY:EDGE1 RISE;'); %fprintf(scope, 'MEASUREMENT:CH1:REFLEVELS::ABSOLUTERISEHIGH 1'); fprintf(scope, ':MEASUREMENT:MEAS1:DELAY:EDGE2 RISE;'); %fprintf(scope, 'MEASUREMENT:CH2:REFLEVELS:ABSOLUTE:RISEHIGH 1'); pause(1); fprintf(scope, 'PLOT:ADDNEW "PLOT1"'); fprintf(scope, 'PLOT:PLOT1:TYPe HISTOGRAM'); fprintf(scope, 'PLOT:PLOT1:SOUrce MEAS1'); %fprintf(scope, 'DISplay:SELect:VIEW PLOTVIEW1'); pause(10); fprintf(scope, 'ACQuire:STATE STOP'); fprintf(scope, 'SAVe:PLOTData "E:/plot3.csv"'); % save it on external USB %fprintf(scope, 'SAVe:PLOTData "C:/plot1.csv"'); % save it on c driver of the scope %fprintf(scope, 'SAVe:PLOTData "E:/plot3.csv"'); % save it on external USB %fprintf(scope, 'FILESYSTEM:READFILE “C:/plot1.csv”');