Difficulties in Scilab

4

I'm communicating via USB - > Arduino Serial and receiving values from a sensor. But sometimes values have different sizes and the function used to receive the bytes from the serial needs a defined amount of input bytes. Example: data = readserial (arduino, 3); The date value is sometimes also given the end-of-line character. So I found in Octave, a function that fulfilled the purpose of picking up one character at a time and stopping when it encountered an end-of-line character. The function is this:

Octave Program:

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 even so I started writing the program on it, because I want to use a feature that Scilab has and Octave does not. I'll post the Scilab program along with the error.

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)

Thanks for the help. Matthew Lucas.

    
asked by anonymous 09.09.2016 / 15:36

0 answers