1

I'm on ubuntu 12.04 beta. I premit that minicom works properly on /dev/ttyS0 (but putty doesn't). I control the port in C code which works properly on ubuntu 11.10:

fd = open(p_ttys_parms->device, O_RDWR | O_NOCTTY | O_NDELAY);
if(fd < 0)
{
    printf("ERROR: cannot open device %s\n", p_ttys_parms->device);
    return 0;
}

but in 12.04 beta I get fd < 0 and exit after the printf. Did anybody experience the same and succeeded somehow?

3
  • 2
    And what is in errno? That should be the first thing you look at.
    – paxdiablo
    Mar 23, 2012 at 13:29
  • I get errno: Permission denied, running it again with sudo it works. You solved my problem thank you (even if I don't get the reason why in 12.04 I need sudo to open a serial port while in 11.10 it was not necessary).
    – giuspen
    Mar 23, 2012 at 13:42
  • No probs, I'll copy that to an answer and add some more detail on the likely reason and fix.
    – paxdiablo
    Mar 23, 2012 at 13:59

2 Answers 2

7

The first thing you should do is check the value of errno. The open call, if it returns -1, will set errno to a value indicating what the actual problem is.


And, based on your comment that it's Permission denied and your program works when run under sudo, it's probably a permissions problem with the /dev/ttyS0 device file.

I get a similar issue under Debian 6:

pax> ls -al /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Mar 23 21:00 /dev/ttyS0
pax> echo xyzzy >/dev/ttyS0
bash: /dev/ttyS0: Permission denied

You may find you need to add your user to the dialout group (or another group, depending on how far Ubuntu deviates from my beloved Debian) to be allowed access:

pax> id -Gn
pax cdrom floppy audio dip video plugdev netdev bluetooth scanner

pax> sudo adduser pax dialout
[sudo] password for pax: 
Adding user pax to group dialout
Done.

<< Restart done here to ensure new group picked up >>

pax> id -Gn
pax dialout cdrom floppy audio dip video plugdev netdev bluetooth scanner
2
  • yes it worked for mee too, thank you very much (sudo usermod -a -G dialout myusername ; sudo shutdown -r 0)
    – giuspen
    Mar 23, 2012 at 14:01
  • No need to "restart". The pax user just needs to log out and back in again.
    – Wodin
    Nov 22, 2012 at 12:10
1

I used following command to set perminssion (i'm using /dev/ttyUSB0).

sudo chmod 0777 /dev/ttyUSB0 

When i execute the command:

 AvailableSerialPorts: {'/dev/ttyUSB0'}
       JarFileVersion: 'Version 2.11.0'
ObjectConstructorName: {'serial('/dev/ttyUSB0');'}
          SerialPorts: {'/dev/ttyUSB0'}

And also, I've opened matlab with root permission (in terminal).

sudo /usr/local/MATLAB/R2010b/bin/matlab
1
  • Thank you, but this works for only one serial device... I think adding the user to the group dialout is a better solution
    – giuspen
    Jun 28, 2012 at 12:19

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.