This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
尊敬的专家
我使用的是 TDA4VEN 板、使用 select 函数轮询当前串行端口是否可读、便返回-1。
代码对齐:
fd = open("/dev/ttyS2", O_RDWR | O_NONBLOCK); ret = pthread_create(&uart_read_thread,NULL,uart_read_thread_fun,&data); void *uart_read_thread_fun (void *data) { int ThreadFd = fd; struct timeval WaitTime; fd_set fds; int ReadResult=0; FD_ZERO(&fds); FD_SET(ThreadFd,&fds); WaitTime.tv_sec = 0; WaitTime.tv_usec = 100000; printf("in read thread\n"); while(1) { if(select(ThreadFd+1,&fds,0,0,&WaitTime) > 0) { ReadResult = read(ThreadFd,BufForRead,sizeof(BufForRead)); if(ReadResult > 0) { readCount++; printf("data=%s,ret=%d,read count=%ld\n",BufForRead,ReadResult,readCount); } } else { printf("read select error\n"); } } }
如果不使用 SELECT 函数并只读取数据、那么它可以读取数据。
fd = open("/dev/ttyS2", O_RDWR); ret = pthread_create(&uart_read_thread,NULL,uart_read_thread_fun,&data); void *uart_read_thread_fun (void *data) { int ThreadFd = fd; struct timeval WaitTime; fd_set fds; int ReadResult=0; FD_ZERO(&fds); FD_SET(ThreadFd,&fds); WaitTime.tv_sec = 0; WaitTime.tv_usec = 100000; printf("in read thread\n"); while(1) { //if(select(ThreadFd+1,&fds,0,0,&WaitTime) > 0) //{ ReadResult = read(ThreadFd,BufForRead,sizeof(BufForRead)); if(ReadResult > 0) { readCount++; printf("data=%s,ret=%d,read count=%ld\n",BufForRead,ReadResult,readCount); } // } //else //{ // printf("read select error\n"); //} } }
UART 端口不支持非阻塞访问。
这是因为内核驱动程序不支持它吗? 是否有方法进行更正。
SDK 版本:
ti-processor-sdk-linux-adas-j722s-evm-10_00_00_08-Linux-x86-Install.bin
谢谢。
您好!
我向我们的内部专家了解了这一点。 反馈是此功能必须来自 TTY 层。 TI UART 驱动程序无法识别阻塞/非阻塞。
更好的 Linux 论坛问题。
我将关闭此文件。
-基尔西
您好!
感谢您的检查和回复。 我现在结束这个问题。