4
I am communicating via USB -> Arduino Serial and receiving values from a sensor. But sometimes values have different sizes and the function used to receive the serial bytes needs a defined amount of input bytes. Example: date = readserial(Rduine, 3); The date value sometimes also receives the end-of-line character. So I found in the Octave, a function that performed the goal of taking one character at a time and stopping when I found an end-of-line character. The function is this:
Program of the Octave:
pkg load instrument-control
function [char_array] = ReadToTermination (srl_handle, term_char)
% parameter term_char is optional, if not specified
% then CR = '\r' = 13dec is the default.
if(nargin == 1)
term_char = 10;
end
not_terminated = true;
i = 1;
int_array = uint8(1);
while not_terminated
val = srl_read(srl_handle, 1);
if(val == term_char)
not_terminated = false;
end
% Add char received to array
int_array(i) = val;
i = i + 1;
end
% Change int array to a char array and return a string array
char_array = char(int_array);
endfunction
I have little familiarity with Scilab, but I still started writing the program on it, because I want to use a feature that Scilab has and Octave doesn’t. I will post the Scilab program along with the bug.
Scilab program:
function [char_array] = read_term(srl_handle, term_char)
not_terminated = 1;
i = 1;
int_array = uint8(1);
while not_terminated
val = readserial(srl_handle, 1);
if(val == term_char)
not_terminated = 0;
end
int_array(i) = val;
i = i+1;
end
char_array = (int_array);
endfunction
m = read_term(h,13) %Chamamento da função
Scilab error:
Operação indefinida para os dados operandos.
Verifique ou defina a função %c_i_i para overloading.
at line 10 of function read_term called by :
m = read_term(h,13)
at line 17 of exec file called by :
exec('C:\Users\Mateus\Documents\read_term.sci', -1)
I appreciate the help. Matthew Lucas.