|
|
|
|
| [Challenge] 串口文件读写 non-blocking 模式 -- 求救 |
|
|
|
[Original]
[Print]
[Top]
|
现在想打开一个 串口文件读写, 想要的方式是 非 阻塞式。
下面的参数 好像都是设置对的, 但是 read 文件 的时候, 就是阻塞式的。
各位 大大 求救啊~
++++++++++设置++++++++++
/* open the device to be non-blocking (read will return immediatly) */
DevPtr = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (DevPtr < 0) {
std::cout << "Failed to open Modem!" << std::endl;
exit(-1);
}
/* install the signal handler before making the device asynchronous */
SigAction.sa_handler = signal_handler_IO;
sigemptyset(&SigAction.sa_mask);
SigAction.sa_flags = 0;
SigAction.sa_restorer = NULL;
sigaction(SIGIO, &SigAction, NULL);
/* allow the process to receive SIGIO */
fcntl(DevPtr, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(DevPtr, F_SETFL, FASYNC);
++++++++++读写++++++++++
printf("read once. +
");
res = read(fd,buf,255);
printf("read once.-
");
+++++++++++现象++++++++++++
每次等待读的时候
都只打印 "read once. +", 没有 "read once.-"。 所以我判断是阻塞式的
|
|
|
[Original]
[Print]
[Top]
|
|
|