%% TDS3000 MATLAB ICT Get Screen 1 % Get a copy of the screen in PNG format. %% variables serial_port = 'com1'; buffer = 2 * 1024; target_path = 'c:\'; target_name = 'tds_screen.png'; lf = 10; % ASCII linefeed, used to terminate commands %% instrument communication tds = serial(serial_port, 'InputBufferSize', buffer, ... 'OutputBufferSize', buffer); fopen(tds); % Because no handshaking takes place (?), RequestToSend must be set % manually after opening. The instrument will not reply otherwise. set(tds, 'RequestToSend', 'on'); % configure instrument for screen capture fwrite(tds, [':hardc:form png;inks 0;port rs232;' lf]); % initialize data variable binary = uint8(''); % begin data transfer fwrite(tds, [':hardc star;' lf]); pause(1); % read loop while get(tds, 'BytesAvailable') > 0, a = get(tds, 'BytesAvailable'); binary = [binary; fread(tds, a)]; pause(1); end % close connection with instrument fclose(tds); delete(tds); clear tds; %% save image data to file % create (or overwrite) file my_file = fopen([target_path target_name], 'w'); % write to file fwrite(my_file, binary); % close file fclose(my_file); %% notes %{ % Variable "binary" is of dynamic size because the image data transfer % begins without any metadata of the size. MATLAB complains about dynamic % variables but there isn't really much you can do about it. It's small % enough that I do not notice any performance degradation. Variable % "buffer" can also be increased to accommodate image data within one read % as well. % %}