% ========================================================================= % Sample MATLAB program to query LeCroy LC334A oscilloscope using Prologix % GPIB-USB Controller 6.0. % % LeCroy LC334A is configured as TALKER/LISTENER and GPIB address 4. % % Output will be as follows: % % Prologix GPIB-USB Controller version 6.0 % "LeCroy LC334A" % % ========================================================================= % Specify the virtual serial port created by USB driver. Other serial port % parameters don't matter out = instrfind sport = serial('COM3'); % Prologix Controller 6.0 requires CR as command terminator, LF is % optional. The controller terminates internal query responses with CR and % LF. Responses from the instrument are passed through as is. (See Prologix % Controller Manual) sport.Terminator = 'CR/LF'; % ========================================================================= % Method #1 uses fgets to read controller response. Since the Prologix % controller always terminates internal query responses with CR/LF which is % same as the currently specified serial port terminator, this method will % work fine. % ========================================================================= % Open virtual serial port fopen(sport); % Send Prologix Controller query version command fprintf(sport, '++ver'); % Read and display response ver = fgets(sport); disp(ver); % Close port fclose(sport); delete(sport); %clear sport % ========================================================================= % Method #2 simply opens the port and writes to the port some useful % commands. Then it closes the port. % ========================================================================= % Suppress "not enough data read before timeout" warning sport = serial('COM3'); fopen(sport); % Configure ProLogix GPIB-USB as Controller (++mode 1), instrument address 4, % and with read-after-write (++auto 1) enabled fprintf(sport, '++mode 1'); fprintf(sport, '++addr 4'); fprintf(sport, '++auto 1'); fclose(sport); delete(sport); % ========================================================================= % Method #3 uses fread to read instrument response. Here we read a % waveform from the LeCroy LC534A scope. % ========================================================================= % Specify the virtual serial port created by USB driver. sport = serial('COM3'); %sport.BytesAvailable % Increase size of the buffer for storing data from its 512 byte default sport.InputBufferSize = 32768; fopen(sport); % Turn on read-after-write feature fprintf(sport, '++auto 1'); % Define file to read data into filename = 'C:\Documents and Settings\vanczb7\Desktop\LeCroy_Data\LeCroy_334A_data'; fid = fopen(filename, 'w+'); % Send command to read Waveform Template %fprintf(sport, 'Template?'); % Send command to read Trace A Waveform from LeCroy LC534A fprintf(sport, 'TA:WF?'); %fprintf(sport, 'TA:INSP?'); %fprintf(sport, 'INSPECT? "SIMPLE"'); % Read until data is read or timeout expires results = fread(sport); % Write to binary file count = fwrite(fid, results) % Enable front panel operation of the currently addressed instrument fprintf(sport, '++loc'); % Close serial port and file status = fclose('all') % fclose(fid); % fclose(sport); delete(sport); clear sport out = instrfind;