Author Topic: Ubuntu - Can't open serial port ttyUSB0 during debug  (Read 187 times)

Offline meranges

  • Single posting newcomer
  • *
  • Posts: 3
Ubuntu - Can't open serial port ttyUSB0 during debug
« on: February 09, 2019, 01:25:06 pm »
Hi,

I'm new developper with Code::Blocks (16.01 installed yesterday from Ubuntu application center) under Ubuntu 18.04.1 LTS (up to date)

I try to make a program which can reads on a serial port (/dev/ttyuSB0).

When I run the program without debbuging.
When I try to debug it, I can open the port I have an error message indication "Input/out Error"
The same application can be debugged under Rapian without problem

How to solve this issue ?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11492
    • Travis build status
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #1 on: February 09, 2019, 02:38:35 pm »
Can you be more clear what the problem is? Your program fails when? When you single step? What happens if you debug it using command line gdb? Does it still fail? Debuggers change timing behaviour of programs, so if you have a timing bug then it is possible that the debugger is exaggerating it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2253
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #2 on: February 09, 2019, 04:54:22 pm »
you probably have to set the udev rules for your usb device
https://wiki.archlinux.org/index.php/Udev

Offline meranges

  • Single posting newcomer
  • *
  • Posts: 3
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #3 on: February 10, 2019, 08:06:16 am »
Thank you for your answer.

Yes of course, my access to the serial port is made by an ifstream object.
I can run in step by step mode or run with debugging my program, the program is waiting for a while and the port is not opened.
The perror message is "input/output Error"

Here is my code extracted from a small class

    ifstream SerialPort;
    SerialPort.open ("/dev/ttyUSB0");
    if (!SerialPort.is_open())
    {
        perror("can't open serial port");
        exit(1);
    }

I don't know how to debug with gdb command line but I have a warning indicating gdb failed to set controlling terminal. because it is not permitted

Hope it helps to solve this issue
« Last Edit: February 10, 2019, 09:06:00 am by meranges »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11492
    • Travis build status
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #4 on: February 10, 2019, 11:15:15 am »
I don't know how to debug with gdb command line but I have a warning indicating gdb failed to set controlling terminal. because it is not permitted
If you search about this warning you'll see that it is harmless and it is not related to your problem.

To debug with gdb just enable full debug log and you'll see all the commands executed by C::B.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline meranges

  • Single posting newcomer
  • *
  • Posts: 3
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #5 on: February 12, 2019, 04:50:32 pm »
I keep on my investigations.

It seems to be linked with the amount of data sended by the serial port. There is continously data on the serial port.

If I stop the stream , or I reduce it, all works fine.

I don't understand the link between the amount of data and this error even more beacause it woks fine on a small Raspberry Pi Zero.



Offline Miguel Gimenez

  • Almost regular
  • **
  • Posts: 207
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #6 on: February 12, 2019, 06:21:59 pm »
The serial port has a limited character throughput (given by bauds/10). This is the same limit in a computer and in the Raspberry Pi Zero. The latter is relatively slow and (possibly) can't overflow the output buffer. The former is way faster and any buffer will overflow soon or later.

Are you checking if the calls to I/O functions are successful?. For example, fprintf() returns the number of characters really written: do this value match the number of characters you sent?.