bugGNU Octave - Bugs: bug #59581, [octave forge]...

 
 

bug #59581: [octave forge] (instrument-control) serialport error after second call

Submitter:  None
Submitted:  Tue 01 Dec 2020 12:54:37 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  lostbard
Originator Name:  Jens Bongartz Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 6.1.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 24 Feb 2021 12:52:06 PM UTC, comment #12: 

A new version of instrument control has been released with this change in it. Closing this report as fixed

John Donoghue <lostbard>
Group Member
Wed 02 Dec 2020 02:36:54 PM UTC, comment #11: 

Thanks a lot, John!

Jens Bongartz <jens_bongartz>
Wed 02 Dec 2020 02:17:18 PM UTC, comment #10: 

I pushed up a change to the repo that will appear in the next release

https://sourceforge.net/p/octave/instrument-control/ci/795af95e851879822dc0fbdf9b92882f573d00e9/

Thats applies the change to get for the various instrument types.

With that change, I am hoping the issue with fread also disappears

John Donoghue <lostbard>
Group Member
Wed 02 Dec 2020 01:58:20 AM UTC, comment #9: 

fread does cal get to get the number of bytes available if the number of bytes to fread isnt input - so would be causing the serial not not free.

John Donoghue <lostbard>
Group Member
Wed 02 Dec 2020 01:54:51 AM UTC, comment #8: 

For the get issue, if I modify @octave_serialport/get.m, around line 122 to:


  #func     = @(x) __srlp_properties__ (serial, x);
  #retval   = cellfun (func, property, 'UniformOutput', false);
  retval = {};
  for i=1:length(property)
    retval{end+1} = __srlp_properties__ (serial, property{i});
  endfor


The # parts being the old code ...

I the do not get the unreleased serial port. It seems that a reference to the serial object is kept because of the handle to the function, even when the function loses scope.


John Donoghue <lostbard>
Group Member
Wed 02 Dec 2020 12:44:27 AM UTC, comment #7: 

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;


Jens Bongartz <jens_bongartz>
Wed 02 Dec 2020 12:09:00 AM UTC, comment #6: 

im not sure why its gives you that message - when the port fails to open it it displays "serialport: Error opening the interface:" followed by the windows conversion of the error code from the fail to open.

fread just calls read so should be no real difference - how are you calling it in both cases ?




John Donoghue <lostbard>
Group Member
Tue 01 Dec 2020 11:23:25 PM UTC, comment #5: 

Hi John,
I am quite new to the instrument-control package and I didn't realize from the online reference to get the property from the object this elegant way. Thank you for this hint.

If you don't mind one more question:
In 6.1.0 I get in my script the error "serialport: Error opening the interface: Illegal byte sequence" after reopening the serial port, when I use fread(). It works fine by using read(). What is the best way to read the serial port? And what is the difference between read() and fread()?
In 5.2.0 both versions work.

Many thanks
Jens
 I


 


Jens Bongartz <jens_bongartz>
Tue 01 Dec 2020 10:08:26 PM UTC, comment #4: 

Yes I can see that - I will take a look


I do notice that if instead of using get, I use the direct property, it doesnt have the issue.

ie:  bytesavailable = s1.numbytesavailable



John Donoghue <lostbard>
Group Member
Tue 01 Dec 2020 09:53:54 PM UTC, comment #3: 

Hi John,
thanks for your reply. I tried to condense the code to a point where the error message is reproducible. I suppose I found it.

>> pkg load instrument-control
>> s1 = serialport("COM9");
>> clear s1
>> s1 = serialport("COM9");
>> clear s1
>> s1 = serialport("COM9");
>> bytesavailable = get(s1,"numbytesavailable")

bytesavailable = 0

>> clear s1
>> s1 = serialport("COM9");

error: serialport: Error opening the interface: No such file or directory

I can open and close the serialport without problems until I request "numbytesavailable". After this the serialport seems not to be released properly. I found this on Win 8.1 and OSX. Can you confirm this behavior on your side?

Best
Jens

Jens Bongartz <jens_bongartz>
Tue 01 Dec 2020 06:30:24 PM UTC, comment #2: 

Works for me in win10 - octave 6.1.0 64 bit


>> pkg load instrument-control
>> serialportlist
ans =
{
  [1,1] = COM2
  [1,2] = COM6
}

>> s1 = serialport('com2')
s1 =

  Serial Port Object Serial-com2
    port:     com2
    baudrate: 115200
    parity:   None
    databits: 8
    stopbits: 1
    timeout:  -1


>> s2 = serialport('com2')
error: serialport: Error opening the interface: No such file or directory
>> clear s1

>> s2 = serialport('com2')
s2 =

  Serial Port Object Serial-com2
    port:     com2
    baudrate: 115200
    parity:   None
    databits: 8
    stopbits: 1
    timeout:  -1
>>


Can you provide actual code ? In addition ensure you dont have other variables that have the serial port assigned to them


John Donoghue <lostbard>
Group Member
Tue 01 Dec 2020 03:01:44 PM UTC, comment #1: 

I tried Octave 6.1.0 with the instrument-control package as well under Mac OSX and observed the same behavior. First call is flawless and my serial communication script works. Different to Windows a second run of the script does not produce an error message but there is no data coming from the serial port. Arduino IDE reports also a blocked serial port until I quit Octave. Hence, a quite similar behavior like Windows.

Best regards
Jens

Jens Bongartz <jens_bongartz>
Tue 01 Dec 2020 12:54:37 AM UTC, original submission:  

Hello!

I tested Octave 6.1.0 (Windows 8.1 and 10) with the instrument-control package (0.6.0) to receive data from a connected Arduino via serialport(). First initalization of serialport works as expected. After closing (clear) serialport a second call to serialport leads to one of the following errors:

serialport: Error opening the interface: Illegal byte sequence
serialport: Error opening the interface: No such file or directory

It seems that the serial port of the computer remains blocked after closing because other application can also not access the serial port. Closing of Octave releases the serial port and access is regained.

With Octave 5.2.0 and instrument-control (0.6.0) the problem does not occur.

Best regards
Jens Bongartz


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lostbard (Posted a comment)
  • -email is unavailable- added by jens_bongartz (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-24 lostbard StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-12-02 lostbard StatusNone Ready For Test
        Assigned toNone lostbard
    2020-12-01 siko1056 Summary(instrument-control) serialport error after second call [octave forge] (instrument-control) serialport error after second call

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code