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

Offline meranges

  • Single posting newcomer
  • *
  • Posts: 4
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: 11629
    • 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: 2290
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: 4
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: 11629
    • 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: 4
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: 234
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?.

Offline meranges

  • Single posting newcomer
  • *
  • Posts: 4
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #7 on: March 08, 2019, 08:10:21 pm »
I don't understand how serial ports work under Linux.


I keep on develop my C++ application. And I have no problem for a while.

I add some files, new class, into my project and it doesn'y works again. And now it is in Debug or release...
On open (SerialPortName.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
I get a negative value. If I display the status witha perror, i can have something like "Success" !!! or "input/Outut error", even if I don't change anything in my code !

I try to go back in my project, and I can find a version working fine every launches.
I try to add some of my new code but I don't call it The propblem appears...

Is anyone can help me to understand what is this ununderstandable problem ?

Is there a link with character ASCII or not ? are char always only 1 byte long ? or is it depending on ??? I don't know what.


« Last Edit: March 08, 2019, 08:18:03 pm by meranges »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: Ubuntu - Can't open serial port ttyUSB0 during debug
« Reply #8 on: March 08, 2019, 10:36:21 pm »
You need to find a programming support site for your Operating System (OS).
http://forums.codeblocks.org/index.php/topic,9996.0.html

Edit: The above is true if the issue can be duplicated when running from the command [line] to verify the problem is not part of Code::Blocks. The others in this thread are likely to try to help you; but, if the problem is not in Code::Blocks there is a good chance they will not be able to help you.

Tim S.
« Last Edit: March 08, 2019, 11:36:07 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org