<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[V3s串口连接传感器，读取传感器数据时候出错]]></title><description><![CDATA[<p dir="auto">大佬们，我用v3s串口连接传感器，读取传感器数据时候出错，read(): Resource temporarily unavailable,网上说加select，我加了没用，怎么回事啊</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/select.h&gt;
#include &lt;termios.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;errno.h&gt;

#define SENSOR "/dev/ttyS2"

int main()
{
	int fd,ret;
	struct	termios option;
	char	cRest[]={0xFE, 0x01, 0x0d, 0x8A, 0x80, 0x0d};
	char	cPower_On[]={0xFE, 0x01, 0x0d, 0x0A, 0x00, 0x0d};
	char	cTem[10];
	fd_set rset;
	struct timeval timeout;
	int rv;
	
	fd = open(SENSOR,O_RDWR | O_NONBLOCK);
	if(fd &lt; 0)
	{
		perror("open()");
		return -1;
	}
	if(fd &gt; 0)
	{
		printf("uart2 open successfully!\n");
	}
	
	/*配置串口*/
	memset(&amp;option, 0, sizeof option);
    option.c_iflag = IGNPAR;
	option.c_cflag = B460800 | HUPCL | CS8 | CREAD | CLOCAL;
	option.c_cc[VTIME] = 0;
	option.c_cc[VMIN] = 10;
	
	ret = tcsetattr(fd, TCSANOW, &amp;option);
	if (ret &lt; 0) 
	{
		printf("set USART2-352 failed\n");
		return -1;
	}
	printf("USART2-352 is opened successfully! \n");

	/*配置传感器*/
	write(fd,cRest,6);
	sleep(1);
	write(fd,cPower_On,6);
    while(1)
    {
//		FD_ZERO(&amp;rset);
//		FD_SET(fd,&amp;rset);
//
//		timeout.tv_sec = 5;
//      timeout.tv_usec = 0;
		memset(cTem, 0, 10);
		
//		rv = select(fd+1,&amp;rset,NULL,NULL,&amp;timeout);
//		if(rv &lt; 0){
//			perror("select error");
//			continue;
//			}
//		else if(rv == 0){
//			perror("select timeout");
//			continue;
//			}
//		else
//		{
			ret=read(fd,cTem,10);
			if(ret &lt; 0)
			{
				perror("read()");
				close(fd);
				break;
			}
			if(ret &gt; 0)
			{
				printf("read data : %s\n",cTem);
			}
		//}
    }
	
	close(fd);
	return 0;
}

</code></pre>
<p dir="auto">这是程序，编译没问题，运行成这样</p>
<p dir="auto"><img src="/assets/uploads/files/1698134438878-qq%E5%9B%BE%E7%89%8720231024155932.png" alt="QQ图片20231024155932.png" class=" img-responsive img-markdown" /></p>
]]></description><link>https://bbs.aw-ol.com/topic/4479/v3s串口连接传感器-读取传感器数据时候出错</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 13:52:29 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/4479.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Oct 2023 08:00:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to V3s串口连接传感器，读取传感器数据时候出错 on Mon, 06 Jan 2025 07:48:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://bbs.aw-ol.com/uid/1865">@livpo</a> 在 <a href="/post/19379">v3s串口连接传感器，读取传感器数据时候出错</a> 中说：</p>
<blockquote>
<p dir="auto">能不能打开并通讯，如果可以，说明v3s这个串口驱动有问题</p>
</blockquote>
<p dir="auto">串口直接这样读取，不会存在读取数据不完整，应该有一个中断接收完成的函数把</p>
]]></description><link>https://bbs.aw-ol.com/post/25053</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/25053</guid><dc:creator><![CDATA[honghu886]]></dc:creator><pubDate>Mon, 06 Jan 2025 07:48:44 GMT</pubDate></item><item><title><![CDATA[Reply to V3s串口连接传感器，读取传感器数据时候出错 on Mon, 30 Oct 2023 07:11:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://bbs.aw-ol.com/uid/1865">@livpo</a></p>
<p dir="auto">你好。</p>
<p dir="auto">在控制台中运行命令：<br />
echo 12345 &gt;/dev/ttyS2</p>
<p dir="auto">如果答案是这样的：<br />
write error: Input/output error</p>
<p dir="auto">这意味着问题不在于您的程序，而在于驱动程序。</p>
<p dir="auto">需要在控制台查看 dmesg 命令的输出</p>
]]></description><link>https://bbs.aw-ol.com/post/19494</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/19494</guid><dc:creator><![CDATA[Alb702]]></dc:creator><pubDate>Mon, 30 Oct 2023 07:11:52 GMT</pubDate></item><item><title><![CDATA[Reply to V3s串口连接传感器，读取传感器数据时候出错 on Tue, 24 Oct 2023 08:15:07 GMT]]></title><description><![CDATA[<p dir="auto">先把你的程序在x86上编译测试能不能打开并通讯，如果可以，说明v3s这个串口驱动有问题</p>
]]></description><link>https://bbs.aw-ol.com/post/19379</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/19379</guid><dc:creator><![CDATA[livpo]]></dc:creator><pubDate>Tue, 24 Oct 2023 08:15:07 GMT</pubDate></item></channel></rss>