octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #59581] [octave forge] (instrument-control) se


From: Jens Bongartz
Subject: [Octave-bug-tracker] [bug #59581] [octave forge] (instrument-control) serialport error after second call
Date: Tue, 1 Dec 2020 19:44:27 -0500 (EST)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36

Follow-up Comment #7, bug #59581 (project octave):

The following code is the core of my serial communication. The Arduino sends
strings like "REF:123,ADC:456" with 200Hz. The script extracts the numbers and
adds them to the ref_array and adc_array. I use read() and fread() as shown in
the online reference. Are there better ways? 
Using fread() in Octave 6.1.0 leads to the mentioned error message.

Thanks for your help!

pkg load instrument-control;
clear all;

serial_01 = serialport("COM9",115200);

flush(serial_01);
adc_array = [];
ref_array = [];
x_index = 0;

do
   bytesavailable = serial_01.numbytesavailable;
   
   if (bytesavailable > 0)
     inSerial = read(serial_01,bytesavailable);
     ##inSerial = fread(serial_01);
     inChar = char(inSerial);
     inNumbers = strsplit(inChar,{',','ADC:','REF:'});
     count = length(inNumbers);
     for i = 2:2:count
        ref = str2num(inNumbers{i});
        adc = str2num(inNumbers{i+1});
        adc_array(end+1)=adc;
        ref_array(end+1)=ref;
        x_index++
     endfor
   endif
until(kbhit(1) == 'x');

clear serial_01;



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59581>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]