我已经向opencapsensense控制器写了一个程序,它有8个端口,传感器连接到控制器的第一个端口,现在我想只显示一个端口数据,但结果就像数组一样。所以请建议我如何只显示第一个端口的数据。
输出类似于str = [22565,0,0,0,0,0,0,0]
,程序是
s = serial('COM3'); %assigns the object s to serial port
set(s, 'InputBufferSize', 240); %number of bytes in inout buffer
set(s, 'FlowControl', 'software');
set(s, 'BaudRate', 115200);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
disp(['Port setup done',num2str(prop)]);
fopen(s); %opens the serial port
disp('Running');
d= size(s);
disp(d)
t = 1;i = 1;
nr_of_samples = 100;
print_matrix = zeros(nr_of_samples,3);
while (t<(nr_of_samples+1))
str = fgets(s)% reads one line of text from the device connected to the serial port
fprintf(s,2)
if numel(str) > 10
%extract information from string to matrix
sender = str2double(str(3));
receiver = str2double(str(5));
value = str2double(str(7:length(str)));
%text = ['sender: ',int2str(sender),', receiver: ', int2str(receiver),' value: ',int2str(value),'\n'];
text = [' value: ',int2str(value),'\n'];
fprintf(text);
print_matrix(t,1) = sender;
print_matrix(t,2) = receiver;
print_matrix(t,3) = value;
t = t+1;
end
end
fprintf('\n');
distance = 50;
filename = ['conductivePaintOnFabric_' num2str(distance) '.dat'];
csvwrite(filename,print_matrix);
type(filename);
fclose(s); % disconnect serial port object
delete(s); % remove from memory
clear s; % remove from workspace
disp('Serial port closed');