现在的位置: 首页 > 综合 > 正文

open serial port: Permission denied

2013年10月10日 ⁄ 综合 ⁄ 共 3362字 ⁄ 字号 评论关闭
今天测试一个linux下串口的程序,执行时 提示
open serial port: Permission denied
open_port: Permission denied
环境:
ubuntu12.04
pl2303 usb转串口

后来在网上搜到此文,原来是使用者权限不够
处理办法
1,改变ttyUSB0的执行权限# sudo chmod 777 /dev/ttyUSB0 
2,直接su root  用超级用户执行


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

 (2006-09-08 09:37:17)

Check 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 obviously 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 many 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 should reside in: /lib/modules/.../misc/serial.o.

 

0

阅读(366) 评论 (1)
收藏(0) 转载(0)

 喜欢 打印举报

  • cuidengzhi2006-09-09
    16:08:34
     [举报]

    下面是一个简单的读取串口数据的例子
    #include     <stdio.h>      /*标准输入输出定义*/
    #include     <stdlib.h>     /*标准函数库定义*/
    #include     <unistd.h>     /*Unix标准函数定义*/
    #include     <sys/types.h>  /**/
    #include     <sys/stat.h>   /**/
    #include     <fcntl.h>      /*文件控制定义*/
    #include     <termios.h>    /*PPSIX终端控制定义*/
    #include     <errno.h>      /*错误号定义*/

    #define FALSE  -1
    #define TRUE   0

    /***@brief  设置串口通信速率
    *@param  fd     类型 int  打开串口的文件句柄
    *@param  speed  类型 int  串口速度
    *@return  void*/

    int speed_arr[] B38400, B19200, B9600, B4800, B2400, B1200, B300,
            B38400, B19200, B9600, B4800, B2400, B1200, B300, };
    int name_arr[] {38400,  19200,  9600,  4800,  2400,  1200,  300,
            38400,  19200,  9600, 4800, 2400, 1200,  300, };
    void set_speed(int fd, int speed)
    {
      int   i;
      int   status;
      struct termios   Opt;
      tcgetattr(fd, &Opt);
      for i= 0;  sizeof(speed_arr) sizeof(int);  i++)
       {
           if  (speed == name_arr[i])
           {
               tcflush(fd, TCIOFLUSH);
            cfsetispeed(&Opt, speed_arr[i]);
        

抱歉!评论已关闭.