[英]What is the meaning of No such device or address(Error code 6)
我正在尝试使用C代码打开一个串行端口,并使用以下命令创建了一个节点;
mknod /tmp/ttyACM0 c 100 0;
chmod 700 /tmp/ttyACM0;
然后运行可执行文件,使用以下方法打开串行端口;
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;
}
它返回;
Error opening serial port /tmp/ttyACM0 - No such device or address(6).
实际上,/ tmp目录下有一个ttyACM0文件,但它会向我返回错误消息。 如何解决此错误?
编辑:当我查看/ proc / devices文件时,没有ttyACM0设备。 现在我认为我的问题的原因可能是此。
设备节点并不意味着该设备实际存在。 当您打开它时,内核会尝试查找匹配的设备,如果不存在,则会出现上述错误。
过去十年中形成的任何Linux系统都将通过udevd自动为现有设备创建设备节点。 您必须手动创建它,这充分说明该设备根本不存在,正如错误所说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.