<?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[Serial read is blocking]]></title><description><![CDATA[<p dir="auto">I'm running a serial connection to a sensor wired as simplex.  The code runs fine when the sensor is there. I wanted to turn the LED yellow if the serial read times out and returns no data, but the read function is blocking. It just sits there indefinitely.</p>
<p dir="auto">I am playing around with</p>
<p dir="auto">char buff = {0};<br />
int fd;</p>
<p dir="auto">fd = open("/dev/ttyS1", O_RDONLY | O_NOCTTY | O_NONBLOCK);<br />
struct termios config;<br />
tcgetattr(fd, &amp;config);<br />
config.c_iflag &amp;= ~(IGNBRK | BRKINT | ICRNL |INLCR | PARMRK | INPCK | ISTRIP | IXON);<br />
config.c_oflag = 0;<br />
config.c_lflag &amp;= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);<br />
config.c_cflag &amp;= ~(CSIZE | PARENB);<br />
config.c_cflag |= CS8;<br />
config.c_cc[VMIN]  = 0;<br />
config.c_cc[VTIME] = 10;<br />
cfsetispeed(&amp;config, B57600);<br />
cfsetospeed(&amp;config, B57600);<br />
tcflush(fd, TCIOFLUSH);<br />
tcsetattr(fd, TCSANOW, &amp;config)</p>
<p dir="auto">ret = read(fd, &amp;buff, 1);<br />
if (ret&lt;=0) {<br />
status_yellow();<br />
}</p>
]]></description><link>https://forum.modalai.com/topic/142/serial-read-is-blocking</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Jul 2026 16:29:37 GMT</lastBuildDate><atom:link href="https://forum.modalai.com/topic/142.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Feb 2021 17:58:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Serial read is blocking on Fri, 26 Feb 2021 16:52:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/andrew-keefe" aria-label="Profile: Andrew-Keefe">@<bdi>Andrew-Keefe</bdi></a>,</p>
<p dir="auto">I'm not positive on this one.  I have an example of using UART for an ESC here, and I remember having to be careful what task was opening the UART port:</p>
<p dir="auto"></p><div class="card col-md-9 col-lg-6 position-relative link-preview p-0">



<a href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp" title="px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp at modalai-1.11 · modalai/px4-firmware">
<img src="https://opengraph.githubassets.com/ce1bea1e95d6e0d06a62e8826c5596483145fbfc673f099d58846b8c0703502b/modalai/px4-firmware" class="card-img-top not-responsive" style="max-height:15rem" alt="Link Preview Image" />
</a>



<div class="card-body">
<h5 class="card-title">
<a class="text-decoration-none" href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp">
px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp at modalai-1.11 · modalai/px4-firmware
</a>
</h5>
<p class="card-text line-clamp-3">PX4 Autopilot Software. Contribute to modalai/px4-firmware development by creating an account on GitHub.</p>
</div>
<a href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc.cpp" class="card-footer text-body-secondary small d-flex gap-2 align-items-center lh-2">



<img src="https://github.githubassets.com/favicons/favicon.svg" alt="favicon" class="not-responsive overflow-hiddden" style="max-width:21px;max-height:21px" />



<p class="d-inline-block text-truncate mb-0">GitHub <span class="text-secondary">(github.com)</span></p>
</a>
</div><p></p>
<p dir="auto">Here's opening of the port (note: this is beta level code)</p>
<p dir="auto"></p><div class="card col-md-9 col-lg-6 position-relative link-preview p-0">



<a href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp" title="px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp at modalai-1.11 · modalai/px4-firmware">
<img src="https://opengraph.githubassets.com/ce1bea1e95d6e0d06a62e8826c5596483145fbfc673f099d58846b8c0703502b/modalai/px4-firmware" class="card-img-top not-responsive" style="max-height:15rem" alt="Link Preview Image" />
</a>



<div class="card-body">
<h5 class="card-title">
<a class="text-decoration-none" href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp">
px4-firmware/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp at modalai-1.11 · modalai/px4-firmware
</a>
</h5>
<p class="card-text line-clamp-3">PX4 Autopilot Software. Contribute to modalai/px4-firmware development by creating an account on GitHub.</p>
</div>
<a href="https://github.com/modalai/px4-firmware/blob/modalai-1.11/src/drivers/uart_esc/modalai_esc/modalai_esc_serial.cpp" class="card-footer text-body-secondary small d-flex gap-2 align-items-center lh-2">



<img src="https://github.githubassets.com/favicons/favicon.svg" alt="favicon" class="not-responsive overflow-hiddden" style="max-width:21px;max-height:21px" />



<p class="d-inline-block text-truncate mb-0">GitHub <span class="text-secondary">(github.com)</span></p>
</a>
</div><p></p>
]]></description><link>https://forum.modalai.com/post/627</link><guid isPermaLink="true">https://forum.modalai.com/post/627</guid><dc:creator><![CDATA[modaltb]]></dc:creator><pubDate>Fri, 26 Feb 2021 16:52:50 GMT</pubDate></item></channel></rss>