简体   繁体   中英

open Unix, Linux System Call Permission denied for Arduino Uno

This is my c++ code:

#include <iostream>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

void createConnect(){

        const char *portname = "/dev/ttyACM0";
        int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
        if (fd < 0)
        {
           std::cout << "error: " <<  errno << " portname: " << portname << " strerror: " << strerror << std::endl;
        }

    }

This is output:

error: 13 portname: /dev/ttyACM0 strerror: 1

When I connect the phone to the USB port, this code don't give the error. But When I connect the Arduino Uno to the USB port, this code gives the error. Error is "Permission denied". How Can I solve this problem?

To solve this, write the following in terminal:

sudo chmod 666 /dev/ttyACM0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM