function varargout = RackWriter(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RackWriter_OpeningFcn, ...
'gui_OutputFcn', @RackWriter_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before RackWriter is made visible.
function RackWriter_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for RackWriter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
axes(handles.axes2)
imshow('sensordeckelOben.jpg');
% UIWAIT makes RackWriter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RackWriter_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in onOff.
function onOff_Callback(hObject, eventdata, handles)
% hObject handle to onOff (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%This is where my stuff begins
% Preparations
close all %close all figures
clear all %clear all workspace variables
fclose('all') %close all Files
delete(instrfindall) %Reset Com Port
delete(timerfindall) %Delete Timers
%clear handles
% setup serial
serialPort = serial('COM3');
command = 'A';
nrow = 16;
ncol = 10;
row_index = [9,10,11,12,13,14,15,16,8,7,6,5,4,3,2,1];
col_index = [1,2,3,4,5,6,7,8,9,10];
% 10x16 = 160 bytes
lendata = 160;
BaudRate = 115200;
%InputBufferSize is bein displayed (disp(serialPort.BytesAvailable))
%with only 322 Bytes. The more information it has to process, the more
%bytes that havve to be stored in the InputBufferSize. But it seams to
%not go over 400
InputBufferSize = 500;
Timeout = 1;
set(serialPort , 'BaudRate', BaudRate);
set(serialPort , 'InputBufferSize', InputBufferSize);
set(serialPort , 'Timeout', Timeout);
fopen(serialPort);
while 1
% Request data
fprintf(serialPort, command);
% Get data
%Data is read as string (CSV)
data_string = fgetl(serialPort);
data_string_array = strsplit(data_string, ',');
data = str2double(data_string_array);
% Reshape data (1D -> 2D array)
data2d = zeros(nrow, ncol);
k = 1;
for i = 1:nrow
for j = 1:ncol
data2d(row_index(i), col_index(j)) = data(k);
k = k + 1;
end
end
%resize 16x10 image to 160x100 image
data2d_resized = imresize(data2d,10);
%sensetivity [0 255]
%axes(handles.axes1)
imshow(data2d_resized,[0 50]);
%clean out the InputBufferSize
flushinput(serialPort)
end
fclose(serialPort);
clear handlessomewhere? - Sueverhandlesis a cleared variable which means that it is not accessible when you try to use it. - Suever