How can I import screenshot from Tektronix MSO4054B oscilloscope to PC via MATLAB?

10 ビュー (過去 30 日間)
Henry Chang
Henry Chang 2021 年 1 月 25 日
回答済み: Sanchari 2024 年 5 月 23 日
Hey guys,
I'm trying to write a tool on App Designer to let the oscilloscope (Tektronix MSO4054B) communicate with PC via USB cable. I've adopted quick-control oscilloscope functions, which work pretty well when tuning display configurations of the oscilloscope. However, I'm trying to add a feature that saves the oscilloscope's screenshot directly to PC. The readWaveform function doesn't meet my needs since it only records an array of dots of the waveform.
I tried to reproduce the results of this article: Capture image using GPIB on Infiniium DCA86100 Oscilloscope, but it uses a different communication interface (GPIB) and different commands from those of Tektronix's hence pretty much impractical for my situation. Does anyone have a better idea on implementing this image saving function? Thx.

回答 (1 件)

Sanchari
Sanchari 2024 年 5 月 23 日
Hello Henry,
There are few possible approaches to solve the issue.
1. Extract code from ReadWaveform script: Using the “Test and Measurement Tool”, save the “Session Log” script as a MATLAB script. Extract the printing code from the script to use with App Designer. When plot appears in figure window, use the save options to capture the plot image. Follow the tutorial provided in this MathWorks Documentation for the same: https://www.mathworks.com/videos/read-a-waveform-from-an-oscilloscope-using-the-test-and-measurement-tool-1489428574572.html
2. Custom MATLAB code: In the App Designer code, add the following steps to capture and save the screenshot:
  1. Open a VISA connection to the oscilloscope using its VISA address.
  2. Send SCPI commands to the oscilloscope to capture the screen image.
  3. Read the image data from the oscilloscope.
  4. Save the image data to a file on the PC.
  5. Close the VISA connection.
Here’s an example code snippet that demonstrates these steps:
function saveOscilloscopeScreenshot(app)
% Replace with your oscilloscope's VISA address
visaAddress = 'USB0::0x0699::0x0363::C010233::0::INSTR';
% Create a VISA-USB object
osc = visa('TEK', visaAddress);
% Open connection to the oscilloscope
fopen(osc);
% Send SCPI command to capture the screen image
fprintf(osc, 'SAVE:IMAGE:FILEFORMAT PNG'); % Set the format to PNG
fprintf(osc, 'HARDCOPY START'); % Trigger screenshot capture
% Send SCPI command to read the image data
fprintf(osc, 'HARDCOPY:DATA?');
imgData = binblockread(osc, 'uint8'); % Read binary block data
% Close the connection
fclose(osc);
delete(osc);
% Save the image data to a file
filename = 'oscilloscope_screenshot.png';
fileID = fopen(filename, 'w');
fwrite(fileID, imgData, 'uint8');
fclose(fileID);
% Optionally, display a message or update the UI
disp(['Screenshot saved as ', filename]);
end
Few things to note:
  • Adjust the VISA address string to match required oscilloscope’s address.
  • Check the oscilloscope's manual for the correct SCPI commands if the ones provided don't work. The commands I've used (SAVE:IMAGE:FILEFORMAT and HARDCOPY START) are common, but required oscilloscope's manual may specify different ones.
  • Buffer Size: If the image data is larger than the input buffer, consider increasing the “InputBufferSize”.
This approach avoids the limitations of “readWaveform” by directly capturing the screen image, which includes the waveforms, measurements, and any annotations present on the screen, and saving it as a PNG file on PC.
Please refer to the following references to know further about:
  1. Snap_scope function (File Exchange): https://www.mathworks.com/matlabcentral/fileexchange/5639-snap_scope?s_tid=srchtitle_support_results_2_get%20image%20from%20oscilloscope
  2. Oscilloscope App to read waveform data (ML Answer): https://www.mathworks.com/matlabcentral/answers/403640-is-there-an-example-app-for-reading-waveform-data-from-an-oscilloscope?s_tid=answers_rc1-1_p1_Topic
  3. Acquire data from a Tektronix RSA 306 using Instrument Control Toolbox (ML Answer): https://www.mathworks.com/matlabcentral/answers/251299-is-it-possible-to-acquire-data-from-a-tektronix-rsa-306-real-time-signal-analyzer-using-instrument?s_tid=answers_rc1-1_p1_Topic
  4. Oscilloscope App (File Exchange): https://www.mathworks.com/matlabcentral/fileexchange/69847-oscilloscope-app?s_tid=answers_rc2-1_p4_BOTH
Hope this helps!

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by