Open serial port: Permission denied

Source: Internet
Author: User
Today, I tested a program with a serial port in Linux. The prompt "open serial port: Permission denied" is displayed during execution.
Open_port: Permission denied
Environment: ubuntu12.04pl2303 USB to serial port
Later, I found this article on the Internet. It turns out that the user's permissions are insufficient. 1. Change the execution permission of ttyusb0 # sudo chmod 777/dev/ttyusb0 2, and run the command directly by Su root with the Super User.

"Cannot open/dev/TTYs? : Permission denied"

(09:37:17)

Reprinted tokenHttp://blog.sina.com.cn/s/blog_483df0b7010005n6.htmlCannot open/dev/TTYs? : Permission deniedcheck the file permissions on this port with "ls-L/dev/TTYs? "_ If you own the TTYs? Then you need read and write permissions: CrW with the C (character device) in col. 1. it you don't own it then it will work for you if it shows RW-In cols. 8 & 9 which
Means that everyone has read and write permission on it. use "chmod" to change permissions. there are more complicated (and secure) ways to get access like belonging to a "group" that has group permission. some programs change the permissions when they run
But restore them when the program exists normally. But if someone pulls the plug on your PC it's an abnormal exit and correct permissions may not be restored. "cannot open/dev/TTYs? "

Unless stty is set for clocal, the CD pin may need to be asserted in order to open a serial port. if the physical port is not connected to anything, or if it's connected to something that is not powered on (such an external modem) then there will be no voltage
On CD from that device. Thus the "cannot open" message. Either set clocal or connect the serial port connector to something and power it on.

Even if a device is powered on and connected to a port, it may sometimes prevent opening the port. an example of this is where the device has negated CD and the CD pin on your PC is negated (negative voltage ).

"Operation not supported by device" for TTYs?

This means that an operation requested by setserial, stty, etc. couldn't be done because the kernel doesn't support doing it. formerly this was often due to the "serial" module not being loaded. but with the advent of PNP, it may likely mean that there is no
Modem (or other serial device) at the address where the driver (and setserial) thinks it is. if there is no modem there, commands (for operations) sent to that address obviusly don't get done. see what
Is set in my serial port hardware?

If the "serial" module wasn' t loaded but "lsmod" shows you it's now loaded it might be the case that it's loaded now but wasn' t loaded when you got the error message. in seconds cases the module will automatically loaded when needed (if it can be found ). to force
Loading of the "serial" module it may be listed in the file:/etc/modules. conf or/etc/modules. the actual module shocould reside in:/lib/modules /... /MISC/serial. o.

  Share: Share with Sina Qing

0

Like

Read (366) Workshop comments (1) Workshop
Favorites (0) reprint (0)

Previous Article: Write makefile (II) with me; next article: 4. Thanks (on official occasions) important comments: Be cautious with false winning information | [business news] I have a star momentum signature [ Send comments]

  • Cuidengzhi2006-09-09
    16:08:34 [report]

    Below is a simple example of reading serial data
    # Include    <Stdio. h>     /* Standard input/output definition */
    # Include    <Stdlib. h>    /* Standard function library definition */
    # Include    <Unistd. h>    /* UNIX standard function definition */
    # Include    <Sys/types. h> /**/
    # Include    <Sys/STAT. h>  /**/
    # Include    <Fcntl. h>     /* File control definition */
    # Include    <Termios. h>   /* Ppsix terminal control definition */
    # Include    <Errno. h>     /* Error Code definition */

    # DefineFalse -1
    # DefineTrue  0

    /*** @ Brief Set the serial communication rate
    * @ Param FD    TypeInt Open the file handle of the serial port
    * @ Param Speed TypeInt Serial Port Speed
    * @ Return Void */

    IntSpeed_arr []={B38400,B19200,B9600,B4800,B2400,B1200,B300,
            B38400,B19200,B9600,B4800,B2400,B1200,B300,};
    IntName_arr []={0, 38400, 19200, 9600, 4800, 2400, 1200, 300,
            38400, 19200, 9600,4800,2400,1200, 300,};
    VoidSet_speed (intFD,IntSpeed)
    {
      Int  I;
      Int  Status;
      StructTermios  OPT;
      Tcgetattr (FD,& OPT );
      For(I =0; I<Sizeof (speed_arr)/Sizeof (INT ); I ++)
       {
           If (Speed=Name_arr [I])
           {
               Tcflush (FD,Tcioflush );
            Cfsetispeed (& OPT,Speed_arr [I]);
        

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.