<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>HOB Techtalk: Programming Applications for PC Serial Ports </title>
    <link>http://www.hob-techtalk.com/articles/2007/09/10/programming-applications-for-pc-serial-ports</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Programming Applications for PC Serial Ports </title>
      <description>1. The Problem &lt;br&gt;&lt;br&gt;
 
On the serial ports of PCs, asynchronous communication is mostly used. This means, every piece of information, which is normally one byte with 7 or 8 bits of information, is sent individually. There are start-bits at the beginning of each character and there are stop-bits at the end of each character. 
Information sent mostly contains multiple characters, forming a block. &lt;br&gt;
The problem now is, that neither the hardware nor the software driver can know how many characters form such a block. &lt;br&gt;
We discuss here how applications handle this type of traffic. &lt;br&gt;&lt;br&gt;
 
2. Applications We Have Seen &lt;br&gt;&lt;br&gt;
 
We have seen applications of other vendors and how they work. The have a buffer of a certain length, for example two kilobytes. They set a very short timeout and receive data in a 
loop. &lt;br&gt;
In Windows, ReadFile() is done, giving the buffer and its entire length.&lt;br&gt; 

The ReadFile() returns when either the entire buffer has been filled by the driver or when the timeout has elapsed. &lt;br&gt;
Now in the loop, there is mostly no data received, and the ReadFile() returns after the short timeout saying it has received nothing. &lt;br&gt;
So these applications constantly give a certain load to the machine they are running on. Another disadvantage of this technique is, that there is also a delay before the application gets the data that have been received, because the buffer normally does not get filled; there are just some bytes received. &lt;br&gt;
This delay is theoretically half of the time of the timeout set. &lt;br&gt;&lt;br&gt;
 
3. HOB Approach for Receiving Data with the Serial Interface &lt;br&gt;&lt;br&gt;
 
In the HOB approach, the serial interface is set for no timeout, or a very long timeout. When data is received by the application, ReadFile() is started, giving a buffer of one byte length. Then the ReadFile() operation returns each and every time a single character has been received, and only then. &lt;br&gt;
During times when no data is received over the serial line, this application does not consume any CPU cycles. &lt;br&gt;
When data are received, CPU load is higher, since there is a context switch for every byte received. 
When data are received, they can be immediately processed by the application without any delay. 


</description>
      <pubDate>Mon, 10 Sep 2007 14:28:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1c11d07f-08a0-443c-a729-fbae1c70b642</guid>
      <author>hob</author>
      <link>http://www.hob-techtalk.com/articles/2007/09/10/programming-applications-for-pc-serial-ports</link>
    </item>
  </channel>
</rss>
