<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software SolutionsのトピックRe: select() on serial port</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251378#M7275</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sorry, but I'm not working on that project now. When I come back to it, I will try the suggestion of David and let you know the result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Mar 2013 07:40:58 GMT</pubDate>
    <dc:creator>pozz</dc:creator>
    <dc:date>2013-03-20T07:40:58Z</dc:date>
    <item>
      <title>select() on serial port</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251375#M7272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using MQX 4.0 with Tower system (Kinetis K60).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm writing a task that communicates to another device through the serial port of TWR-SER board. I'm able to open the port and send/receive bytes on that port without problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I'd like to have a function similar to the classical select() function: I want to put the task in blocked state until a character on the serial port has arrived or a timeout expires. I noticed the select() function is implemented only in RTCS, but not for simple I/O serial port.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The serial protocol I'm implemented is master/slave, where the MQX application is the master. So it sends a packet and waits for the answer. The wait can't be indefinitely, because the other device couldn't be actually connected, so I have to do something if this condition occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can open the serial port in polling non-blocking mode and poll the serial port with fgetc() and make some ticks calculations to detect the timeout:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while(1) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; send_packet();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end = start = _time_ticks();&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(_time_diff(end, start) &amp;lt; TIMEOUT) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = fgetc(serial_port);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (c &amp;gt;= 0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; add_to_rx(c);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (rxpacket_complete()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (rxpacket_complete()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Process the incoming packet */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; clear_rx();&lt;/P&gt;&lt;P&gt;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* No answer */&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But I'd like to avoid this. The task is always running and never goes in blocked mode.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 11:23:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251375#M7272</guid>
      <dc:creator>pozz</dc:creator>
      <dc:date>2013-02-07T11:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: select() on serial port</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251376#M7273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Giuseppe,&lt;/P&gt;&lt;P&gt;Please have a look at an example of timeout for a read() with timeout.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; result_custom = read_custom(fh_ptr,(pointer)bptr,MAX_NUMER_OF_CHARACTERS,INPUT_CHARACTER_DELAY_MILLISECONDS);&amp;nbsp; //DES read 7 character or timeout in X seconds&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not certain this addresses your needs totally but hopefully gets you moving in right direction.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 17:54:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251376#M7273</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2013-03-06T17:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: select() on serial port</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251377#M7274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Giuseppe, is this working now?&lt;/P&gt;&lt;P&gt;Let us know :smileywink:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Mar 2013 23:19:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251377#M7274</guid>
      <dc:creator>Monica</dc:creator>
      <dc:date>2013-03-19T23:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: select() on serial port</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251378#M7275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sorry, but I'm not working on that project now. When I come back to it, I will try the suggestion of David and let you know the result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 07:40:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/select-on-serial-port/m-p/251378#M7275</guid>
      <dc:creator>pozz</dc:creator>
      <dc:date>2013-03-20T07:40:58Z</dc:date>
    </item>
  </channel>
</rss>

