简体   繁体   English

没有这样的设备或地址是什么意思(错误代码6)

[英]What is the meaning of No such device or address(Error code 6)

I am trying to open a serial port with using c code and I have created a node with the following command; 我正在尝试使用C代码打开一个串行端口,并使用以下命令创建了一个节点;

mknod /tmp/ttyACM0 c 100 0; 
chmod 700 /tmp/ttyACM0;

and then run an executable file that opens a serial port with the following method; 然后运行可执行文件,使用以下方法打开串行端口;

static int OpenSerialPort(const char *bsdPath)
{
int                fileDescriptor = -1;
struct termios    options;

fileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fileDescriptor == -1 || flock(fileDescriptor, LOCK_EX) == -1 )
{
    printf("Error opening serial port %s - %s(%d).\n",
           bsdPath, strerror(errno), errno);
    goto error;
}

if (fcntl(fileDescriptor, F_SETFL, 0) == -1)
{
    printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
        bsdPath, strerror(errno), errno);
    goto error;
}

if (ioctl(fileDescriptor, TIOCEXCL, (char *) 0) < 0) {
  printf("Error setting TIOCEXCL %s - %s(%d).\n",
      bsdPath, strerror(errno), errno);
  goto error;
}
memset(&options,0,sizeof(options));

options.c_iflag=0;
options.c_oflag=0;
options.c_cflag=CS8|CREAD|CLOCAL;
options.c_lflag=0;
options.c_cc[VMIN]=1;
options.c_cc[VTIME]=5;
cfsetospeed(&options, B115200);
cfsetispeed(&options, B115200);

if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1)
{
    printf("Error setting tty attributes %s - %s(%d).\n",
        bsdPath, strerror(errno), errno);
    goto error;
}

return fileDescriptor;
error:
if (fileDescriptor != -1)
{
    close(fileDescriptor);
}
exit(1);
return -1;
}

and it returns; 它返回;

Error opening serial port /tmp/ttyACM0 - No such device or address(6).

There is actually a ttyACM0 file under /tmp directory but it returns me the error message. 实际上,/ tmp目录下有一个ttyACM0文件,但它会向我返回错误消息。 What can I do to pass this error? 如何解决此错误?

EDIT: When I look at the /proc/devices file, there is not a ttyACM0 device. 编辑:当我查看/ proc / devices文件时,没有ttyACM0设备。 Now I think my problem's reason can be this. 现在我认为我的问题的原因可能是此。

A device node does not mean that the device actually exists. 设备节点并不意味着该设备实际存在。 When you open it the kernel tries to find the matching device and if it doesn't exists you get the above error. 当您打开它时,内核会尝试查找匹配的设备,如果不存在,则会出现上述错误。

Any Linux system form the last decade will create device nodes for existing devices automatically through udevd. 过去十年中形成的任何Linux系统都将通过udevd自动为现有设备创建设备节点。 That you had to create it manually is a strong indication the device doesn't exist at all just as the error says. 您必须手动创建它,这充分说明该设备根本不存在,正如错误所说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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