<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3035002048794942023</id><updated>2011-11-27T15:19:22.202-08:00</updated><title type='text'>serial-programming-in-win32-os</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>43</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-3341548991505897545</id><published>2008-07-22T22:21:00.000-07:00</published><updated>2008-07-22T22:24:30.445-07:00</updated><title type='text'>convert linux code to windows serial port programming code</title><content type='html'>&lt;span class="c"&gt;&lt;/span&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"winsup.h"&lt;/span&gt;&lt;br /&gt;&lt;div id="CodeDiv"&gt;&lt;pre&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"&lt;/span&gt;&lt;a title="Search for references of 'fcntl'" href="javascript:searchRef('fcntl')" class="r"&gt;fcntl&lt;/a&gt;.&lt;a title="Search for references of 'h'" href="javascript:searchRef('h')" class="r"&gt;h&lt;span class="str"&gt;"&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"&lt;/span&gt;&lt;a title="Search for references of 'errno'" href="javascript:searchRef('errno')" class="r"&gt;errno&lt;/a&gt;.&lt;a title="Search for references of 'h'" href="javascript:searchRef('h')" class="r"&gt;h&lt;/a&gt;&lt;span class="str"&gt;"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"&lt;/span&gt;&lt;a title="Search for references of 'unistd'" href="javascript:searchRef('unistd')" class="r"&gt;unistd&lt;/a&gt;.&lt;a title="Search for references of 'h'" href="javascript:searchRef('h')" class="r"&gt;h&lt;/a&gt;&lt;span class="str"&gt;"&lt;br /&gt;&lt;/span&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"&lt;/span&gt;&lt;a title="Search for references of 'stdlib'" href="javascript:searchRef('stdlib')" class="r"&gt;stdlib&lt;/a&gt;.&lt;a title="Search for references of 'h'" href="javascript:searchRef('h')" class="r"&gt;h&lt;/a&gt;&lt;span class="str"&gt;"&lt;br /&gt;&lt;/span&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"cygerrno.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"security.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"fhandler.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"sync.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"sigproc.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;span class="str"&gt;"pinfo.h"&lt;/span&gt;&lt;br /&gt;#&lt;a title="Search for references of 'include'" href="javascript:searchRef('include')" class="r"&gt;include&lt;/a&gt; &lt;&lt;a title="Search for references of 'sys'" href="javascript:searchRef('sys')" class="r"&gt;sys&lt;/a&gt;/&lt;a title="Search for references of 'termios'" href="javascript:searchRef('termios')" class="r"&gt;termios&lt;/a&gt;.&lt;a title="Search for references of 'h'" href="javascript:searchRef('h')" class="r"&gt;h&lt;/a&gt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/**********************************************************************/&lt;/span&gt;&lt;br /&gt;&lt;span class="c"&gt;/* fhandler_serial */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt; (&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="k"&gt;char&lt;/span&gt; *&lt;a title="Search for references of 'name'" href="javascript:searchRef('name')" class="r"&gt;name&lt;/a&gt;, &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'devtype'" href="javascript:searchRef('devtype')" class="r"&gt;devtype&lt;/a&gt;, &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'unit'" href="javascript:searchRef('unit')" class="r"&gt;unit&lt;/a&gt;) :&lt;br /&gt; &lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt; (&lt;a title="Search for references of 'devtype'" href="javascript:searchRef('devtype')" class="r"&gt;devtype&lt;/a&gt;, &lt;a title="Search for references of 'name'" href="javascript:searchRef('name')" class="r"&gt;name&lt;/a&gt;, &lt;a title="Search for references of 'unit'" href="javascript:searchRef('unit')" class="r"&gt;unit&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'set_cb'" href="javascript:searchRef('set_cb')" class="r"&gt;set_cb&lt;/a&gt; (&lt;span class="k"&gt;sizeof&lt;/span&gt; *&lt;span class="k"&gt;this&lt;/span&gt;);&lt;br /&gt; &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; = 0;&lt;br /&gt; &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; = 0;&lt;br /&gt; &lt;a title="Search for references of 'pgrp_'" href="javascript:searchRef('pgrp_')" class="r"&gt;pgrp_&lt;/a&gt; = &lt;a title="Search for references of 'myself'" href="javascript:searchRef('myself')" class="r"&gt;myself&lt;/a&gt;-&gt;&lt;a title="Search for references of 'pgid'" href="javascript:searchRef('pgid')" class="r"&gt;pgid&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'set_need_fork_fixup'" href="javascript:searchRef('set_need_fork_fixup')" class="r"&gt;set_need_fork_fixup&lt;/a&gt; ();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'overlapped_setup'" href="javascript:searchRef('overlapped_setup')" class="r"&gt;overlapped_setup&lt;/a&gt; ()&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'memset'" href="javascript:searchRef('memset')" class="r"&gt;memset&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;, 0, &lt;span class="k"&gt;sizeof&lt;/span&gt; (&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;));&lt;br /&gt; &lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt; = &lt;a title="Search for references of 'CreateEvent'" href="javascript:searchRef('CreateEvent')" class="r"&gt;CreateEvent&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'sec_none_nih'" href="javascript:searchRef('sec_none_nih')" class="r"&gt;sec_none_nih&lt;/a&gt;, &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;, &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;, &lt;a title="Search for references of 'NULL'" href="javascript:searchRef('NULL')" class="r"&gt;NULL&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'ProtectHandle'" href="javascript:searchRef('ProtectHandle')" class="r"&gt;ProtectHandle&lt;/a&gt; (&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt; = 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'raw_read'" href="javascript:searchRef('raw_read')" class="r"&gt;raw_read&lt;/a&gt; (&lt;span class="k"&gt;void&lt;/span&gt; *&lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt;, &lt;a title="Search for references of 'size_t'" href="javascript:searchRef('size_t')" class="r"&gt;size_t&lt;/a&gt; &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'HANDLE'" href="javascript:searchRef('HANDLE')" class="r"&gt;HANDLE&lt;/a&gt; &lt;a title="Search for references of 'w4'" href="javascript:searchRef('w4')" class="r"&gt;w4&lt;/a&gt;[2];&lt;br /&gt; &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'minchars'" href="javascript:searchRef('minchars')" class="r"&gt;minchars&lt;/a&gt; = &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; ?: &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'w4'" href="javascript:searchRef('w4')" class="r"&gt;w4&lt;/a&gt;[0] = &lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'w4'" href="javascript:searchRef('w4')" class="r"&gt;w4&lt;/a&gt;[1] = &lt;a title="Search for references of 'signal_arrived'" href="javascript:searchRef('signal_arrived')" class="r"&gt;signal_arrived&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"ulen %d, vmin_ %d, vtime_ %d, hEvent %p"&lt;/span&gt;, &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;, &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;, &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;,&lt;br /&gt;  &lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     (&lt;span class="k"&gt;void&lt;/span&gt;) &lt;a title="Search for references of 'SetCommMask'" href="javascript:searchRef('SetCommMask')" class="r"&gt;SetCommMask&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'EV_RXCHAR'" href="javascript:searchRef('EV_RXCHAR')" class="r"&gt;EV_RXCHAR&lt;/a&gt;);&lt;br /&gt;     &lt;a title="Search for references of 'ResetEvent'" href="javascript:searchRef('ResetEvent')" class="r"&gt;ResetEvent&lt;/a&gt; (&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;for&lt;/span&gt; (&lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt; = 0, &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt; = 0; &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;; &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt; -= &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt; = (&lt;span class="k"&gt;char&lt;/span&gt; *)&lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt; + &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'COMSTAT'" href="javascript:searchRef('COMSTAT')" class="r"&gt;COMSTAT&lt;/a&gt; &lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; = 1;&lt;br /&gt;&lt;br /&gt;     &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt; = 0;&lt;br /&gt;&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; &amp;amp;&amp;amp; !&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; = &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;)&lt;br /&gt; {&lt;br /&gt;   &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; = &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;; &lt;span class="c"&gt;// non-interruptible -- have to use kernel timeouts&lt;br /&gt;&lt;/span&gt;   &lt;span class="c"&gt;// also note that this is not strictly correct.&lt;br /&gt;&lt;/span&gt;   &lt;span class="c"&gt;// if vmin &gt; ulen then things won't work right.&lt;br /&gt;&lt;/span&gt;   &lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt; = -1;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'ClearCommError'" href="javascript:searchRef('ClearCommError')" class="r"&gt;ClearCommError&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;))&lt;br /&gt; &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"error detected %x"&lt;/span&gt;, &lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;);&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;.&lt;a title="Search for references of 'cbInQue'" href="javascript:searchRef('cbInQue')" class="r"&gt;cbInQue&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; = &lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;.&lt;a title="Search for references of 'cbInQue'" href="javascript:searchRef('cbInQue')" class="r"&gt;cbInQue&lt;/a&gt;;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt;)&lt;br /&gt; {&lt;br /&gt;   &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'size_t'" href="javascript:searchRef('size_t')" class="r"&gt;size_t&lt;/a&gt;)&lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt; &gt;= &lt;a title="Search for references of 'minchars'" href="javascript:searchRef('minchars')" class="r"&gt;minchars&lt;/a&gt;)&lt;br /&gt;     &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;   &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'WaitCommEvent'" href="javascript:searchRef('WaitCommEvent')" class="r"&gt;WaitCommEvent&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;))&lt;br /&gt;     {&lt;br /&gt;       &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"WaitCommEvent succeeded: ev %x"&lt;/span&gt;, &lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;);&lt;br /&gt;       &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;)&lt;br /&gt;  &lt;span class="k"&gt;continue&lt;/span&gt;;&lt;br /&gt;     }&lt;br /&gt;   &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'GetLastError'" href="javascript:searchRef('GetLastError')" class="r"&gt;GetLastError&lt;/a&gt; () != &lt;a title="Search for references of 'ERROR_IO_PENDING'" href="javascript:searchRef('ERROR_IO_PENDING')" class="r"&gt;ERROR_IO_PENDING&lt;/a&gt;)&lt;br /&gt;     &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;   &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;     {&lt;br /&gt;       &lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt; = 1;&lt;br /&gt;       &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 'WaitForMultipleObjects'" href="javascript:searchRef('WaitForMultipleObjects')" class="r"&gt;WaitForMultipleObjects&lt;/a&gt; (2, &lt;a title="Search for references of 'w4'" href="javascript:searchRef('w4')" class="r"&gt;w4&lt;/a&gt;, &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;, &lt;a title="Search for references of 'INFINITE'" href="javascript:searchRef('INFINITE')" class="r"&gt;INFINITE&lt;/a&gt;))&lt;br /&gt;  {&lt;br /&gt;  &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'WAIT_OBJECT_0'" href="javascript:searchRef('WAIT_OBJECT_0')" class="r"&gt;WAIT_OBJECT_0&lt;/a&gt;:&lt;br /&gt;    &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'GetOverlappedResult'" href="javascript:searchRef('GetOverlappedResult')" class="r"&gt;GetOverlappedResult&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;))&lt;br /&gt;      &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;    &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"n %d, ev %x"&lt;/span&gt;, &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;);&lt;br /&gt;    &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;  &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'WAIT_OBJECT_0'" href="javascript:searchRef('WAIT_OBJECT_0')" class="r"&gt;WAIT_OBJECT_0&lt;/a&gt; + 1:&lt;br /&gt;    &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt; = -1;&lt;br /&gt;    &lt;a title="Search for references of 'PurgeComm'" href="javascript:searchRef('PurgeComm')" class="r"&gt;PurgeComm&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'PURGE_RXABORT'" href="javascript:searchRef('PURGE_RXABORT')" class="r"&gt;PURGE_RXABORT&lt;/a&gt;);&lt;br /&gt;    &lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt; = 0;&lt;br /&gt;    &lt;a title="Search for references of 'set_sig_errno'" href="javascript:searchRef('set_sig_errno')" class="r"&gt;set_sig_errno&lt;/a&gt; (&lt;a title="Search for references of 'EINTR'" href="javascript:searchRef('EINTR')" class="r"&gt;EINTR&lt;/a&gt;);&lt;br /&gt;    &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'out'" href="javascript:searchRef('out')" class="r"&gt;out&lt;/a&gt;;&lt;br /&gt;  &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt;    &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;  }&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;     &lt;a title="Search for references of 'overlapped_armed'" href="javascript:searchRef('overlapped_armed')" class="r"&gt;overlapped_armed&lt;/a&gt; = 0;&lt;br /&gt;     &lt;a title="Search for references of 'ResetEvent'" href="javascript:searchRef('ResetEvent')" class="r"&gt;ResetEvent&lt;/a&gt; (&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; &gt; &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt; = &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"inq %d"&lt;/span&gt;, &lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt;);&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'ReadFile'" href="javascript:searchRef('ReadFile')" class="r"&gt;ReadFile&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt;(), &lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt;, &lt;a title="Search for references of 'min'" href="javascript:searchRef('min')" class="r"&gt;min&lt;/a&gt; (&lt;a title="Search for references of 'inq'" href="javascript:searchRef('inq')" class="r"&gt;inq&lt;/a&gt;, &lt;a title="Search for references of 'ulen'" href="javascript:searchRef('ulen')" class="r"&gt;ulen&lt;/a&gt;), &amp;amp;&lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;))&lt;br /&gt; &lt;span class="c"&gt;/* Got something */&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'GetLastError'" href="javascript:searchRef('GetLastError')" class="r"&gt;GetLastError&lt;/a&gt; () != &lt;a title="Search for references of 'ERROR_IO_PENDING'" href="javascript:searchRef('ERROR_IO_PENDING')" class="r"&gt;ERROR_IO_PENDING&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'GetOverlappedResult'" href="javascript:searchRef('GetOverlappedResult')" class="r"&gt;GetOverlappedResult&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;))&lt;br /&gt; &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;     &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt; += &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"vtime_ %d, vmin_ %d, n %d, tot %d"&lt;/span&gt;, &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;, &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;, &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;, &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt;);&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; || !&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; || !&lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt;)&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;continue&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;   &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;:&lt;br /&gt;     &lt;a title="Search for references of 'PurgeComm'" href="javascript:searchRef('PurgeComm')" class="r"&gt;PurgeComm&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'PURGE_RXABORT'" href="javascript:searchRef('PURGE_RXABORT')" class="r"&gt;PURGE_RXABORT&lt;/a&gt;);&lt;br /&gt;     &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"err %E"&lt;/span&gt;);&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'GetLastError'" href="javascript:searchRef('GetLastError')" class="r"&gt;GetLastError&lt;/a&gt; () == &lt;a title="Search for references of 'ERROR_OPERATION_ABORTED'" href="javascript:searchRef('ERROR_OPERATION_ABORTED')" class="r"&gt;ERROR_OPERATION_ABORTED&lt;/a&gt;)&lt;br /&gt; &lt;a title="Search for references of 'n'" href="javascript:searchRef('n')" class="r"&gt;n&lt;/a&gt; = 0;&lt;br /&gt;     &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt; {&lt;br /&gt;   &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt; = -1;&lt;br /&gt;   &lt;a title="Search for references of '__seterrno'" href="javascript:searchRef('__seterrno')" class="r"&gt;__seterrno&lt;/a&gt; ();&lt;br /&gt;   &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt; }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;a title="Search for references of 'out'" href="javascript:searchRef('out')" class="r"&gt;out&lt;/a&gt;:&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;a title="Search for references of 'tot'" href="javascript:searchRef('tot')" class="r"&gt;tot&lt;/a&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* Cover function to WriteFile to provide Posix interface and semantics&lt;br /&gt;  (as much as possible).  */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'raw_write'" href="javascript:searchRef('raw_write')" class="r"&gt;raw_write&lt;/a&gt; (&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; *&lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt;, &lt;a title="Search for references of 'size_t'" href="javascript:searchRef('size_t')" class="r"&gt;size_t&lt;/a&gt; &lt;a title="Search for references of 'len'" href="javascript:searchRef('len')" class="r"&gt;len&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'bytes_written'" href="javascript:searchRef('bytes_written')" class="r"&gt;bytes_written&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'OVERLAPPED'" href="javascript:searchRef('OVERLAPPED')" class="r"&gt;OVERLAPPED&lt;/a&gt; &lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'memset'" href="javascript:searchRef('memset')" class="r"&gt;memset&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;, 0, &lt;span class="k"&gt;sizeof&lt;/span&gt; (&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;));&lt;br /&gt; &lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt; = &lt;a title="Search for references of 'CreateEvent'" href="javascript:searchRef('CreateEvent')" class="r"&gt;CreateEvent&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'sec_none_nih'" href="javascript:searchRef('sec_none_nih')" class="r"&gt;sec_none_nih&lt;/a&gt;, &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;, &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;, &lt;a title="Search for references of 'NULL'" href="javascript:searchRef('NULL')" class="r"&gt;NULL&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'ProtectHandle'" href="javascript:searchRef('ProtectHandle')" class="r"&gt;ProtectHandle&lt;/a&gt; (&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;for&lt;/span&gt; (;;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'WriteFile'" href="javascript:searchRef('WriteFile')" class="r"&gt;WriteFile&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt;(), &lt;a title="Search for references of 'ptr'" href="javascript:searchRef('ptr')" class="r"&gt;ptr&lt;/a&gt;, &lt;a title="Search for references of 'len'" href="javascript:searchRef('len')" class="r"&gt;len&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'bytes_written'" href="javascript:searchRef('bytes_written')" class="r"&gt;bytes_written&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;))&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;     &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 'GetLastError'" href="javascript:searchRef('GetLastError')" class="r"&gt;GetLastError&lt;/a&gt; ())&lt;br /&gt; {&lt;br /&gt;   &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'ERROR_OPERATION_ABORTED'" href="javascript:searchRef('ERROR_OPERATION_ABORTED')" class="r"&gt;ERROR_OPERATION_ABORTED&lt;/a&gt;:&lt;br /&gt;     &lt;span class="k"&gt;continue&lt;/span&gt;;&lt;br /&gt;   &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'ERROR_IO_PENDING'" href="javascript:searchRef('ERROR_IO_PENDING')" class="r"&gt;ERROR_IO_PENDING&lt;/a&gt;:&lt;br /&gt;     &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;   &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt;     &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'GetOverlappedResult'" href="javascript:searchRef('GetOverlappedResult')" class="r"&gt;GetOverlappedResult&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'bytes_written'" href="javascript:searchRef('bytes_written')" class="r"&gt;bytes_written&lt;/a&gt;, &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;))&lt;br /&gt; &lt;a title="Search for references of 'goto'" href="javascript:searchRef('goto')" class="r"&gt;goto&lt;/a&gt; &lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;     &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'ForceCloseHandle'" href="javascript:searchRef('ForceCloseHandle')" class="r"&gt;ForceCloseHandle&lt;/a&gt;(&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;a title="Search for references of 'bytes_written'" href="javascript:searchRef('bytes_written')" class="r"&gt;bytes_written&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;a title="Search for references of 'err'" href="javascript:searchRef('err')" class="r"&gt;err&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of '__seterrno'" href="javascript:searchRef('__seterrno')" class="r"&gt;__seterrno&lt;/a&gt; ();&lt;br /&gt; &lt;a title="Search for references of 'ForceCloseHandle'" href="javascript:searchRef('ForceCloseHandle')" class="r"&gt;ForceCloseHandle&lt;/a&gt;(&lt;a title="Search for references of 'write_status'" href="javascript:searchRef('write_status')" class="r"&gt;write_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'dump'" href="javascript:searchRef('dump')" class="r"&gt;dump&lt;/a&gt; (&lt;span class="k"&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'paranoid_printf'" href="javascript:searchRef('paranoid_printf')" class="r"&gt;paranoid_printf&lt;/a&gt; (&lt;span class="str"&gt;"here"&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'init'" href="javascript:searchRef('init')" class="r"&gt;init&lt;/a&gt; (&lt;a title="Search for references of 'HANDLE'" href="javascript:searchRef('HANDLE')" class="r"&gt;HANDLE&lt;/a&gt; &lt;a title="Search for references of 'f'" href="javascript:searchRef('f')" class="r"&gt;f&lt;/a&gt;, &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'mode_t'" href="javascript:searchRef('mode_t')" class="r"&gt;mode_t&lt;/a&gt; &lt;a title="Search for references of 'bin'" href="javascript:searchRef('bin')" class="r"&gt;bin&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt;::&lt;a title="Search for references of 'init'" href="javascript:searchRef('init')" class="r"&gt;init&lt;/a&gt; (&lt;a title="Search for references of 'f'" href="javascript:searchRef('f')" class="r"&gt;f&lt;/a&gt;, &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'bin'" href="javascript:searchRef('bin')" class="r"&gt;bin&lt;/a&gt;);&lt;br /&gt; (&lt;span class="k"&gt;void&lt;/span&gt;) &lt;a title="Search for references of 'open'" href="javascript:searchRef('open')" class="r"&gt;open&lt;/a&gt; (&lt;a title="Search for references of 'NULL'" href="javascript:searchRef('NULL')" class="r"&gt;NULL&lt;/a&gt;, &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'bin'" href="javascript:searchRef('bin')" class="r"&gt;bin&lt;/a&gt; ? &lt;a title="Search for references of 'O_BINARY'" href="javascript:searchRef('O_BINARY')" class="r"&gt;O_BINARY&lt;/a&gt; : 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'open'" href="javascript:searchRef('open')" class="r"&gt;open&lt;/a&gt; (&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="k"&gt;char&lt;/span&gt; *&lt;a title="Search for references of 'name'" href="javascript:searchRef('name')" class="r"&gt;name&lt;/a&gt;, &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'mode_t'" href="javascript:searchRef('mode_t')" class="r"&gt;mode_t&lt;/a&gt; &lt;a title="Search for references of 'mode'" href="javascript:searchRef('mode')" class="r"&gt;mode&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'COMMTIMEOUTS'" href="javascript:searchRef('COMMTIMEOUTS')" class="r"&gt;COMMTIMEOUTS&lt;/a&gt; &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;extern&lt;/span&gt; &lt;a title="Search for references of 'BOOL'" href="javascript:searchRef('BOOL')" class="r"&gt;BOOL&lt;/a&gt; &lt;a title="Search for references of 'reset_com'" href="javascript:searchRef('reset_com')" class="r"&gt;reset_com&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'syscall_printf'" href="javascript:searchRef('syscall_printf')" class="r"&gt;syscall_printf&lt;/a&gt; (&lt;span class="str"&gt;"fhandler_serial::open (%s, %p, %p)"&lt;/span&gt;,&lt;br /&gt;   &lt;a title="Search for references of 'get_name'" href="javascript:searchRef('get_name')" class="r"&gt;get_name&lt;/a&gt; (), &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'mode'" href="javascript:searchRef('mode')" class="r"&gt;mode&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'name'" href="javascript:searchRef('name')" class="r"&gt;name&lt;/a&gt; &amp;amp;&amp;amp; !(&lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt; = &lt;span class="k"&gt;this&lt;/span&gt;-&gt;&lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt;::&lt;a title="Search for references of 'open'" href="javascript:searchRef('open')" class="r"&gt;open&lt;/a&gt; (&lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'mode'" href="javascript:searchRef('mode')" class="r"&gt;mode&lt;/a&gt;)))&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt; = 1;&lt;br /&gt;&lt;br /&gt; (&lt;span class="k"&gt;void&lt;/span&gt;) &lt;a title="Search for references of 'SetCommMask'" href="javascript:searchRef('SetCommMask')" class="r"&gt;SetCommMask&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'EV_RXCHAR'" href="javascript:searchRef('EV_RXCHAR')" class="r"&gt;EV_RXCHAR&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'set_r_no_interrupt'" href="javascript:searchRef('set_r_no_interrupt')" class="r"&gt;set_r_no_interrupt&lt;/a&gt; (1); &lt;span class="c"&gt;// Handled explicitly in read code&lt;br /&gt;&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'overlapped_setup'" href="javascript:searchRef('overlapped_setup')" class="r"&gt;overlapped_setup&lt;/a&gt; ();&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'memset'" href="javascript:searchRef('memset')" class="r"&gt;memset&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;, 0, &lt;span class="k"&gt;sizeof&lt;/span&gt; (&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;));&lt;br /&gt; (&lt;span class="k"&gt;void&lt;/span&gt;) &lt;a title="Search for references of 'SetCommTimeouts'" href="javascript:searchRef('SetCommTimeouts')" class="r"&gt;SetCommTimeouts&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Reset serial port to known state of 9600-8-1-no flow control&lt;br /&gt;    on open for better behavior under Win 95.&lt;br /&gt;&lt;br /&gt;    FIXME:  This should only be done when explicitly opening the com&lt;br /&gt;    port.  It should not be reset if an fd is inherited.&lt;br /&gt;    Using __progname in this way, to determine how far along in the&lt;br /&gt;    initialization we are, is really a terrible kludge and should&lt;br /&gt;    be fixed ASAP.&lt;br /&gt; */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="k"&gt;char&lt;/span&gt; *&lt;a title="Search for references of '__progname'" href="javascript:searchRef('__progname')" class="r"&gt;__progname&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'reset_com'" href="javascript:searchRef('reset_com')" class="r"&gt;reset_com&lt;/a&gt; &amp;amp;&amp;amp; &lt;a title="Search for references of '__progname'" href="javascript:searchRef('__progname')" class="r"&gt;__progname&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'DCB'" href="javascript:searchRef('DCB')" class="r"&gt;DCB&lt;/a&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'GetCommState'" href="javascript:searchRef('GetCommState')" class="r"&gt;GetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;);&lt;br /&gt;     &lt;a title="Search for references of 'syscall_printf'" href="javascript:searchRef('syscall_printf')" class="r"&gt;syscall_printf&lt;/a&gt; (&lt;span class="str"&gt;"setting initial state on %s (reset_com %d)"&lt;/span&gt;,&lt;br /&gt;        &lt;a title="Search for references of 'get_name'" href="javascript:searchRef('get_name')" class="r"&gt;get_name&lt;/a&gt; (), &lt;a title="Search for references of 'reset_com'" href="javascript:searchRef('reset_com')" class="r"&gt;reset_com&lt;/a&gt;);&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_9600'" href="javascript:searchRef('CBR_9600')" class="r"&gt;CBR_9600&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt; = 8;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'StopBits'" href="javascript:searchRef('StopBits')" class="r"&gt;StopBits&lt;/a&gt; = &lt;a title="Search for references of 'ONESTOPBIT'" href="javascript:searchRef('ONESTOPBIT')" class="r"&gt;ONESTOPBIT&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'Parity'" href="javascript:searchRef('Parity')" class="r"&gt;Parity&lt;/a&gt; = &lt;a title="Search for references of 'NOPARITY'" href="javascript:searchRef('NOPARITY')" class="r"&gt;NOPARITY&lt;/a&gt;; &lt;span class="c"&gt;/* FIXME: correct default? */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fBinary'" href="javascript:searchRef('fBinary')" class="r"&gt;fBinary&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;; &lt;span class="c"&gt;/* binary xfer */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'EofChar'" href="javascript:searchRef('EofChar')" class="r"&gt;EofChar&lt;/a&gt; = 0; &lt;span class="c"&gt;/* no end-of-data in binary mode */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fNull'" href="javascript:searchRef('fNull')" class="r"&gt;fNull&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* don't discard nulls in binary mode */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fParity'" href="javascript:searchRef('fParity')" class="r"&gt;fParity&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* ignore parity errors */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fErrorChar'" href="javascript:searchRef('fErrorChar')" class="r"&gt;fErrorChar&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fTXContinueOnXoff'" href="javascript:searchRef('fTXContinueOnXoff')" class="r"&gt;fTXContinueOnXoff&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;; &lt;span class="c"&gt;/* separate TX and RX flow control */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutX'" href="javascript:searchRef('fOutX')" class="r"&gt;fOutX&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* disable transmission flow control */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fInX'" href="javascript:searchRef('fInX')" class="r"&gt;fInX&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* disable reception flow control */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; = 0x11;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; = 0x13;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxDsrFlow'" href="javascript:searchRef('fOutxDsrFlow')" class="r"&gt;fOutxDsrFlow&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* disable DSR flow control */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; = &lt;a title="Search for references of 'RTS_CONTROL_ENABLE'" href="javascript:searchRef('RTS_CONTROL_ENABLE')" class="r"&gt;RTS_CONTROL_ENABLE&lt;/a&gt;; &lt;span class="c"&gt;/* ignore lead control except&lt;br /&gt;        DTR */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxCtsFlow'" href="javascript:searchRef('fOutxCtsFlow')" class="r"&gt;fOutxCtsFlow&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* disable output flow control */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDtrControl'" href="javascript:searchRef('fDtrControl')" class="r"&gt;fDtrControl&lt;/a&gt; = &lt;a title="Search for references of 'DTR_CONTROL_ENABLE'" href="javascript:searchRef('DTR_CONTROL_ENABLE')" class="r"&gt;DTR_CONTROL_ENABLE&lt;/a&gt;; &lt;span class="c"&gt;/* assert DTR */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDsrSensitivity'" href="javascript:searchRef('fDsrSensitivity')" class="r"&gt;fDsrSensitivity&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;; &lt;span class="c"&gt;/* don't assert DSR */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fAbortOnError'" href="javascript:searchRef('fAbortOnError')" class="r"&gt;fAbortOnError&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;&lt;br /&gt;     &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'SetCommState'" href="javascript:searchRef('SetCommState')" class="r"&gt;SetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;))&lt;br /&gt; &lt;a title="Search for references of 'system_printf'" href="javascript:searchRef('system_printf')" class="r"&gt;system_printf&lt;/a&gt; (&lt;span class="str"&gt;"couldn't set initial state for %s, %E"&lt;/span&gt;, &lt;a title="Search for references of 'get_name'" href="javascript:searchRef('get_name')" class="r"&gt;get_name&lt;/a&gt; ());&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'SetCommMask'" href="javascript:searchRef('SetCommMask')" class="r"&gt;SetCommMask&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'EV_RXCHAR'" href="javascript:searchRef('EV_RXCHAR')" class="r"&gt;EV_RXCHAR&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'set_open_status'" href="javascript:searchRef('set_open_status')" class="r"&gt;set_open_status&lt;/a&gt; ();&lt;br /&gt; &lt;a title="Search for references of 'syscall_printf'" href="javascript:searchRef('syscall_printf')" class="r"&gt;syscall_printf&lt;/a&gt; (&lt;span class="str"&gt;"%p = fhandler_serial::open (%s, %p, %p)"&lt;/span&gt;,&lt;br /&gt;   &lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt;, &lt;a title="Search for references of 'get_name'" href="javascript:searchRef('get_name')" class="r"&gt;get_name&lt;/a&gt; (), &lt;a title="Search for references of 'flags'" href="javascript:searchRef('flags')" class="r"&gt;flags&lt;/a&gt;, &lt;a title="Search for references of 'mode'" href="javascript:searchRef('mode')" class="r"&gt;mode&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'close'" href="javascript:searchRef('close')" class="r"&gt;close&lt;/a&gt; ()&lt;br /&gt;{&lt;br /&gt; (&lt;span class="k"&gt;void&lt;/span&gt;) &lt;a title="Search for references of 'ForceCloseHandle'" href="javascript:searchRef('ForceCloseHandle')" class="r"&gt;ForceCloseHandle&lt;/a&gt; (&lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt;::&lt;a title="Search for references of 'close'" href="javascript:searchRef('close')" class="r"&gt;close&lt;/a&gt; ();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcsendbreak: POSIX 7.2.2.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="c"&gt;/* Break for 250-500 milliseconds if duration == 0 */&lt;/span&gt;&lt;br /&gt;&lt;span class="c"&gt;/* Otherwise, units for duration are undefined */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcsendbreak'" href="javascript:searchRef('tcsendbreak')" class="r"&gt;tcsendbreak&lt;/a&gt; (&lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'duration'" href="javascript:searchRef('duration')" class="r"&gt;duration&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;unsigned&lt;/span&gt; &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'sleeptime'" href="javascript:searchRef('sleeptime')" class="r"&gt;sleeptime&lt;/a&gt; = 300000;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'duration'" href="javascript:searchRef('duration')" class="r"&gt;duration&lt;/a&gt; &gt; 0)&lt;br /&gt;   &lt;a title="Search for references of 'sleeptime'" href="javascript:searchRef('sleeptime')" class="r"&gt;sleeptime&lt;/a&gt; *= &lt;a title="Search for references of 'duration'" href="javascript:searchRef('duration')" class="r"&gt;duration&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'SetCommBreak'" href="javascript:searchRef('SetCommBreak')" class="r"&gt;SetCommBreak&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; ()) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* FIXME: need to send zero bits during duration */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'usleep'" href="javascript:searchRef('usleep')" class="r"&gt;usleep&lt;/a&gt; (&lt;a title="Search for references of 'sleeptime'" href="javascript:searchRef('sleeptime')" class="r"&gt;sleeptime&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'ClearCommBreak'" href="javascript:searchRef('ClearCommBreak')" class="r"&gt;ClearCommBreak&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; ()) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'syscall_printf'" href="javascript:searchRef('syscall_printf')" class="r"&gt;syscall_printf&lt;/a&gt; (&lt;span class="str"&gt;"0 = fhandler_serial:tcsendbreak (%d)"&lt;/span&gt;, &lt;a title="Search for references of 'duration'" href="javascript:searchRef('duration')" class="r"&gt;duration&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcdrain: POSIX 7.2.2.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcdrain'" href="javascript:searchRef('tcdrain')" class="r"&gt;tcdrain&lt;/a&gt; (&lt;span class="k"&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'FlushFileBuffers'" href="javascript:searchRef('FlushFileBuffers')" class="r"&gt;FlushFileBuffers&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; ()) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcflow: POSIX 7.2.2.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcflow'" href="javascript:searchRef('tcflow')" class="r"&gt;tcflow&lt;/a&gt; (&lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'win32action'" href="javascript:searchRef('win32action')" class="r"&gt;win32action&lt;/a&gt; = 0;&lt;br /&gt; &lt;a title="Search for references of 'DCB'" href="javascript:searchRef('DCB')" class="r"&gt;DCB&lt;/a&gt; &lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;char&lt;/span&gt; &lt;a title="Search for references of 'xchar'" href="javascript:searchRef('xchar')" class="r"&gt;xchar&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"action %d"&lt;/span&gt;, &lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'TCOOFF'" href="javascript:searchRef('TCOOFF')" class="r"&gt;TCOOFF&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'win32action'" href="javascript:searchRef('win32action')" class="r"&gt;win32action&lt;/a&gt; = &lt;a title="Search for references of 'SETXOFF'" href="javascript:searchRef('SETXOFF')" class="r"&gt;SETXOFF&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'TCOON'" href="javascript:searchRef('TCOON')" class="r"&gt;TCOON&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'win32action'" href="javascript:searchRef('win32action')" class="r"&gt;win32action&lt;/a&gt; = &lt;a title="Search for references of 'SETXON'" href="javascript:searchRef('SETXON')" class="r"&gt;SETXON&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'TCION'" href="javascript:searchRef('TCION')" class="r"&gt;TCION&lt;/a&gt;:&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'TCIOFF'" href="javascript:searchRef('TCIOFF')" class="r"&gt;TCIOFF&lt;/a&gt;:&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'GetCommState'" href="javascript:searchRef('GetCommState')" class="r"&gt;GetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt; == &lt;a title="Search for references of 'TCION'" href="javascript:searchRef('TCION')" class="r"&gt;TCION&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'xchar'" href="javascript:searchRef('xchar')" class="r"&gt;xchar&lt;/a&gt; = (&lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; ? &lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; : 0x11);&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'xchar'" href="javascript:searchRef('xchar')" class="r"&gt;xchar&lt;/a&gt; = (&lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; ? &lt;a title="Search for references of 'dcb'" href="javascript:searchRef('dcb')" class="r"&gt;dcb&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; : 0x13);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'TransmitCommChar'" href="javascript:searchRef('TransmitCommChar')" class="r"&gt;TransmitCommChar&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'xchar'" href="javascript:searchRef('xchar')" class="r"&gt;xchar&lt;/a&gt;) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'EscapeCommFunction'" href="javascript:searchRef('EscapeCommFunction')" class="r"&gt;EscapeCommFunction&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'win32action'" href="javascript:searchRef('win32action')" class="r"&gt;win32action&lt;/a&gt;) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcflush: POSIX 7.2.2.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcflush'" href="javascript:searchRef('tcflush')" class="r"&gt;tcflush&lt;/a&gt; (&lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'queue'" href="javascript:searchRef('queue')" class="r"&gt;queue&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'queue'" href="javascript:searchRef('queue')" class="r"&gt;queue&lt;/a&gt; == &lt;a title="Search for references of 'TCOFLUSH'" href="javascript:searchRef('TCOFLUSH')" class="r"&gt;TCOFLUSH&lt;/a&gt; || &lt;a title="Search for references of 'queue'" href="javascript:searchRef('queue')" class="r"&gt;queue&lt;/a&gt; == &lt;a title="Search for references of 'TCIOFLUSH'" href="javascript:searchRef('TCIOFLUSH')" class="r"&gt;TCIOFLUSH&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'PurgeComm'" href="javascript:searchRef('PurgeComm')" class="r"&gt;PurgeComm&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'PURGE_TXABORT'" href="javascript:searchRef('PURGE_TXABORT')" class="r"&gt;PURGE_TXABORT&lt;/a&gt; | &lt;a title="Search for references of 'PURGE_TXCLEAR'" href="javascript:searchRef('PURGE_TXCLEAR')" class="r"&gt;PURGE_TXCLEAR&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'queue'" href="javascript:searchRef('queue')" class="r"&gt;queue&lt;/a&gt; == &lt;a title="Search for references of 'TCIFLUSH'" href="javascript:searchRef('TCIFLUSH')" class="r"&gt;TCIFLUSH&lt;/a&gt; | &lt;a title="Search for references of 'queue'" href="javascript:searchRef('queue')" class="r"&gt;queue&lt;/a&gt; == &lt;a title="Search for references of 'TCIOFLUSH'" href="javascript:searchRef('TCIOFLUSH')" class="r"&gt;TCIOFLUSH&lt;/a&gt;)&lt;br /&gt;   &lt;span class="c"&gt;/* Input flushing by polling until nothing turns up&lt;br /&gt;      (we stop after 1000 chars anyway) */&lt;/span&gt;&lt;br /&gt;   &lt;span class="k"&gt;for&lt;/span&gt; (&lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'max'" href="javascript:searchRef('max')" class="r"&gt;max&lt;/a&gt; = 1000; &lt;a title="Search for references of 'max'" href="javascript:searchRef('max')" class="r"&gt;max&lt;/a&gt; &gt; 0; &lt;a title="Search for references of 'max'" href="javascript:searchRef('max')" class="r"&gt;max&lt;/a&gt;--)&lt;br /&gt;     {&lt;br /&gt; &lt;a title="Search for references of 'DWORD'" href="javascript:searchRef('DWORD')" class="r"&gt;DWORD&lt;/a&gt; &lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'COMSTAT'" href="javascript:searchRef('COMSTAT')" class="r"&gt;COMSTAT&lt;/a&gt; &lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'PurgeComm'" href="javascript:searchRef('PurgeComm')" class="r"&gt;PurgeComm&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'PURGE_RXABORT'" href="javascript:searchRef('PURGE_RXABORT')" class="r"&gt;PURGE_RXABORT&lt;/a&gt; | &lt;a title="Search for references of 'PURGE_RXCLEAR'" href="javascript:searchRef('PURGE_RXCLEAR')" class="r"&gt;PURGE_RXCLEAR&lt;/a&gt;))&lt;br /&gt;   &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt; &lt;a title="Search for references of 'Sleep'" href="javascript:searchRef('Sleep')" class="r"&gt;Sleep&lt;/a&gt; (100);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'ClearCommError'" href="javascript:searchRef('ClearCommError')" class="r"&gt;ClearCommError&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'ev'" href="javascript:searchRef('ev')" class="r"&gt;ev&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;) || !&lt;a title="Search for references of 'st'" href="javascript:searchRef('st')" class="r"&gt;st&lt;/a&gt;.&lt;a title="Search for references of 'cbInQue'" href="javascript:searchRef('cbInQue')" class="r"&gt;cbInQue&lt;/a&gt;)&lt;br /&gt;   &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcsetattr: POSIX 7.2.1.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcsetattr'" href="javascript:searchRef('tcsetattr')" class="r"&gt;tcsetattr&lt;/a&gt; (&lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt;, &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;a title="Search for references of 'termios'" href="javascript:searchRef('termios')" class="r"&gt;termios&lt;/a&gt; *&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="c"&gt;/* Possible actions:&lt;br /&gt;   TCSANOW:   immediately change attributes.&lt;br /&gt;   TCSADRAIN: flush output, then change attributes.&lt;br /&gt;   TCSAFLUSH: flush output and discard input, then change attributes.&lt;br /&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'BOOL'" href="javascript:searchRef('BOOL')" class="r"&gt;BOOL&lt;/a&gt; &lt;a title="Search for references of 'dropDTR'" href="javascript:searchRef('dropDTR')" class="r"&gt;dropDTR&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'COMMTIMEOUTS'" href="javascript:searchRef('COMMTIMEOUTS')" class="r"&gt;COMMTIMEOUTS&lt;/a&gt; &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'DCB'" href="javascript:searchRef('DCB')" class="r"&gt;DCB&lt;/a&gt; &lt;a title="Search for references of 'ostate'" href="javascript:searchRef('ostate')" class="r"&gt;ostate&lt;/a&gt;, &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;unsigned&lt;/span&gt; &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'ovtime'" href="javascript:searchRef('ovtime')" class="r"&gt;ovtime&lt;/a&gt; = &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;, &lt;a title="Search for references of 'ovmin'" href="javascript:searchRef('ovmin')" class="r"&gt;ovmin&lt;/a&gt; = &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"action %d"&lt;/span&gt;, &lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt; == &lt;a title="Search for references of 'TCSADRAIN'" href="javascript:searchRef('TCSADRAIN')" class="r"&gt;TCSADRAIN&lt;/a&gt;) || (&lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt; == &lt;a title="Search for references of 'TCSAFLUSH'" href="javascript:searchRef('TCSAFLUSH')" class="r"&gt;TCSAFLUSH&lt;/a&gt;))&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'FlushFileBuffers'" href="javascript:searchRef('FlushFileBuffers')" class="r"&gt;FlushFileBuffers&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; ());&lt;br /&gt;     &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"flushed file buffers"&lt;/span&gt;);&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'action'" href="javascript:searchRef('action')" class="r"&gt;action&lt;/a&gt; == &lt;a title="Search for references of 'TCSAFLUSH'" href="javascript:searchRef('TCSAFLUSH')" class="r"&gt;TCSAFLUSH&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'PurgeComm'" href="javascript:searchRef('PurgeComm')" class="r"&gt;PurgeComm&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), (&lt;a title="Search for references of 'PURGE_RXABORT'" href="javascript:searchRef('PURGE_RXABORT')" class="r"&gt;PURGE_RXABORT&lt;/a&gt; | &lt;a title="Search for references of 'PURGE_RXCLEAR'" href="javascript:searchRef('PURGE_RXCLEAR')" class="r"&gt;PURGE_RXCLEAR&lt;/a&gt;));&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* get default/last comm state */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'GetCommState'" href="javascript:searchRef('GetCommState')" class="r"&gt;GetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'ostate'" href="javascript:searchRef('ostate')" class="r"&gt;ostate&lt;/a&gt;))&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt; = &lt;a title="Search for references of 'ostate'" href="javascript:searchRef('ostate')" class="r"&gt;ostate&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set baud rate ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* FIXME: WIN32 also has 14400, 56000, 128000, and 256000.&lt;br /&gt;    Unix also has 230400. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B0'" href="javascript:searchRef('B0')" class="r"&gt;B0&lt;/a&gt;: &lt;span class="c"&gt;/* drop DTR */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'dropDTR'" href="javascript:searchRef('dropDTR')" class="r"&gt;dropDTR&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = 0;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B110'" href="javascript:searchRef('B110')" class="r"&gt;B110&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_110'" href="javascript:searchRef('CBR_110')" class="r"&gt;CBR_110&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B300'" href="javascript:searchRef('B300')" class="r"&gt;B300&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_300'" href="javascript:searchRef('CBR_300')" class="r"&gt;CBR_300&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B600'" href="javascript:searchRef('B600')" class="r"&gt;B600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_600'" href="javascript:searchRef('CBR_600')" class="r"&gt;CBR_600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B1200'" href="javascript:searchRef('B1200')" class="r"&gt;B1200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_1200'" href="javascript:searchRef('CBR_1200')" class="r"&gt;CBR_1200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B2400'" href="javascript:searchRef('B2400')" class="r"&gt;B2400&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_2400'" href="javascript:searchRef('CBR_2400')" class="r"&gt;CBR_2400&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B4800'" href="javascript:searchRef('B4800')" class="r"&gt;B4800&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_4800'" href="javascript:searchRef('CBR_4800')" class="r"&gt;CBR_4800&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B9600'" href="javascript:searchRef('B9600')" class="r"&gt;B9600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_9600'" href="javascript:searchRef('CBR_9600')" class="r"&gt;CBR_9600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B19200'" href="javascript:searchRef('B19200')" class="r"&gt;B19200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_19200'" href="javascript:searchRef('CBR_19200')" class="r"&gt;CBR_19200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B38400'" href="javascript:searchRef('B38400')" class="r"&gt;B38400&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_38400'" href="javascript:searchRef('CBR_38400')" class="r"&gt;CBR_38400&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B57600'" href="javascript:searchRef('B57600')" class="r"&gt;B57600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_57600'" href="javascript:searchRef('CBR_57600')" class="r"&gt;CBR_57600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'B115200'" href="javascript:searchRef('B115200')" class="r"&gt;B115200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt; = &lt;a title="Search for references of 'CBR_115200'" href="javascript:searchRef('CBR_115200')" class="r"&gt;CBR_115200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt; &lt;span class="c"&gt;/* Unsupported baud rate! */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"Invalid t-&gt;c_ospeed %d"&lt;/span&gt;, &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'set_errno'" href="javascript:searchRef('set_errno')" class="r"&gt;set_errno&lt;/a&gt; (&lt;a title="Search for references of 'EINVAL'" href="javascript:searchRef('EINVAL')" class="r"&gt;EINVAL&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set byte size ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CSIZE'" href="javascript:searchRef('CSIZE')" class="r"&gt;CSIZE&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CS5'" href="javascript:searchRef('CS5')" class="r"&gt;CS5&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt; = 5;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CS6'" href="javascript:searchRef('CS6')" class="r"&gt;CS6&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt; = 6;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CS7'" href="javascript:searchRef('CS7')" class="r"&gt;CS7&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt; = 7;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CS8'" href="javascript:searchRef('CS8')" class="r"&gt;CS8&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt; = 8;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt; &lt;span class="c"&gt;/* Unsupported byte size! */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"Invalid t-&gt;c_cflag byte size %d"&lt;/span&gt;,&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CSIZE'" href="javascript:searchRef('CSIZE')" class="r"&gt;CSIZE&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'set_errno'" href="javascript:searchRef('set_errno')" class="r"&gt;set_errno&lt;/a&gt; (&lt;a title="Search for references of 'EINVAL'" href="javascript:searchRef('EINVAL')" class="r"&gt;EINVAL&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set stop bits ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CSTOPB'" href="javascript:searchRef('CSTOPB')" class="r"&gt;CSTOPB&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'StopBits'" href="javascript:searchRef('StopBits')" class="r"&gt;StopBits&lt;/a&gt; = &lt;a title="Search for references of 'TWOSTOPBITS'" href="javascript:searchRef('TWOSTOPBITS')" class="r"&gt;TWOSTOPBITS&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'StopBits'" href="javascript:searchRef('StopBits')" class="r"&gt;StopBits&lt;/a&gt; = &lt;a title="Search for references of 'ONESTOPBIT'" href="javascript:searchRef('ONESTOPBIT')" class="r"&gt;ONESTOPBIT&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set parity ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'PARENB'" href="javascript:searchRef('PARENB')" class="r"&gt;PARENB&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'Parity'" href="javascript:searchRef('Parity')" class="r"&gt;Parity&lt;/a&gt; = (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'PARODD'" href="javascript:searchRef('PARODD')" class="r"&gt;PARODD&lt;/a&gt;) ? &lt;a title="Search for references of 'ODDPARITY'" href="javascript:searchRef('ODDPARITY')" class="r"&gt;ODDPARITY&lt;/a&gt; : &lt;a title="Search for references of 'EVENPARITY'" href="javascript:searchRef('EVENPARITY')" class="r"&gt;EVENPARITY&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'Parity'" href="javascript:searchRef('Parity')" class="r"&gt;Parity&lt;/a&gt; = &lt;a title="Search for references of 'NOPARITY'" href="javascript:searchRef('NOPARITY')" class="r"&gt;NOPARITY&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fBinary'" href="javascript:searchRef('fBinary')" class="r"&gt;fBinary&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;     &lt;span class="c"&gt;/* Binary transfer */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'EofChar'" href="javascript:searchRef('EofChar')" class="r"&gt;EofChar&lt;/a&gt; = 0;     &lt;span class="c"&gt;/* No end-of-data in binary mode */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fNull'" href="javascript:searchRef('fNull')" class="r"&gt;fNull&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;      &lt;span class="c"&gt;/* Don't discard nulls in binary mode */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Parity errors ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* fParity combines the function of INPCK and NOT IGNPAR */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'INPCK'" href="javascript:searchRef('INPCK')" class="r"&gt;INPCK&lt;/a&gt;) &amp;amp;&amp;amp; !(&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'IGNPAR'" href="javascript:searchRef('IGNPAR')" class="r"&gt;IGNPAR&lt;/a&gt;))&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fParity'" href="javascript:searchRef('fParity')" class="r"&gt;fParity&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;   &lt;span class="c"&gt;/* detect parity errors */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fParity'" href="javascript:searchRef('fParity')" class="r"&gt;fParity&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;  &lt;span class="c"&gt;/* ignore parity errors */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Only present in Win32, Unix has no equivalent */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fErrorChar'" href="javascript:searchRef('fErrorChar')" class="r"&gt;fErrorChar&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ErrorChar'" href="javascript:searchRef('ErrorChar')" class="r"&gt;ErrorChar&lt;/a&gt; = 0;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set software flow control ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Set fTXContinueOnXoff to FALSE.  This prevents the triggering of a&lt;br /&gt;    premature XON when the remote device interprets a received character&lt;br /&gt;    as XON (same as IXANY on the remote side).  Otherwise, a TRUE&lt;br /&gt;    value separates the TX and RX functions. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fTXContinueOnXoff'" href="javascript:searchRef('fTXContinueOnXoff')" class="r"&gt;fTXContinueOnXoff&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;     &lt;span class="c"&gt;/* separate TX and RX flow control */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Transmission flow control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'IXON'" href="javascript:searchRef('IXON')" class="r"&gt;IXON&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutX'" href="javascript:searchRef('fOutX')" class="r"&gt;fOutX&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;   &lt;span class="c"&gt;/* enable */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutX'" href="javascript:searchRef('fOutX')" class="r"&gt;fOutX&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;  &lt;span class="c"&gt;/* disable */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Reception flow control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'IXOFF'" href="javascript:searchRef('IXOFF')" class="r"&gt;IXOFF&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fInX'" href="javascript:searchRef('fInX')" class="r"&gt;fInX&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;    &lt;span class="c"&gt;/* enable */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fInX'" href="javascript:searchRef('fInX')" class="r"&gt;fInX&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;   &lt;span class="c"&gt;/* disable */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* XoffLim and XonLim are left at default values */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; = (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTART'" href="javascript:searchRef('VSTART')" class="r"&gt;VSTART&lt;/a&gt;] ? &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTART'" href="javascript:searchRef('VSTART')" class="r"&gt;VSTART&lt;/a&gt;] : 0x11);&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; = (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTOP'" href="javascript:searchRef('VSTOP')" class="r"&gt;VSTOP&lt;/a&gt;] ? &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTOP'" href="javascript:searchRef('VSTOP')" class="r"&gt;VSTOP&lt;/a&gt;] : 0x13);&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set hardware flow control ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Disable DSR flow control */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxDsrFlow'" href="javascript:searchRef('fOutxDsrFlow')" class="r"&gt;fOutxDsrFlow&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Some old flavors of Unix automatically enabled hardware flow&lt;br /&gt;    control when software flow control was not enabled.  Since newer&lt;br /&gt;    Unices tend to require explicit setting of hardware flow-control,&lt;br /&gt;    this is what we do. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* RTS/CTS flow control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CRTSCTS'" href="javascript:searchRef('CRTSCTS')" class="r"&gt;CRTSCTS&lt;/a&gt;)&lt;br /&gt;   {       &lt;span class="c"&gt;/* enable */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxCtsFlow'" href="javascript:searchRef('fOutxCtsFlow')" class="r"&gt;fOutxCtsFlow&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; = &lt;a title="Search for references of 'RTS_CONTROL_HANDSHAKE'" href="javascript:searchRef('RTS_CONTROL_HANDSHAKE')" class="r"&gt;RTS_CONTROL_HANDSHAKE&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   {       &lt;span class="c"&gt;/* disable */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; = &lt;a title="Search for references of 'RTS_CONTROL_ENABLE'" href="javascript:searchRef('RTS_CONTROL_ENABLE')" class="r"&gt;RTS_CONTROL_ENABLE&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxCtsFlow'" href="javascript:searchRef('fOutxCtsFlow')" class="r"&gt;fOutxCtsFlow&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CRTSXOFF'" href="javascript:searchRef('CRTSXOFF')" class="r"&gt;CRTSXOFF&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; = &lt;a title="Search for references of 'RTS_CONTROL_HANDSHAKE'" href="javascript:searchRef('RTS_CONTROL_HANDSHAKE')" class="r"&gt;RTS_CONTROL_HANDSHAKE&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- DTR ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Assert DTR on device open */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDtrControl'" href="javascript:searchRef('fDtrControl')" class="r"&gt;fDtrControl&lt;/a&gt; = &lt;a title="Search for references of 'DTR_CONTROL_ENABLE'" href="javascript:searchRef('DTR_CONTROL_ENABLE')" class="r"&gt;DTR_CONTROL_ENABLE&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- DSR ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Assert DSR at the device? */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'CLOCAL'" href="javascript:searchRef('CLOCAL')" class="r"&gt;CLOCAL&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDsrSensitivity'" href="javascript:searchRef('fDsrSensitivity')" class="r"&gt;fDsrSensitivity&lt;/a&gt; = &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;;  &lt;span class="c"&gt;/* no */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDsrSensitivity'" href="javascript:searchRef('fDsrSensitivity')" class="r"&gt;fDsrSensitivity&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;   &lt;span class="c"&gt;/* yes */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Error handling ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Since read/write operations terminate upon error, we&lt;br /&gt;    will use ClearCommError() to resume. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fAbortOnError'" href="javascript:searchRef('fAbortOnError')" class="r"&gt;fAbortOnError&lt;/a&gt; = &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Set state and exit ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'memcmp'" href="javascript:searchRef('memcmp')" class="r"&gt;memcmp&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'ostate'" href="javascript:searchRef('ostate')" class="r"&gt;ostate&lt;/a&gt;, &amp;amp;&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;, &lt;span class="k"&gt;sizeof&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;)) != 0)&lt;br /&gt;   &lt;a title="Search for references of 'SetCommState'" href="javascript:searchRef('SetCommState')" class="r"&gt;SetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'set_r_binary'" href="javascript:searchRef('set_r_binary')" class="r"&gt;set_r_binary&lt;/a&gt; ((&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'IGNCR'" href="javascript:searchRef('IGNCR')" class="r"&gt;IGNCR&lt;/a&gt;) ? 0 : 1);&lt;br /&gt; &lt;a title="Search for references of 'set_w_binary'" href="javascript:searchRef('set_w_binary')" class="r"&gt;set_w_binary&lt;/a&gt; ((&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_oflag'" href="javascript:searchRef('c_oflag')" class="r"&gt;c_oflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'ONLCR'" href="javascript:searchRef('ONLCR')" class="r"&gt;ONLCR&lt;/a&gt;) ? 0 : 1);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'dropDTR'" href="javascript:searchRef('dropDTR')" class="r"&gt;dropDTR&lt;/a&gt; == &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 'EscapeCommFunction'" href="javascript:searchRef('EscapeCommFunction')" class="r"&gt;EscapeCommFunction&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'CLRDTR'" href="javascript:searchRef('CLRDTR')" class="r"&gt;CLRDTR&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="c"&gt;/* FIXME: Sometimes when CLRDTR is set, setting&lt;br /&gt;     state.fDtrControl = DTR_CONTROL_ENABLE will fail.  This&lt;br /&gt;     is a problem since a program might want to change some&lt;br /&gt;     parameters while DTR is still down. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     &lt;a title="Search for references of 'EscapeCommFunction'" href="javascript:searchRef('EscapeCommFunction')" class="r"&gt;EscapeCommFunction&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &lt;a title="Search for references of 'SETDTR'" href="javascript:searchRef('SETDTR')" class="r"&gt;SETDTR&lt;/a&gt;);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/*&lt;br /&gt; The following documentation on was taken from "Linux Serial Programming&lt;br /&gt; HOWTO".  It explains how MIN (t-&gt;c_cc[VMIN] || vmin_) and TIME&lt;br /&gt; (t-&gt;c_cc[VTIME] || vtime_) is to be used.&lt;br /&gt;&lt;br /&gt; In non-canonical input processing mode, input is not assembled into&lt;br /&gt; lines and input processing (erase, kill, delete, etc.) does not&lt;br /&gt; occur. Two parameters control the behavior of this mode: c_cc[VTIME]&lt;br /&gt; sets the character timer, and c_cc[VMIN] sets the minimum number of&lt;br /&gt; characters to receive before satisfying the read.&lt;br /&gt;&lt;br /&gt; If MIN &gt; 0 and TIME = 0, MIN sets the number of characters to receive&lt;br /&gt; before the read is satisfied. As TIME is zero, the timer is not used.&lt;br /&gt;&lt;br /&gt; If MIN = 0 and TIME &gt; 0, TIME serves as a timeout value. The read will&lt;br /&gt; be satisfied if a single character is read, or TIME is exceeded (t =&lt;br /&gt; TIME *0.1 s). If TIME is exceeded, no character will be returned.&lt;br /&gt;&lt;br /&gt; If MIN &gt; 0 and TIME &gt; 0, TIME serves as an inter-character timer. The&lt;br /&gt; read will be satisfied if MIN characters are received, or the time&lt;br /&gt; between two characters exceeds TIME. The timer is restarted every time&lt;br /&gt; a character is received and only becomes active after the first&lt;br /&gt; character has been received.&lt;br /&gt;&lt;br /&gt; If MIN = 0 and TIME = 0, read will be satisfied immediately. The&lt;br /&gt; number of characters currently available, or the number of characters&lt;br /&gt; requested will be returned. According to Antonino (see contributions),&lt;br /&gt; you could issue a fcntl(fd, F_SETFL, FNDELAY); before reading to get&lt;br /&gt; the same result.&lt;br /&gt; */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_lflag'" href="javascript:searchRef('c_lflag')" class="r"&gt;c_lflag&lt;/a&gt; &amp;amp; &lt;a title="Search for references of 'ICANON'" href="javascript:searchRef('ICANON')" class="r"&gt;ICANON&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; = &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; = 0;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VTIME'" href="javascript:searchRef('VTIME')" class="r"&gt;VTIME&lt;/a&gt;] * 100;&lt;br /&gt;     &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VMIN'" href="javascript:searchRef('VMIN')" class="r"&gt;VMIN&lt;/a&gt;];&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"vtime %d, vmin %d\n"&lt;/span&gt;, &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;, &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'ovmin'" href="javascript:searchRef('ovmin')" class="r"&gt;ovmin&lt;/a&gt; == &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; &amp;amp;&amp;amp; &lt;a title="Search for references of 'ovtime'" href="javascript:searchRef('ovtime')" class="r"&gt;ovtime&lt;/a&gt; == &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'memset'" href="javascript:searchRef('memset')" class="r"&gt;memset&lt;/a&gt; (&amp;amp;&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;, 0, &lt;span class="k"&gt;sizeof&lt;/span&gt; (&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;));&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; &gt; 0) &amp;amp;&amp;amp; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; == 0))&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="c"&gt;/* Returns immediately with whatever is in buffer on a ReadFile();&lt;br /&gt;  or blocks if nothing found.  We will keep calling ReadFile(); until&lt;br /&gt;  vmin_ characters are read */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadIntervalTimeout'" href="javascript:searchRef('ReadIntervalTimeout')" class="r"&gt;ReadIntervalTimeout&lt;/a&gt; = &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutMultiplier'" href="javascript:searchRef('ReadTotalTimeoutMultiplier')" class="r"&gt;ReadTotalTimeoutMultiplier&lt;/a&gt; = &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutConstant'" href="javascript:searchRef('ReadTotalTimeoutConstant')" class="r"&gt;ReadTotalTimeoutConstant&lt;/a&gt; = &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt; - 1;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; == 0) &amp;amp;&amp;amp; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; &gt; 0))&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="c"&gt;/* set timeoout constant appropriately and we will only try to&lt;br /&gt;  read one character in ReadFile() */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutConstant'" href="javascript:searchRef('ReadTotalTimeoutConstant')" class="r"&gt;ReadTotalTimeoutConstant&lt;/a&gt; = &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadIntervalTimeout'" href="javascript:searchRef('ReadIntervalTimeout')" class="r"&gt;ReadIntervalTimeout&lt;/a&gt; = &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutMultiplier'" href="javascript:searchRef('ReadTotalTimeoutMultiplier')" class="r"&gt;ReadTotalTimeoutMultiplier&lt;/a&gt; = &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; &gt; 0) &amp;amp;&amp;amp; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; &gt; 0))&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="c"&gt;/* time applies to the interval time for this case */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadIntervalTimeout'" href="javascript:searchRef('ReadIntervalTimeout')" class="r"&gt;ReadIntervalTimeout&lt;/a&gt; = &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; == 0) &amp;amp;&amp;amp; (&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; == 0))&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="c"&gt;/* returns immediately with whatever is in buffer as per&lt;br /&gt;  Time-Outs docs in Win32 SDK API docs */&lt;/span&gt;&lt;br /&gt;     &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadIntervalTimeout'" href="javascript:searchRef('ReadIntervalTimeout')" class="r"&gt;ReadIntervalTimeout&lt;/a&gt; = &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"ReadTotalTimeoutConstant %d, ReadIntervalTimeout %d, ReadTotalTimeoutMultiplier %d"&lt;/span&gt;,&lt;br /&gt;  &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutConstant'" href="javascript:searchRef('ReadTotalTimeoutConstant')" class="r"&gt;ReadTotalTimeoutConstant&lt;/a&gt;, &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadIntervalTimeout'" href="javascript:searchRef('ReadIntervalTimeout')" class="r"&gt;ReadIntervalTimeout&lt;/a&gt;, &lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;.&lt;a title="Search for references of 'ReadTotalTimeoutMultiplier'" href="javascript:searchRef('ReadTotalTimeoutMultiplier')" class="r"&gt;ReadTotalTimeoutMultiplier&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;int&lt;/span&gt; &lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt; = &lt;a title="Search for references of 'SetCommTimeouts'" href="javascript:searchRef('SetCommTimeouts')" class="r"&gt;SetCommTimeouts&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'to'" href="javascript:searchRef('to')" class="r"&gt;to&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'res'" href="javascript:searchRef('res')" class="r"&gt;res&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 'system_printf'" href="javascript:searchRef('system_printf')" class="r"&gt;system_printf&lt;/a&gt; (&lt;span class="str"&gt;"SetCommTimeout failed, %E"&lt;/span&gt;);&lt;br /&gt;     &lt;a title="Search for references of '__seterrno'" href="javascript:searchRef('__seterrno')" class="r"&gt;__seterrno&lt;/a&gt; ();&lt;br /&gt;     &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="c"&gt;/* tcgetattr: POSIX 7.2.1.1 */&lt;/span&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'tcgetattr'" href="javascript:searchRef('tcgetattr')" class="r"&gt;tcgetattr&lt;/a&gt; (&lt;span class="k"&gt;struct&lt;/span&gt; &lt;a title="Search for references of 'termios'" href="javascript:searchRef('termios')" class="r"&gt;termios&lt;/a&gt; *&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'DCB'" href="javascript:searchRef('DCB')" class="r"&gt;DCB&lt;/a&gt; &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Get current Win32 comm state */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'GetCommState'" href="javascript:searchRef('GetCommState')" class="r"&gt;GetCommState&lt;/a&gt; (&lt;a title="Search for references of 'get_handle'" href="javascript:searchRef('get_handle')" class="r"&gt;get_handle&lt;/a&gt; (), &amp;amp;&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;) == 0)&lt;br /&gt;   &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* for safety */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'memset'" href="javascript:searchRef('memset')" class="r"&gt;memset&lt;/a&gt; (&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;, 0, &lt;span class="k"&gt;sizeof&lt;/span&gt; (*&lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;));&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Baud rate ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; 0:&lt;br /&gt; &lt;span class="c"&gt;/* FIXME: need to drop DTR */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B0'" href="javascript:searchRef('B0')" class="r"&gt;B0&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_110'" href="javascript:searchRef('CBR_110')" class="r"&gt;CBR_110&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B110'" href="javascript:searchRef('B110')" class="r"&gt;B110&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_300'" href="javascript:searchRef('CBR_300')" class="r"&gt;CBR_300&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B300'" href="javascript:searchRef('B300')" class="r"&gt;B300&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_600'" href="javascript:searchRef('CBR_600')" class="r"&gt;CBR_600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B600'" href="javascript:searchRef('B600')" class="r"&gt;B600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_1200'" href="javascript:searchRef('CBR_1200')" class="r"&gt;CBR_1200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B1200'" href="javascript:searchRef('B1200')" class="r"&gt;B1200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_2400'" href="javascript:searchRef('CBR_2400')" class="r"&gt;CBR_2400&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B2400'" href="javascript:searchRef('B2400')" class="r"&gt;B2400&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_4800'" href="javascript:searchRef('CBR_4800')" class="r"&gt;CBR_4800&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B4800'" href="javascript:searchRef('B4800')" class="r"&gt;B4800&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_9600'" href="javascript:searchRef('CBR_9600')" class="r"&gt;CBR_9600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B9600'" href="javascript:searchRef('B9600')" class="r"&gt;B9600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_19200'" href="javascript:searchRef('CBR_19200')" class="r"&gt;CBR_19200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B19200'" href="javascript:searchRef('B19200')" class="r"&gt;B19200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_38400'" href="javascript:searchRef('CBR_38400')" class="r"&gt;CBR_38400&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B38400'" href="javascript:searchRef('B38400')" class="r"&gt;B38400&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_57600'" href="javascript:searchRef('CBR_57600')" class="r"&gt;CBR_57600&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B57600'" href="javascript:searchRef('B57600')" class="r"&gt;B57600&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; &lt;a title="Search for references of 'CBR_115200'" href="javascript:searchRef('CBR_115200')" class="r"&gt;CBR_115200&lt;/a&gt;:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ospeed'" href="javascript:searchRef('c_ospeed')" class="r"&gt;c_ospeed&lt;/a&gt; = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_ispeed'" href="javascript:searchRef('c_ispeed')" class="r"&gt;c_ispeed&lt;/a&gt; = &lt;a title="Search for references of 'B115200'" href="javascript:searchRef('B115200')" class="r"&gt;B115200&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt; &lt;span class="c"&gt;/* Unsupported baud rate! */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"Invalid baud rate %d"&lt;/span&gt;, &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'BaudRate'" href="javascript:searchRef('BaudRate')" class="r"&gt;BaudRate&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'set_errno'" href="javascript:searchRef('set_errno')" class="r"&gt;set_errno&lt;/a&gt; (&lt;a title="Search for references of 'EINVAL'" href="javascript:searchRef('EINVAL')" class="r"&gt;EINVAL&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Byte size ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;switch&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; 5:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CS5'" href="javascript:searchRef('CS5')" class="r"&gt;CS5&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; 6:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CS6'" href="javascript:searchRef('CS6')" class="r"&gt;CS6&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; 7:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CS7'" href="javascript:searchRef('CS7')" class="r"&gt;CS7&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;case&lt;/span&gt; 8:&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CS8'" href="javascript:searchRef('CS8')" class="r"&gt;CS8&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;break&lt;/span&gt;;&lt;br /&gt;     &lt;span class="k"&gt;default&lt;/span&gt;:&lt;br /&gt; &lt;span class="c"&gt;/* Unsupported byte size! */&lt;/span&gt;&lt;br /&gt; &lt;a title="Search for references of 'termios_printf'" href="javascript:searchRef('termios_printf')" class="r"&gt;termios_printf&lt;/a&gt; (&lt;span class="str"&gt;"Invalid byte size %d"&lt;/span&gt;, &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'ByteSize'" href="javascript:searchRef('ByteSize')" class="r"&gt;ByteSize&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'set_errno'" href="javascript:searchRef('set_errno')" class="r"&gt;set_errno&lt;/a&gt; (&lt;a title="Search for references of 'EINVAL'" href="javascript:searchRef('EINVAL')" class="r"&gt;EINVAL&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; -1;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Stop bits ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'StopBits'" href="javascript:searchRef('StopBits')" class="r"&gt;StopBits&lt;/a&gt; == &lt;a title="Search for references of 'TWOSTOPBITS'" href="javascript:searchRef('TWOSTOPBITS')" class="r"&gt;TWOSTOPBITS&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CSTOPB'" href="javascript:searchRef('CSTOPB')" class="r"&gt;CSTOPB&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Parity ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'Parity'" href="javascript:searchRef('Parity')" class="r"&gt;Parity&lt;/a&gt; == &lt;a title="Search for references of 'ODDPARITY'" href="javascript:searchRef('ODDPARITY')" class="r"&gt;ODDPARITY&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= (&lt;a title="Search for references of 'PARENB'" href="javascript:searchRef('PARENB')" class="r"&gt;PARENB&lt;/a&gt; | &lt;a title="Search for references of 'PARODD'" href="javascript:searchRef('PARODD')" class="r"&gt;PARODD&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'Parity'" href="javascript:searchRef('Parity')" class="r"&gt;Parity&lt;/a&gt; == &lt;a title="Search for references of 'EVENPARITY'" href="javascript:searchRef('EVENPARITY')" class="r"&gt;EVENPARITY&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'PARENB'" href="javascript:searchRef('PARENB')" class="r"&gt;PARENB&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Parity errors ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* fParity combines the function of INPCK and NOT IGNPAR */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fParity'" href="javascript:searchRef('fParity')" class="r"&gt;fParity&lt;/a&gt; == &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; |= &lt;a title="Search for references of 'INPCK'" href="javascript:searchRef('INPCK')" class="r"&gt;INPCK&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; |= &lt;a title="Search for references of 'IGNPAR'" href="javascript:searchRef('IGNPAR')" class="r"&gt;IGNPAR&lt;/a&gt;; &lt;span class="c"&gt;/* not necessarily! */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Software flow control ------------------ */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* transmission flow control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutX'" href="javascript:searchRef('fOutX')" class="r"&gt;fOutX&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; |= &lt;a title="Search for references of 'IXON'" href="javascript:searchRef('IXON')" class="r"&gt;IXON&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* reception flow control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fInX'" href="javascript:searchRef('fInX')" class="r"&gt;fInX&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; |= &lt;a title="Search for references of 'IXOFF'" href="javascript:searchRef('IXOFF')" class="r"&gt;IXOFF&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTART'" href="javascript:searchRef('VSTART')" class="r"&gt;VSTART&lt;/a&gt;] = (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; ? &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XonChar'" href="javascript:searchRef('XonChar')" class="r"&gt;XonChar&lt;/a&gt; : 0x11);&lt;br /&gt; &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VSTOP'" href="javascript:searchRef('VSTOP')" class="r"&gt;VSTOP&lt;/a&gt;] = (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; ? &lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'XoffChar'" href="javascript:searchRef('XoffChar')" class="r"&gt;XoffChar&lt;/a&gt; : 0x13);&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- Hardware flow control ------------------ */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Some old flavors of Unix automatically enabled hardware flow&lt;br /&gt;    control when software flow control was not enabled.  Since newer&lt;br /&gt;    Unices tend to require explicit setting of hardware flow-control,&lt;br /&gt;    this is what we do. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* Input flow-control */&lt;/span&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; ((&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; == &lt;a title="Search for references of 'RTS_CONTROL_HANDSHAKE'" href="javascript:searchRef('RTS_CONTROL_HANDSHAKE')" class="r"&gt;RTS_CONTROL_HANDSHAKE&lt;/a&gt;) &amp;amp;&amp;amp;&lt;br /&gt;     (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fOutxCtsFlow'" href="javascript:searchRef('fOutxCtsFlow')" class="r"&gt;fOutxCtsFlow&lt;/a&gt; == &lt;a title="Search for references of 'TRUE'" href="javascript:searchRef('TRUE')" class="r"&gt;TRUE&lt;/a&gt;))&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CRTSCTS'" href="javascript:searchRef('CRTSCTS')" class="r"&gt;CRTSCTS&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fRtsControl'" href="javascript:searchRef('fRtsControl')" class="r"&gt;fRtsControl&lt;/a&gt; == &lt;a title="Search for references of 'RTS_CONTROL_HANDSHAKE'" href="javascript:searchRef('RTS_CONTROL_HANDSHAKE')" class="r"&gt;RTS_CONTROL_HANDSHAKE&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CRTSXOFF'" href="javascript:searchRef('CRTSXOFF')" class="r"&gt;CRTSXOFF&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* -------------- CLOCAL --------------- */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* DSR is only lead toggled only by CLOCAL.  Check it to see if&lt;br /&gt;    CLOCAL was called. */&lt;/span&gt;&lt;br /&gt; &lt;span class="c"&gt;/* FIXME: If tcsetattr() hasn't been called previously, this may&lt;br /&gt;    give a false CLOCAL. */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'state'" href="javascript:searchRef('state')" class="r"&gt;state&lt;/a&gt;.&lt;a title="Search for references of 'fDsrSensitivity'" href="javascript:searchRef('fDsrSensitivity')" class="r"&gt;fDsrSensitivity&lt;/a&gt; == &lt;a title="Search for references of 'FALSE'" href="javascript:searchRef('FALSE')" class="r"&gt;FALSE&lt;/a&gt;)&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cflag'" href="javascript:searchRef('c_cflag')" class="r"&gt;c_cflag&lt;/a&gt; |= &lt;a title="Search for references of 'CLOCAL'" href="javascript:searchRef('CLOCAL')" class="r"&gt;CLOCAL&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span class="c"&gt;/* FIXME: need to handle IGNCR */&lt;/span&gt;&lt;br /&gt;#&lt;span class="k"&gt;if&lt;/span&gt; 0&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'get_r_binary'" href="javascript:searchRef('get_r_binary')" class="r"&gt;get_r_binary&lt;/a&gt; ())&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_iflag'" href="javascript:searchRef('c_iflag')" class="r"&gt;c_iflag&lt;/a&gt; |= &lt;a title="Search for references of 'IGNCR'" href="javascript:searchRef('IGNCR')" class="r"&gt;IGNCR&lt;/a&gt;;&lt;br /&gt;#&lt;a title="Search for references of 'endif'" href="javascript:searchRef('endif')" class="r"&gt;endif&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (!&lt;a title="Search for references of 'get_w_binary'" href="javascript:searchRef('get_w_binary')" class="r"&gt;get_w_binary&lt;/a&gt; ())&lt;br /&gt;   &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_oflag'" href="javascript:searchRef('c_oflag')" class="r"&gt;c_oflag&lt;/a&gt; |= &lt;a title="Search for references of 'ONLCR'" href="javascript:searchRef('ONLCR')" class="r"&gt;ONLCR&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"vmin_ %d, vtime_ %d"&lt;/span&gt;, &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;, &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; == &lt;a title="Search for references of 'MAXDWORD'" href="javascript:searchRef('MAXDWORD')" class="r"&gt;MAXDWORD&lt;/a&gt;)&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_lflag'" href="javascript:searchRef('c_lflag')" class="r"&gt;c_lflag&lt;/a&gt; |= &lt;a title="Search for references of 'ICANON'" href="javascript:searchRef('ICANON')" class="r"&gt;ICANON&lt;/a&gt;;&lt;br /&gt;     &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VTIME'" href="javascript:searchRef('VTIME')" class="r"&gt;VTIME&lt;/a&gt;] = &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VMIN'" href="javascript:searchRef('VMIN')" class="r"&gt;VMIN&lt;/a&gt;] = 0;&lt;br /&gt;   }&lt;br /&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;br /&gt;   {&lt;br /&gt;     &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VTIME'" href="javascript:searchRef('VTIME')" class="r"&gt;VTIME&lt;/a&gt;] = &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; / 100;&lt;br /&gt;     &lt;a title="Search for references of 't'" href="javascript:searchRef('t')" class="r"&gt;t&lt;/a&gt;-&gt;&lt;a title="Search for references of 'c_cc'" href="javascript:searchRef('c_cc')" class="r"&gt;c_cc&lt;/a&gt;[&lt;a title="Search for references of 'VMIN'" href="javascript:searchRef('VMIN')" class="r"&gt;VMIN&lt;/a&gt;] = &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'fixup_after_fork'" href="javascript:searchRef('fixup_after_fork')" class="r"&gt;fixup_after_fork&lt;/a&gt; (&lt;a title="Search for references of 'HANDLE'" href="javascript:searchRef('HANDLE')" class="r"&gt;HANDLE&lt;/a&gt; &lt;a title="Search for references of 'parent'" href="javascript:searchRef('parent')" class="r"&gt;parent&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;span class="k"&gt;if&lt;/span&gt; (&lt;a title="Search for references of 'get_close_on_exec'" href="javascript:searchRef('get_close_on_exec')" class="r"&gt;get_close_on_exec&lt;/a&gt; ())&lt;br /&gt;   &lt;span class="k"&gt;this&lt;/span&gt;-&gt;&lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt;::&lt;a title="Search for references of 'fixup_after_fork'" href="javascript:searchRef('fixup_after_fork')" class="r"&gt;fixup_after_fork&lt;/a&gt; (&lt;a title="Search for references of 'parent'" href="javascript:searchRef('parent')" class="r"&gt;parent&lt;/a&gt;);&lt;br /&gt; &lt;a title="Search for references of 'overlapped_setup'" href="javascript:searchRef('overlapped_setup')" class="r"&gt;overlapped_setup&lt;/a&gt; ();&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"io_status.hEvent %p"&lt;/span&gt;, &lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'fixup_after_exec'" href="javascript:searchRef('fixup_after_exec')" class="r"&gt;fixup_after_exec&lt;/a&gt; (&lt;a title="Search for references of 'HANDLE'" href="javascript:searchRef('HANDLE')" class="r"&gt;HANDLE&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'overlapped_setup'" href="javascript:searchRef('overlapped_setup')" class="r"&gt;overlapped_setup&lt;/a&gt; ();&lt;br /&gt; &lt;a title="Search for references of 'debug_printf'" href="javascript:searchRef('debug_printf')" class="r"&gt;debug_printf&lt;/a&gt; (&lt;span class="str"&gt;"io_status.hEvent %p"&lt;/span&gt;, &lt;a title="Search for references of 'io_status'" href="javascript:searchRef('io_status')" class="r"&gt;io_status&lt;/a&gt;.&lt;a title="Search for references of 'hEvent'" href="javascript:searchRef('hEvent')" class="r"&gt;hEvent&lt;/a&gt;);&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="k"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt;::&lt;a title="Search for references of 'dup'" href="javascript:searchRef('dup')" class="r"&gt;dup&lt;/a&gt; (&lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt; *&lt;a title="Search for references of 'child'" href="javascript:searchRef('child')" class="r"&gt;child&lt;/a&gt;)&lt;br /&gt;{&lt;br /&gt; &lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt; *&lt;a title="Search for references of 'fhc'" href="javascript:searchRef('fhc')" class="r"&gt;fhc&lt;/a&gt; = (&lt;a title="Search for references of 'fhandler_serial'" href="javascript:searchRef('fhandler_serial')" class="r"&gt;fhandler_serial&lt;/a&gt; *) &lt;a title="Search for references of 'child'" href="javascript:searchRef('child')" class="r"&gt;child&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'overlapped_setup'" href="javascript:searchRef('overlapped_setup')" class="r"&gt;overlapped_setup&lt;/a&gt; ();&lt;br /&gt; &lt;a title="Search for references of 'fhc'" href="javascript:searchRef('fhc')" class="r"&gt;fhc&lt;/a&gt;-&gt;&lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt; = &lt;a title="Search for references of 'vmin_'" href="javascript:searchRef('vmin_')" class="r"&gt;vmin_&lt;/a&gt;;&lt;br /&gt; &lt;a title="Search for references of 'fhc'" href="javascript:searchRef('fhc')" class="r"&gt;fhc&lt;/a&gt;-&gt;&lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt; = &lt;a title="Search for references of 'vtime_'" href="javascript:searchRef('vtime_')" class="r"&gt;vtime_&lt;/a&gt;;&lt;br /&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;a title="Search for references of 'fhandler_base'" href="javascript:searchRef('fhandler_base')" class="r"&gt;fhandler_base&lt;/a&gt;::&lt;a title="Search for references of 'dup'" href="javascript:searchRef('dup')" class="r"&gt;dup&lt;/a&gt; (&lt;a title="Search for references of 'child'" href="javascript:searchRef('child')" class="r"&gt;child&lt;/a&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;       &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-3341548991505897545?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/3341548991505897545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=3341548991505897545' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/3341548991505897545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/3341548991505897545'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/convert-linux-code-to-windows-serial.html' title='convert linux code to windows serial port programming code'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-7686100109247539694</id><published>2008-07-18T04:56:00.000-07:00</published><updated>2008-07-18T04:57:19.139-07:00</updated><title type='text'>Serial Communication Device Control Block</title><content type='html'>&lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The most crucial aspect of programming serial communications applications is the settings in the Device-Control Block (DCB) structure. The most common errors in serial communications programming occur in initializing the DCB structure improperly. When the serial communications functions do not behave as expected, a close examination of the DCB structure usually reveals the problem.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Here is an explanation of each of the members of the DCB and how they affect other parts of the serial communications functions.&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The DCB Structure Members&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;table class="MsoNormalTable" style="width: 6in;" border="1" cellpadding="0" width="576"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Member&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Description&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DCBlength&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Size, in   bytes, of the structure. Should not change.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;BaudRate&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the baud at which the communications device operates. This member can be an   actual baud value, or a baud index.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fBinary&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether binary mode is enabled. The system does not support non-binary mode   transfers, so this member should be TRUE (1). Trying to use FALSE (0) will   not work. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fParity&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether parity checking is enabled. If this member is TRUE, parity checking   is performed and parity errors are reported. This should not be confused with   the &lt;b&gt;Parity&lt;/b&gt; member, which controls the type of parity used in   communications.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fOutxCtsFlow&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether the CTS (clear-to-send) signal is monitored for output flow control.   If this member is TRUE and CTS is low, output is suspended until CTS is high   again. The CTS signal is under control of the DCE (usually a modem), the DTE   (usually the PC) simply monitors the status of this signal, the DTE does not   change it.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fOutxDsrFlow&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether the DSR (data-set-ready) signal is monitored for output flow control.   If this member is TRUE and DSR is low, output is suspended until DSR is high again.   Once again, this signal is under the control of the DCE; the DTE only   monitors this signal.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fDtrControl&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the DTR (data-terminal-ready) input flow control. This member can be one of   the following values: &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Value&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Meaning&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DTR_CONTROL_DISABLE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Lowers   the DTR line when the device is opened. The application can dynamically   adjust the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DTR_CONTROL_ENABLE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Raises   the DTR line when the device is opened. The application can dynamically   adjust the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DTR_CONTROL_HANDSHAKE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Enables   DTR flow-control handshaking. If this value is used, it is an error for the   application to attempt to adjust the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fDsrSensitivity&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether the communications driver is sensitive to the state of the DSR   signal. If this member is TRUE, the driver ignores any bytes received, unless   the DSR modem input line is high. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fTXContinueOnXoff&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether transmission stops when the input buffer is full and the driver has   transmitted the XOFF character. If this member is TRUE, transmission   continues after the XOFF character has been sent. If this member is FALSE,   transmission does not continue until the input buffer is within &lt;span class="SpellE"&gt;XonLim&lt;/span&gt; bytes of being empty and the driver has   transmitted the XON character.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fOutX&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether XON/XOFF flow control is used during transmission. If this member is   TRUE, transmission stops when the XOFF character is received and starts again   when the XON character is received. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fInX&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether XON/XOFF flow control is used during reception. If this member is   TRUE, the XOFF character is sent when the input buffer comes within &lt;span class="SpellE"&gt;XoffLim&lt;/span&gt; bytes of being full, and the XON character is sent   when the input buffer comes within &lt;span class="SpellE"&gt;XonLim&lt;/span&gt; bytes of   being empty. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fErrorChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether bytes received with parity errors are replaced with the character   specified by the &lt;span class="SpellE"&gt;&lt;b&gt;ErrorChar&lt;/b&gt;&lt;/span&gt; member. If this   member is TRUE and the &lt;span class="SpellE"&gt;&lt;b&gt;fParity&lt;/b&gt;&lt;/span&gt; member is TRUE,   replacement occurs. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fNull&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether null bytes are discarded. If this member is TRUE, null bytes are   discarded when received. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fRtsControl&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the RTS (request-to-send) input flow control. If this value is zero, the   default is RTS_CONTROL_HANDSHAKE. This member can be one of the following   values: &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Value&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Meaning&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;RTS_CONTROL_DISABLE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Lowers the   RTS line when the device is opened. The application can dynamically change   the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;RTS_CONTROL_ENABLE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Raises   the RTS line when the device is opened. The application can dynamically   change the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;RTS_CONTROL_HANDSHAKE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Enables   RTS flow-control handshaking. The driver raises the RTS line, enabling the   DCE to send, when the input buffer has enough room to receive data. The   driver lowers the RTS line, preventing the DCE to send, when the input buffer   does not have enough room to receive data. If this value is used, it is an   error for the application to attempt to adjust the state of the line.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 39.94%;" valign="top" width="39%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;RTS_CONTROL_TOGGLE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 35.06%;" valign="top" width="35%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   that the RTS line will be high if bytes are available for transmission. After   all buffered bytes have been sent, the RTS line will be low. If this value is   set, it is an error for an application to adjust the line. This value is   ignored in Windows 95; it causes the driver to act as if RTS_CONTROL_ENABLE   were specified.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fAbortOnError&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   whether read and write operations are terminated if an error occurs. If this   member is TRUE, the driver terminates all read and write operations with an   error status (ERROR_IO_ABORTED) if an error occurs. The driver will not accept   any further communications operations until the application has acknowledged   the error. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;fDummy2&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Reserved;   do not use. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;wReserved&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Not   used; &lt;u&gt;must&lt;/u&gt; be set to zero. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XonLim&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the minimum number of bytes allowed in the input buffer before the XON   character is sent. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XoffLim&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the maximum number of bytes allowed in the input buffer before the XOFF   character is sent. The maximum number of bytes allowed is calculated by   subtracting this value from the size, in bytes, of the input buffer. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Parity&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the parity scheme to be used. This member can be one of the following values:   &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Value&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Meaning&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;EVENPARITY&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Even&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;MARKPARITY&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Mark&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;NOPARITY&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;No parity&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;ODDPARITY&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Odd&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;StopBits&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the number of stop bits to be used. This member can be one of the following   values: &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Value&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Meaning&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;ONESTOPBIT&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;1 stop   bit&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;ONE5STOPBITS&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;1.5 stop   bits&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 24.66%;" valign="top" width="24%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;TWOSTOPBITS&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="2" style="padding: 3.75pt; width: 50.34%;" valign="top" width="50%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;2 stop   bits&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XonChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the value of the XON character for both transmission and reception. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XoffChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the value of the XOFF character for both transmission and reception. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;ErrorChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the value of the character used to replace bytes received with a parity   error. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;EofChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the value of the character used to signal the end of data. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span class="SpellE"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;EvtChar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Specifies   the value of the character used to cause the application to receive an   interrupt event. This setting does not actually cause anything to happen   without EV_RXFLAG and the use of an application wait for event.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 23.62%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;wReserved1&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td colspan="3" style="padding: 3.75pt; width: 75.34%;" valign="top" width="75%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Reserved;   do not use. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;!--[if !supportMisalignedColumns]--&gt;  &lt;tr height="0"&gt;   &lt;td style="border: medium none ;" width="139"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td style="border: medium none ;" width="143"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td style="border: medium none ;" width="89"&gt;&lt;br /&gt;&lt;/td&gt;   &lt;td style="border: medium none ;" width="205"&gt;&lt;br /&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;!--[endif]--&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;u3:p&gt;&lt;/u3:p&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 13.5pt; letter-spacing: 0pt;"&gt;Flow Control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Flow control in serial communications provides a mechanism for suspending communications while one of the devices is busy or for some reason cannot do any communication. There are traditionally two types of flow control: hardware and software.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;A common problem with serial communications is write operations that actually do not write the data to the device. Often, the problem lies in flow control being used when the program did not specify it. A close examination of the DCB structure reveals that one or more of the following members may be TRUE: &lt;span class="SpellE"&gt;fOutxCtsFlow&lt;/span&gt;, &lt;span class="SpellE"&gt;fOutxDsrFlow&lt;/span&gt;, or &lt;span class="SpellE"&gt;fOutX&lt;/span&gt;.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;  &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Before discussing the types of flow control, a good understanding of some terms is in order. Serial communications takes place between two devices. Traditionally, there is a PC and a modem or printer. The PC is labeled the Data Terminal Equipment (DTE). The DTE is sometimes called the &lt;i&gt;host&lt;/i&gt;. The modem, printer, or other peripheral equipment is identified as the Data Communications Equipment (DCE). The DCE is sometimes referred to as the &lt;i&gt;device&lt;/i&gt;.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Hardware flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Hardware flow control uses voltage signals on control lines of the serial cable to control whether sending or &lt;span class="GramE"&gt;receiving&lt;/span&gt; is enabled. The DTE and the DCE must agree on the types of flow control used for a communications session. Setting the DCB structure to enable flow control just configures the DTE. The DCE also needs configuration to make certain the DTE and DCE use the same type of flow control. There is no mechanism provided by Win32 to set the flow control of the DCE. DIP switches on the device, or commands sent to it typically establish its configuration. The following table describes the control lines, the direction of the flow control, and the line's effect on the DTE and DCE.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Hardware Flow-control Lines&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;table class="MsoNormalTable" style="width: 440.25pt;" border="1" cellpadding="0" width="587"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Line   and Direction&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Effect   on DTE/DCE&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;CTS&lt;br /&gt;  (Clear To Send)&lt;br /&gt;  Output flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DCE sets   the line high to indicate that it can receive data. DCE sets the line low to   indicate that it cannot receive data. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fOutxCtsFlow&lt;/b&gt;&lt;/span&gt;   member of the DCB is TRUE, then the DTE will not send data if this line is   low. It will resume sending if the line is high.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fOutxCtsFlow&lt;/b&gt;&lt;/span&gt;   member of the DCB is FALSE, then the state of the line does not affect   transmission.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DSR&lt;br /&gt;  (Data Set Ready)&lt;br /&gt;  Output flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DCE sets   the line high to indicate that it can receive data. DCE sets the line low to indicate   that it cannot receive data. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fOutxDsrFlow&lt;/b&gt;&lt;/span&gt;   member of the DCB is TRUE, then the DTE will not send data if this line is   low. It will resume sending if the line is high.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fOutxDsrFlow&lt;/b&gt;&lt;/span&gt;   member of the DCB is FALSE, then the state of the line does not affect   transmission.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DSR&lt;br /&gt;  (Data Set Ready)&lt;br /&gt;  Input flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the   DSR line is low, then data that arrives at the port is ignored. If the DSR   line is high, data that arrives at the port is received. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;This behavior occurs if the &lt;span class="SpellE"&gt;&lt;b&gt;fDsrSensitivity&lt;/b&gt;&lt;/span&gt; member of the DCB is set to TRUE.   If it is FALSE, then the state of the line does not affect reception.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;RTS&lt;br /&gt;  (Ready To Send)&lt;br /&gt;  Input flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The RTS   line is controlled by the DTE. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fRtsControl&lt;/b&gt;&lt;/span&gt;   member of the DCB is set to RTS_CONTROL_HANDSHAKE, the following flow control   is used: If the input buffer has enough room to receive data (at least half   the buffer is empty), the driver sets the RTS line high. If the input buffer   has little room for incoming data (less than a quarter of the buffer is   empty), the driver sets the RTS line low.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fRtsControl&lt;/b&gt;&lt;/span&gt;   member of the DCB is set to RTS_CONTROL_TOGGLE, the driver sets the RTS line   high when data is available for sending. The driver sets the line low when no   data is available for sending. Windows 95 ignores this value and treats it   the same as RTS_CONTROL_ENABLE.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fRtsControl&lt;/b&gt;&lt;/span&gt;   member of the DCB is set to RTS_CONTROL_ENABLE or RTS_CONTROL_DISABLE, the   application is free to change the state of the line as it needs. Note that in   this case, the state of the line does not affect reception.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The DCE will suspend transmission   when the line goes low. The DCE will resume transmission when the line goes   high.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 22.76%;" valign="top" width="22%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DTR&lt;br /&gt;  (Data Terminal Ready)&lt;br /&gt;  Input flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 76.22%;" valign="top" width="76%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The DTR   line is controlled by the DTE. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fDtrControl&lt;/b&gt;&lt;/span&gt;   member of the DCB is set to DTR_CONTROL_HANDSHAKE, the following flow control   is used: If the input buffer has enough room to receive data (at least half   the buffer is empty), the driver sets the DTR line high. If the input buffer   has little room for incoming data (less than a quarter of the buffer is   empty), the driver sets the DTR line low.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If the &lt;span class="SpellE"&gt;&lt;b&gt;fDtrControl&lt;/b&gt;&lt;/span&gt;   member of the DCB is set to DTR_CONTROL_ENABLE or DTR_CONTROL_DISABLE, the   application is free to change the state of the line as it needs. In this   case, the state of the line does not affect reception.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The DCE will suspend transmission   when the line goes low. The DCE will resume transmission when the line goes   high.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;u3:p&gt;&lt;/u3:p&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The need for flow control is easy to recognize when the CE_RXOVER error occurs. This error indicates an overflow of the receive buffer and data loss. If data arrives at the port faster than it is read, CE_RXOVER can occur. Increasing the input buffer size may cause the error to occur less frequently, but it does not completely solve the problem. Input flow control is necessary to completely alleviate this problem. When the driver detects that the input buffer is nearly full, it will lower the input flow-control lines. This should cause the DCE to stop transmitting, which gives the DTE enough time to read the data from the input buffer. When the input buffer has more room available, the voltage on flow-control lines is set high, and the DCE resumes sending data. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;A similar error is CE_OVERRUN. This error occurs when new data arrives before the communications hardware and serial communications driver completely receives old data. This can occur when the transmission speed is too high for the type of communications hardware or CPU. This can also occur when the operating system is not free to service the communications hardware. The only way to alleviate this problem is to apply some combination of decreasing the transmission speed, replacing the communications hardware, and increasing the CPU speed. Sometimes third-party hardware drivers that are not very efficient with CPU resources cause this error. Flow control cannot completely solve the problems that cause the CE_OVERRUN error, although it may help to reduce the frequency of the error.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Software flow control&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Software flow control uses data in the communications stream to control the transmission and reception of data. Because software flow control uses two special characters, XOFF and XON, binary transfers cannot use software flow control; the XON or XOFF character may appear in the binary data and would interfere with data transfer. Software flow control befits text-based communications or data being transferred that does not contain the XON and XOFF characters. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;In order to enable software flow control, the &lt;span class="SpellE"&gt;&lt;b&gt;fOutX&lt;/b&gt;&lt;/span&gt; and &lt;span class="SpellE"&gt;&lt;b&gt;fInX&lt;/b&gt;&lt;/span&gt; members of the DCB must be set to TRUE. The &lt;span class="SpellE"&gt;&lt;b&gt;fOutX&lt;/b&gt;&lt;/span&gt; member controls output flow control. The &lt;span class="SpellE"&gt;&lt;b&gt;fInX&lt;/b&gt;&lt;/span&gt; member controls input flow control.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;One thing to note is that the DCB allows the program to dynamically assign the values the system recognizes as flow-control characters. The &lt;span class="SpellE"&gt;&lt;b&gt;XoffChar&lt;/b&gt;&lt;/span&gt; member of the DCB dictates the XOFF character for both input and output flow control. The &lt;span class="SpellE"&gt;&lt;b&gt;XonChar&lt;/b&gt;&lt;/span&gt; member of the DCB similarly dictates the XON character. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;For input flow control, the &lt;span class="SpellE"&gt;&lt;b&gt;XoffLim&lt;/b&gt;&lt;/span&gt; member of the DCB specifies the minimum amount of free space allowed in &lt;span class="GramE"&gt;the&lt;/span&gt; input buffer before the XOFF character is sent. If the amount of free space in the input buffer drops below this amount, then the XOFF character is sent. For input flow control, the &lt;span class="SpellE"&gt;&lt;b&gt;XonLim&lt;/b&gt;&lt;/span&gt; member of the DCB specifies the minimum number of bytes allowed in the input buffer before the XON character is sent. If the amount of data in the input buffer drops below this value, then the XON character is sent.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;The following table lists the behavior of the DTE when using XOFF/XON flow control.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Software flow-control behavior&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;u3:p&gt;&lt;/u3:p&gt;   &lt;u3:p&gt;&lt;/u3:p&gt;  &lt;table class="MsoNormalTable" style="width: 440.25pt;" border="1" cellpadding="0" width="587"&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 27.72%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Flow-control   character&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 71.26%;" valign="top" width="71%"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;Behavior&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 27.72%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XOFF   received by DTE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 71.26%;" valign="top" width="71%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;DTE   transmission is suspended until XON is received. DTE reception continues. The   &lt;span class="SpellE"&gt;&lt;b&gt;fOutX&lt;/b&gt;&lt;/span&gt; member of the DCB controls this   behavior.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 27.72%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XON   received by DTE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 71.26%;" valign="top" width="71%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If DTE   transmission is suspended because of a previous XOFF character being   received, DTE transmission is resumed. The &lt;span class="SpellE"&gt;&lt;b&gt;fOutX&lt;/b&gt;&lt;/span&gt;   member of the DCB controls this behavior.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 27.72%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XOFF   sent from DTE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 71.26%;" valign="top" width="71%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XOFF is   automatically sent by the DTE when the receive buffer approaches full. The   actual limit is dictated by the &lt;span class="SpellE"&gt;&lt;b&gt;XoffLim&lt;/b&gt;&lt;/span&gt;   member of the DCB. The &lt;span class="SpellE"&gt;&lt;b&gt;fInX&lt;/b&gt;&lt;/span&gt; member of the   DCB controls this behavior. DTE transmission is controlled by the &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; member of the DCB as described   below.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 3.75pt; width: 27.72%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XON sent   from the DTE&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 3.75pt; width: 71.26%;" valign="top" width="71%"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;XON is   automatically sent by the DTE when the receive buffer approaches empty. The   actual limit is dictated by the &lt;span class="SpellE"&gt;&lt;b&gt;XonLim&lt;/b&gt;&lt;/span&gt;   member of the DCB. The &lt;span class="SpellE"&gt;&lt;b&gt;fInX&lt;/b&gt;&lt;/span&gt; member of the   DCB controls this behavior. &lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;u3:p&gt;&lt;/u3:p&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;If software flow control is enabled for input control, then the &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; member of the DCB takes effect. The &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; member controls whether transmission is suspended after the XOFF character is automatically sent by the system. If &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; is TRUE, then transmission continues after the XOFF is sent when the receive buffer is full. If &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; is FALSE, then transmission is suspended until the system automatically sends the XON character. DCE devices using software flow control will suspend their sending after the XOFF character is received. Some equipment will resume sending when the XON character is sent by the DTE. On the other hand, some DCE devices will resume sending after &lt;i&gt;any&lt;/i&gt; character arrives. The &lt;span class="SpellE"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/span&gt; member should be set to FALSE when communicating with a DCE device that resumes sending after any character arrives. If the DTE continued transmission after it automatically sent the XOFF, the resumption of transmission would cause the DCE to continue sending, defeating the XOFF.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;There is no mechanism available in the Win32 API to cause the DTE to behave the same way as these devices. The DCB structure contains no members for specifying suspended transmission to resume when &lt;i&gt;any&lt;/i&gt; character is received. The XON character is the only character that causes transmission to resume.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;One other interesting note about software flow control is that reception of XON and XOFF characters causes pending read operations to complete with zero bytes read. The XON and XOFF characters cannot be read by the application, since they are not placed in the input buffer.&lt;u3:p&gt;&lt;/u3:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt; &lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-size: 12pt; letter-spacing: 0pt;"&gt;A lot of programs on the market, including the Terminal program that comes with Windows, give the user three choices for flow control: Hardware, Software, or None. The Windows operating system itself does not limit an application in this way. The settings of the DCB allow for Software &lt;i&gt;and&lt;/i&gt; Hardware flow control simultaneously. In fact, it is possible to separately configure each member of the DCB that affects flow control, which allows for several different flow-control configurations. The limits placed on flow-control choices are there for ease-of-use reasons to reduce confusion for end users. The limits placed on flow-control choices may also be because devices used for communications may not support all types of flow control.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-7686100109247539694?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/7686100109247539694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=7686100109247539694' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7686100109247539694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7686100109247539694'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/serial-communication-device-control.html' title='Serial Communication Device Control Block'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-7456570149442075642</id><published>2008-07-18T04:33:00.000-07:00</published><updated>2008-07-18T04:39:42.162-07:00</updated><title type='text'>Configuring a Serial Port</title><content type='html'>&lt;p&gt;The most critical phase in serial communications programming is configuring the port settings with the &lt;a id="ctl00_rs1_mainContentContainer_ctl01" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/ms885192.aspx"&gt;DCB&lt;/a&gt; structure. &lt;/p&gt; &lt;p&gt;Erroneously initializing the &lt;b&gt;DCB&lt;/b&gt; structure is a common problem. When a serial communications function does not produce the expected results, the &lt;b&gt;DCB&lt;/b&gt; structure might be in err.&lt;/p&gt; &lt;p&gt;A call to the &lt;b&gt;CreateFile&lt;/b&gt; function opens a serial port with default port settings. Usually, the application needs to change the defaults. Use the &lt;a id="ctl00_rs1_mainContentContainer_ctl02" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/ms885609.aspx"&gt;GetCommState&lt;/a&gt; function to retrieve the default settings and use the &lt;a id="ctl00_rs1_mainContentContainer_ctl03" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/ms886806.aspx"&gt;SetCommState&lt;/a&gt; function to make port settings.&lt;/p&gt; &lt;p&gt;Also, port configuration involves using the &lt;a id="ctl00_rs1_mainContentContainer_ctl04" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/ms885171.aspx"&gt;COMMTIMEOUTS&lt;/a&gt; structure to set the timeout values for read/write operations. When a timeout occurs, the &lt;b&gt;ReadFile&lt;/b&gt; or &lt;b&gt;WriteFile&lt;/b&gt; function returns the specific number of characters successfully transferred.&lt;/p&gt; &lt;p class="labelproc"&gt;&lt;b&gt;To configure a serial port&lt;/b&gt; &lt;/p&gt;&lt;ol type="1"&gt;&lt;li&gt;Initialize the &lt;b&gt;DCBlength&lt;/b&gt; member of the &lt;b&gt;DCB&lt;/b&gt; structure to the size of the structure.  &lt;p&gt;This is required before passing the member as a variable to a function. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;Call the &lt;b&gt;GetCommState&lt;/b&gt; function to retrieve the default settings for the port opened with the &lt;b&gt;CreateFile&lt;/b&gt; function.  &lt;p&gt;To identify the port, specify in the &lt;i&gt;hPort&lt;/i&gt; parameter the handle that &lt;b&gt;CreateFile&lt;/b&gt; returns. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;Modify &lt;b&gt;DCB&lt;/b&gt; members as required.  &lt;p&gt;The following are &lt;b&gt;DCB&lt;/b&gt; structure members. &lt;/p&gt;&lt;div class="tablediv"&gt;&lt;table class="dtTABLE"&gt; &lt;tbody&gt;&lt;tr valign="top"&gt; &lt;th width="28%"&gt;Member&lt;/th&gt; &lt;th width="72%"&gt;Description&lt;/th&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;DCBlength&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Before calling the &lt;b&gt;GetCommState&lt;/b&gt; function, set this member to the length of the &lt;b&gt;DCB&lt;/b&gt; structure.  &lt;p&gt;Neglecting to do this can cause a failure or return erroneous data.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;BaudRate&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the device communication rate.  &lt;p&gt;Assigns an actual baud rate or an index by specifying a CBR_ constant.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fBinary&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if binary mode is enabled.  &lt;p&gt;The Microsoft® Win32® API does not support nonbinary mode transfers, so this member must be TRUE. &lt;/p&gt; &lt;p&gt;Using FALSE does not work.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fParity&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if parity checking is enabled.  &lt;p&gt;If this member is TRUE, parity checking is performed and errors are reported&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fOutxCtsFlow&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Turns the CTS flow control on and off.  &lt;p&gt;To use RTS/CTS flow control, specify TRUE for this member and RTS_CONTROL_HANDSHAKE for the &lt;b&gt;fRtsControl&lt;/b&gt; member.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fOutxDsrFlow&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Turns the DSR flow control on and off.  &lt;p&gt;DSR flow control is rarely used. &lt;/p&gt; &lt;p&gt;A typical port configuration is to set this member to FALSE, while enabling the DTR line.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fDtrControl&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the DTR flow control.  &lt;p&gt;DTR_CONTROL_ENABLE turns on the DTR line during the connection. &lt;/p&gt; &lt;p&gt;DTR_CONTROL_HANDSHAKE turns on DTR handshaking. &lt;/p&gt; &lt;p&gt;DTR_CONTROL_DISABLE turns off the DTR line.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fDsrSensitivity&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if the communications driver is sensitive to the state of the DSR signal.  &lt;p&gt;If this member is TRUE, the driver ignores any bytes received, unless the DSR modem input line is high.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fTXContinueOnXoff&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if transmission stops when the input buffer is full and the driver has transmitted the &lt;i&gt;XoffChar&lt;/i&gt; character.  &lt;p&gt;If this member is TRUE, transmission continues after the input buffer has come within &lt;i&gt;XoffLim&lt;/i&gt; bytes of being full and the driver has transmitted the &lt;i&gt;XoffChar&lt;/i&gt; character to stop receiving bytes. &lt;/p&gt; &lt;p&gt;If this member is FALSE, transmission does not continue until the input buffer is within &lt;i&gt;XonLim&lt;/i&gt; bytes of being empty and the driver has transmitted the &lt;i&gt;XonChar&lt;/i&gt; character to resume reception.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fOutX&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if XON/XOFF flow control is used during transmission.  &lt;p&gt;If this member is TRUE, transmission stops when the &lt;i&gt;XoffChar&lt;/i&gt; character is received and starts again when the &lt;i&gt;XonChar&lt;/i&gt; character is received.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fInX&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if XON/XOFF flow control is used during reception.  &lt;p&gt;If this member is TRUE, the &lt;i&gt;XoffChar&lt;/i&gt; character is sent when the input buffer comes within &lt;i&gt;XoffLim&lt;/i&gt; bytes of being full, and the &lt;i&gt;XonChar&lt;/i&gt; character is sent when the input buffer comes within &lt;i&gt;XonLim&lt;/i&gt; bytes of being empty.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fErrorChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if bytes received with parity errors are replaced with the character specified by the &lt;b&gt;ErrorChar&lt;/b&gt; member.  &lt;p&gt;If this member is TRUE and the &lt;i&gt;fParity&lt;/i&gt; member is TRUE, replacement occurs.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fNull&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if null bytes are discarded.  &lt;p&gt;If this member is TRUE, null bytes are discarded when received.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fRtsControl&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Turns the RTS flow control on and off.  &lt;p&gt;RTS_CONTROL_ENABLE turns on the RTS line during the connection. &lt;/p&gt; &lt;p&gt;RTS_CONTROL_HANDSHAKE turns on RTS handshaking. &lt;/p&gt; &lt;p&gt;RTS_CONTROL_DISABLE turns off the RTS line. &lt;/p&gt; &lt;p&gt;RTS_CONTROL_TOGGLE Specifies that the RTS line is high if bytes are available for transmission. &lt;/p&gt; &lt;p&gt;After all buffered bytes have been sent, the RTS line is low.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fAbortOnError&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies if read and write operations are terminated when an error occurs. &lt;p&gt;If this member is TRUE, the driver terminates read and write operations with an error status when an error occurs. &lt;/p&gt; &lt;p&gt;The driver does not accept further communications operations until the application has acknowledged the error by calling the &lt;b&gt;ClearCommError&lt;/b&gt; function.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;fDummy2&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Reserved; do not use.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;wReserved&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Not used; set to zero.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;XonLim&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the maximum number of bytes allowed in the queue.  &lt;p&gt;The XON character is sent if the number of bytes in the queue falls below this number.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;XoffLim&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the maximum number of bytes accepted in the input buffer before the XOFF character is sent.  &lt;p&gt;The maximum number of bytes accepted is calculated by subtracting this value from the size, in bytes, of the input buffer.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;ByteSize&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the bits per byte transmitted and received.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;Parity&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the parity scheme.  &lt;p&gt;Do not confuse this member with the &lt;b&gt;fParity&lt;/b&gt; member, which turns parity on or off. &lt;/p&gt; &lt;p&gt;Because parity is rarely used, this member can usually be NOPARITY.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;StopBits&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the number of stop bits.  &lt;p&gt;ONESTOPBIT is the most common setting.&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;XonChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the value of the XON character for both transmission and reception.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;XoffChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the value of the XOFF character for both transmission and reception.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;ErrorChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the value of the character used to replace bytes received with a parity error.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;EofChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the value of the character used to signal the end of data.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;EvtChar&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Specifies the value of the character used to signal an event.&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td width="28%"&gt;&lt;b&gt;WReserved1&lt;/b&gt;&lt;/td&gt; &lt;td width="72%"&gt;Reserved, do not use.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;/li&gt;&lt;li&gt;Call the &lt;b&gt;SetCommState&lt;/b&gt; function to set the port settings.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The following code example shows how to use the &lt;b&gt;GetCommState&lt;/b&gt; and &lt;b&gt;SetCommState&lt;/b&gt; functions to configure a serial port.&lt;/p&gt; &lt;div class="" id="ctl00_rs1_mainContentContainer_ctl05_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl05');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl05" space="preserve"&gt;DCB PortDCB;&lt;br /&gt;&lt;br /&gt;// Initialize the DCBlength member.&lt;br /&gt;PortDCB.DCBlength = sizeof (DCB);&lt;br /&gt;&lt;br /&gt;// Get the default port setting information.&lt;br /&gt;GetCommState (hPort, &amp;amp;PortDCB);&lt;br /&gt;&lt;br /&gt;// Change the DCB structure settings.&lt;br /&gt;PortDCB.BaudRate = 9600;              // Current baud&lt;br /&gt;PortDCB.fBinary = TRUE;               // Binary mode; no EOF check&lt;br /&gt;PortDCB.fParity = TRUE;               // Enable parity checking&lt;br /&gt;PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control&lt;br /&gt;PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control&lt;br /&gt;PortDCB.fDtrControl = DTR_CONTROL_ENABLE;&lt;br /&gt;                                     // DTR flow control type&lt;br /&gt;PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity&lt;br /&gt;PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx&lt;br /&gt;PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control&lt;br /&gt;PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control&lt;br /&gt;PortDCB.fErrorChar = FALSE;           // Disable error replacement&lt;br /&gt;PortDCB.fNull = FALSE;                // Disable null stripping&lt;br /&gt;PortDCB.fRtsControl = RTS_CONTROL_ENABLE;&lt;br /&gt;                                     // RTS flow control&lt;br /&gt;PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes on&lt;br /&gt;                                     // error&lt;br /&gt;PortDCB.ByteSize = 8;                 // Number of bits/byte, 4-8&lt;br /&gt;PortDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space&lt;br /&gt;PortDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2&lt;br /&gt;&lt;br /&gt;// Configure the port according to the specifications of the DCB&lt;br /&gt;// structure.&lt;br /&gt;if (!SetCommState (hPort, &amp;amp;PortDCB))&lt;br /&gt;{&lt;br /&gt; // Could not configure the serial port.&lt;br /&gt; dwError = GetLastError ();&lt;br /&gt; MessageBox (hMainWnd, TEXT("Unable to configure the serial port"),&lt;br /&gt;             TEXT("Error"), MB_OK);&lt;br /&gt; return FALSE;&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-7456570149442075642?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/7456570149442075642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=7456570149442075642' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7456570149442075642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7456570149442075642'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/configuring-serial-port_18.html' title='Configuring a Serial Port'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-8049708507837195791</id><published>2008-07-18T04:32:00.000-07:00</published><updated>2008-07-18T04:33:06.730-07:00</updated><title type='text'>Configuring a Communications Resource</title><content type='html'>&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl02" space="preserve"&gt;#include &lt;windows.h&gt;&lt;br /&gt;#include &lt;tchar.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;int _tmain(&lt;br /&gt;           int argc,&lt;br /&gt;           TCHAR *argv[]&lt;br /&gt;          )&lt;br /&gt;{&lt;br /&gt;  DCB dcb;&lt;br /&gt;  HANDLE hCom;&lt;br /&gt;  BOOL fSuccess;&lt;br /&gt;  TCHAR *pcCommPort = TEXT("\\\\.\\COM2");&lt;br /&gt;&lt;br /&gt;  hCom = CreateFile( pcCommPort,&lt;br /&gt;                   GENERIC_READ | GENERIC_WRITE,&lt;br /&gt;                   0,    // must be opened with exclusive-access&lt;br /&gt;                   NULL, // default security attributes&lt;br /&gt;                   OPEN_EXISTING, // must use OPEN_EXISTING&lt;br /&gt;                   0,    // not overlapped I/O&lt;br /&gt;                   NULL  // hTemplate must be NULL for comm devices&lt;br /&gt;                   );&lt;br /&gt;&lt;br /&gt;  if (hCom == INVALID_HANDLE_VALUE)&lt;br /&gt;  {&lt;br /&gt;      // Handle the error.&lt;br /&gt;      printf ("CreateFile failed with error %d.\n", GetLastError());&lt;br /&gt;      return (1);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // Build on the current configuration, and skip setting the size&lt;br /&gt;  // of the input and output buffers with SetupComm.&lt;br /&gt;&lt;br /&gt;  SecureZeroMemory(&amp;amp;dcb, sizeof(DCB));&lt;br /&gt;  dcb.DCBlength = sizeof(DCB);&lt;br /&gt;  fSuccess = GetCommState(hCom, &amp;amp;dcb);&lt;br /&gt;&lt;br /&gt;  if (!fSuccess)&lt;br /&gt;  {&lt;br /&gt;     // Handle the error.&lt;br /&gt;     printf ("GetCommState failed with error %d.\n", GetLastError());&lt;br /&gt;     return (2);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  // Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.&lt;br /&gt;&lt;br /&gt;  dcb.BaudRate = CBR_57600;     // set the baud rate&lt;br /&gt;  dcb.ByteSize = 8;             // data size, xmit, and rcv&lt;br /&gt;  dcb.Parity = NOPARITY;        // no parity bit&lt;br /&gt;  dcb.StopBits = ONESTOPBIT;    // one stop bit&lt;br /&gt;&lt;br /&gt;  fSuccess = SetCommState(hCom, &amp;amp;dcb);&lt;br /&gt;&lt;br /&gt;  if (!fSuccess)&lt;br /&gt;  {&lt;br /&gt;     // Handle the error.&lt;br /&gt;     printf ("SetCommState failed with error %d.\n", GetLastError());&lt;br /&gt;     return (3);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  _tprintf (TEXT("Serial port %s successfully reconfigured.\n"), pcCommPort);&lt;br /&gt;  return (0);&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-8049708507837195791?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/8049708507837195791/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=8049708507837195791' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8049708507837195791'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8049708507837195791'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/configuring-communications-resource.html' title='Configuring a Communications Resource'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-8668837811402955498</id><published>2008-07-18T04:21:00.001-07:00</published><updated>2008-07-18T04:21:57.647-07:00</updated><title type='text'>The CeChat Example Program</title><content type='html'>&lt;p&gt;The CeChat program is a simple point-to-point chat program that connects two Windows CE devices using any of the available serial ports on the device. The CeChat window is shown in Figure 16-1. Most of the window is taken up by the receive text window. Text received from the other device is displayed here. Along the bottom of the screen is the send text window. If you type characters here and either hit the Enter key or tap the Send button, the text is sent to the other device. The combo box on the command bar selects the serial port to use.&lt;/p&gt; &lt;p class="figureimage"&gt;&lt;img src="http://i.msdn.microsoft.com/Cc500407.figure_C16624177_1%28en-us,MSDN.10%29.png" /&gt;&lt;/p&gt; &lt;p class="caption"&gt;&lt;b&gt;FIGURE 16-1&lt;/b&gt; The CeChat window&lt;/p&gt; &lt;p&gt;The source code for CeChat is shown in Listing 16-1. CeChat uses three threads to accomplish its work. The primary thread manages the window and the message loop. The two secondary threads handle reading from and writing to the appropriate serial port.&lt;/p&gt;&lt;b&gt;LISTING 16-1&lt;/b&gt; &lt;h4&gt;CeChat.rc&lt;/h4&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl01_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl01');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl01" space="preserve"&gt;//======================================================================&lt;br /&gt;// Resource file&lt;br /&gt;//&lt;br /&gt;// Written for the book Programming Windows CE&lt;br /&gt;// Copyright (C) 2007 Douglas Boling&lt;br /&gt;//======================================================================&lt;br /&gt;#include “windows.h”&lt;br /&gt;#include “CeChat.h” // Program-specific stuff&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Icons and bitmaps&lt;br /&gt;//&lt;br /&gt;ID_ICON ICON “CeChat.ico” // Program icon&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Menu&lt;br /&gt;//&lt;br /&gt;ID_MENU MENU DISCARDABLE&lt;br /&gt;BEGIN&lt;br /&gt;POPUP “&amp;amp;File”&lt;br /&gt;BEGIN&lt;br /&gt;MENUITEM “E&amp;amp;xit”, IDM_EXIT&lt;br /&gt;END&lt;br /&gt;POPUP “&amp;amp;Help”&lt;br /&gt;BEGIN&lt;br /&gt;MENUITEM “&amp;amp;About...”, IDM_ABOUT&lt;br /&gt;END&lt;br /&gt;END&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Accelerator table&lt;br /&gt;//&lt;br /&gt;ID_ACCEL ACCELERATORS DISCARDABLE&lt;br /&gt;BEGIN&lt;br /&gt;“Q”, IDM_EXIT, VIRTKEY, CONTROL, NOINVERT&lt;br /&gt;“S”, ID_SENDBTN, VIRTKEY, ALT&lt;br /&gt;VK_RETURN, ID_SENDBTN, VIRTKEY&lt;br /&gt;END&lt;br /&gt;///----------------------------------------------------------------------&lt;br /&gt;// About box dialog template&lt;br /&gt;//&lt;br /&gt;aboutbox DIALOG discardable 10, 10, 135, 40&lt;br /&gt;STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | DS_CENTER |&lt;br /&gt;DS_MODALFRAME&lt;br /&gt;CAPTION “About”&lt;br /&gt;BEGIN&lt;br /&gt;ICON ID_ICON, -1, 3, 5, 10, 10&lt;br /&gt;LTEXT “CeChat - Written for the book Programming Windows \&lt;br /&gt;                             CE Copyright 2007 Douglas Boling”&lt;br /&gt;                                                 -1, 30, 5, 102, 37 END&lt;/pre&gt;&lt;/div&gt; &lt;h4&gt;CeChat.h&lt;/h4&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl02_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl02');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl02" space="preserve"&gt;/ //======================================================================&lt;br /&gt;// Header file&lt;br /&gt;//&lt;br /&gt;// Written for the book Programming Windows CE&lt;br /&gt;// Copyright (C) 2007 Douglas Boling&lt;br /&gt;//======================================================================&lt;br /&gt;// Returns number of elements&lt;br /&gt;#define dim(x) (sizeof(x) / sizeof(x[0]))&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Generic defines and data types&lt;br /&gt;//&lt;br /&gt;struct decodeUINT { // Structure associates&lt;br /&gt;UINT Code; // messages&lt;br /&gt;// with a function.&lt;br /&gt;LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;};&lt;br /&gt;struct decodeCMD { // Structure associates&lt;br /&gt;UINT Code; // menu IDs with a&lt;br /&gt;LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function.&lt;br /&gt;};&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Generic defines used by application&lt;br /&gt;#define ID_ICON 1 // App icon resource ID&lt;br /&gt;#define ID_MENU 2 // Menu resource ID&lt;br /&gt;#define ID_ACCEL 3 // Accel table ID&lt;br /&gt;#define IDC_CMDBAR 4 // Command band ID&lt;br /&gt;#define ID_RCVTEXT 5 // Receive text box&lt;br /&gt;#define ID_SENDTEXT 6 // Send text box&lt;br /&gt;#define ID_SENDBTN 7 // Send button&lt;br /&gt;// Menu item IDs&lt;br /&gt;#define IDM_EXIT 1&lt;br /&gt;#define IDM_USECOM 110 // Use COM.&lt;br /&gt;#define IDM_ABOUT 120 // Help menu&lt;br /&gt;// Command bar IDs&lt;br /&gt;#define IDC_COMPORT 150 // COM port combo box&lt;br /&gt;#define IDC_BAUDRATE 151 // Baud rate combo box&lt;br /&gt;#define TEXTSIZE 256&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Function prototypes&lt;br /&gt;//&lt;br /&gt;DWORD WINAPI ReadThread (PVOID pArg);&lt;br /&gt;DWORD WINAPI SendThread (PVOID pArg);&lt;br /&gt;HANDLE InitCommunication (HWND, LPTSTR);&lt;br /&gt;int FillComComboBox (HWND);&lt;br /&gt;HWND InitInstance (HINSTANCE, LPWSTR, int);&lt;br /&gt;int TermInstance (HINSTANCE, int);&lt;br /&gt;// Window procedures&lt;br /&gt;LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;// Message handlers&lt;br /&gt;LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;LRESULT DoSizeMain (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;LRESULT DoSetFocusMain (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;LRESULT DoPocketPCShell (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;LRESULT DoCommandMain (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;// Command functions&lt;br /&gt;LPARAM DoMainCommandExit (HWND, WORD, HWND, WORD);&lt;br /&gt;LPARAM DoMainCommandComPort (HWND, WORD, HWND, WORD);&lt;br /&gt;LPARAM DoMainCommandSendText (HWND, WORD, HWND, WORD);&lt;br /&gt;LPARAM DoMainCommandAbout (HWND, WORD, HWND, WORD);&lt;br /&gt;// Dialog procedures&lt;br /&gt;BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM);&lt;br /&gt;BOOL CALLBACK EditAlbumDlgProc (HWND, UINT, WPARAM, LPARAM);&lt;/pre&gt;&lt;/div&gt; &lt;h4&gt;CeChat.cpp&lt;/h4&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl03_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl03');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl03" space="preserve"&gt;//======================================================================&lt;br /&gt;// CeChat - A Windows CE communication demo&lt;br /&gt;//&lt;br /&gt;// Written for the book Programming Windows CE&lt;br /&gt;// Copyright (C) 2007 Douglas Boling&lt;br /&gt;//======================================================================&lt;br /&gt;#include &lt;windows.h&gt; // For all that Windows stuff&lt;br /&gt;#include &lt;commctrl.h&gt; // Command bar includes&lt;br /&gt;#include “CeChat.h” // Program-specific stuff&lt;br /&gt;#if defined(WIN32_PLATFORM_PSPC)&lt;br /&gt;#include &lt;aygshell.h&gt; // Add Pocket PC includes.&lt;br /&gt;#pragma comment( lib, “aygshell” ) // Link Pocket PC lib for menu bar.&lt;br /&gt;#endif&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// Global data&lt;br /&gt;//&lt;br /&gt;const TCHAR szAppName[] = TEXT (“CeChat”);&lt;br /&gt;HINSTANCE hInst; // Program instance handle.&lt;br /&gt;BOOL fContinue = TRUE;&lt;br /&gt;HANDLE hComPort = INVALID_HANDLE_VALUE;&lt;br /&gt;int nSpeed = CBR_19200;&lt;br /&gt;int nLastDev = -1;&lt;br /&gt;#if defined(WIN32_PLATFORM_PSPC) &amp;amp;&amp;amp; (_WIN32_WCE &gt;= 300)&lt;br /&gt;SHACTIVATEINFO sai;&lt;br /&gt;#endif&lt;br /&gt;HANDLE g_hSendEvent = INVALID_HANDLE_VALUE;&lt;br /&gt;HANDLE hReadThread = INVALID_HANDLE_VALUE;&lt;br /&gt;// Message dispatch table for MainWindowProc&lt;br /&gt;const struct decodeUINT MainMessages[] = {&lt;br /&gt;WM_CREATE, DoCreateMain,&lt;br /&gt;WM_SIZE, DoSizeMain,&lt;br /&gt;WM_COMMAND, DoCommandMain,&lt;br /&gt;WM_SETTINGCHANGE, DoPocketPCShell,&lt;br /&gt;WM_ACTIVATE, DoPocketPCShell,&lt;br /&gt;WM_SETFOCUS, DoSetFocusMain,&lt;br /&gt;WM_DESTROY, DoDestroyMain,&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// Command Message dispatch for MainWindowProc&lt;br /&gt;const struct decodeCMD MainCommandItems[] = {&lt;br /&gt;IDC_COMPORT, DoMainCommandComPort,&lt;br /&gt;ID_SENDBTN, DoMainCommandSendText,&lt;br /&gt;IDM_EXIT, DoMainCommandExit,&lt;br /&gt;IDM_ABOUT, DoMainCommandAbout,&lt;br /&gt;};&lt;br /&gt;//======================================================================&lt;br /&gt;// Program entry point&lt;br /&gt;//&lt;br /&gt;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,&lt;br /&gt;                                LPWSTR lpCmdLine, int nCmdShow) {&lt;br /&gt;HWND hwndMain;&lt;br /&gt;HACCEL hAccel;&lt;br /&gt;MSG msg;&lt;br /&gt;int rc = 0;&lt;br /&gt;// Initialize this instance.&lt;br /&gt;hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);&lt;br /&gt;if (hwndMain == 0)&lt;br /&gt;   return 0x10;&lt;br /&gt;// Load accelerator table.&lt;br /&gt;hAccel = LoadAccelerators (hInst, MAKEINTRESOURCE (ID_ACCEL));&lt;br /&gt;// Application message loop&lt;br /&gt;while (GetMessage (&amp;amp;msg, NULL, 0, 0)) {&lt;br /&gt;      if (!TranslateAccelerator (hwndMain, hAccel, &amp;amp;msg)) {&lt;br /&gt;TranslateMessage (&amp;amp;msg);&lt;br /&gt;DispatchMessage (&amp;amp;msg);&lt;br /&gt;       }&lt;br /&gt;}&lt;br /&gt;// Instance cleanup&lt;br /&gt;return TermInstance (hInstance, msg.wParam);&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// InitInstance - Instance initialization&lt;br /&gt;//&lt;br /&gt;HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow){&lt;br /&gt;HWND hWnd;&lt;br /&gt;HANDLE hThread;&lt;br /&gt;WNDCLASS wc;&lt;br /&gt;INITCOMMONCONTROLSEX icex;&lt;br /&gt;// Save program instance handle in global variable.&lt;br /&gt;hInst = hInstance;&lt;br /&gt;#if defined(WIN32_PLATFORM_PSPC)&lt;br /&gt;// If Win Mobile, allow only one instance of the application.&lt;br /&gt;hWnd = FindWindow (szAppName, NULL);&lt;br /&gt;if (hWnd) {&lt;br /&gt;SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#endif&lt;br /&gt;// Register application main window class.&lt;br /&gt;  wc.style = 0; // Window style&lt;br /&gt; wc.lpfnWndProc = MainWndProc; // Callback function&lt;br /&gt; wc.cbClsExtra = 0; // Extra class data&lt;br /&gt; wc.cbWndExtra = 0; // Extra window data&lt;br /&gt; wc.hInstance = hInstance; // Owner handle&lt;br /&gt; wc.hIcon = NULL; // Application icon&lt;br /&gt; wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor&lt;br /&gt; wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);&lt;br /&gt; wc.lpszMenuName = NULL; // Menu name&lt;br /&gt; wc.lpszClassName = szAppName; // Window class name&lt;br /&gt;if (RegisterClass (&amp;amp;wc) == 0) return 0;&lt;br /&gt;// Load the command bar common control class.&lt;br /&gt;icex.dwSize = sizeof (INITCOMMONCONTROLSEX);&lt;br /&gt;icex.dwICC = ICC_BAR_CLASSES;&lt;br /&gt;InitCommonControlsEx (&amp;amp;icex);&lt;br /&gt;// Create unnamed auto-reset event initially false.&lt;br /&gt;g_hSendEvent = CreateEvent (NULL, FALSE, FALSE, NULL);&lt;br /&gt;// Create main window.&lt;br /&gt;hWnd = CreateWindow (szAppName, TEXT (“CeChat”),&lt;br /&gt;WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,&lt;br /&gt;CW_USEDEFAULT, CW_USEDEFAULT, NULL,&lt;br /&gt;NULL, hInstance, NULL);&lt;br /&gt;// Return fail code if window not created.&lt;br /&gt;if (!IsWindow (hWnd)) return 0;&lt;br /&gt;// Create write thread. Read thread created when port opened.&lt;br /&gt;hThread = CreateThread (NULL, 0, SendThread, hWnd, 0, NULL);&lt;br /&gt;if (hThread)&lt;br /&gt;CloseHandle (hThread);&lt;br /&gt;else {&lt;br /&gt;DestroyWindow (hWnd);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;// Standard show and update calls&lt;br /&gt;ShowWindow (hWnd, nCmdShow);&lt;br /&gt;UpdateWindow (hWnd);&lt;br /&gt;return hWnd;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// TermInstance - Program cleanup&lt;br /&gt;//&lt;br /&gt;int TermInstance (HINSTANCE hInstance, int nDefRC) {&lt;br /&gt;HANDLE hPort = hComPort;&lt;br /&gt;fContinue = FALSE;&lt;br /&gt;hComPort = INVALID_HANDLE_VALUE;&lt;br /&gt;if (hPort != INVALID_HANDLE_VALUE)&lt;br /&gt;CloseHandle (hPort);&lt;br /&gt;if (g_hSendEvent != INVALID_HANDLE_VALUE) {&lt;br /&gt;PulseEvent (g_hSendEvent);&lt;br /&gt;Sleep(100);&lt;br /&gt;CloseHandle (g_hSendEvent);&lt;br /&gt;} return nDefRC;&lt;br /&gt;}&lt;br /&gt;//======================================================================&lt;br /&gt;// Message handling procedures for MainWindow&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// MainWndProc - Callback function for application window&lt;br /&gt;//&lt;br /&gt;LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;          LPARAM lParam) {&lt;br /&gt;int i;&lt;br /&gt;//&lt;br /&gt;// Search message list to see if we need to handle this&lt;br /&gt;// message. If in list, call procedure.&lt;br /&gt;//&lt;br /&gt;for (i = 0; i &lt; dim(MainMessages); i++) {&lt;br /&gt;  if (wMsg == MainMessages[i].Code)&lt;br /&gt;  return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);&lt;br /&gt;}&lt;br /&gt;return DefWindowProc (hWnd, wMsg, wParam, lParam);&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoCreateMain - Process WM_CREATE message for window.&lt;br /&gt;//&lt;br /&gt;LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;              LPARAM lParam) {&lt;br /&gt;HWND hwndCB, hC1, hC2, hC3;&lt;br /&gt;int i;&lt;br /&gt;TCHAR szFirstDev[32];&lt;br /&gt;LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;&lt;br /&gt;#if defined(WIN32_PLATFORM_PSPC)&lt;br /&gt; memset (&amp;amp;sai, 0, sizeof (sai));&lt;br /&gt; sai.cbSize = sizeof (sai);&lt;br /&gt;{&lt;br /&gt;SHMENUBARINFO mbi; // For WinMobile, create&lt;br /&gt;memset(&amp;amp;mbi, 0, sizeof(SHMENUBARINFO)); // menu bar so that we&lt;br /&gt;mbi.cbSize = sizeof(SHMENUBARINFO); // have a sip button.&lt;br /&gt;mbi.hwndParent = hWnd;&lt;br /&gt;mbi.dwFlags = SHCMBF_EMPTYBAR;&lt;br /&gt;SHCreateMenuBar(&amp;amp;mbi);&lt;br /&gt;SetWindowPos (hWnd, 0, 0, 0, lpcs-&gt;cx, lpcs-&gt;cy-26,&lt;br /&gt;SWP_NOZORDER | SWP_NOMOVE);&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;// Create a command bar.&lt;br /&gt;hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);&lt;br /&gt;CommandBar_InsertMenubar (hwndCB, hInst, ID_MENU, 0);&lt;br /&gt;// Insert the COM port combo box.&lt;br /&gt;CommandBar_InsertComboBox (hwndCB, hInst, 140, CBS_DROPDOWNLIST,&lt;br /&gt;        IDC_COMPORT, 1);&lt;br /&gt;FillComComboBox (hWnd);&lt;br /&gt;// Add exit button to command bar.&lt;br /&gt;CommandBar_AddAdornments (hwndCB, 0, 0);&lt;br /&gt;// Create child windows. They will be positioned in WM_SIZE.&lt;br /&gt;// Create receive text window.&lt;br /&gt;hC1 = CreateWindowEx (WS_EX_CLIENTEDGE, TEXT (“edit”),&lt;br /&gt;TEXT (“”), WS_VISIBLE | WS_CHILD |&lt;br /&gt;WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL |&lt;br /&gt;ES_READONLY, 0, 0, 10, 10, hWnd,&lt;br /&gt;(HMENU)ID_RCVTEXT, hInst, NULL);&lt;br /&gt;// Create send text window.&lt;br /&gt;hC2 = CreateWindowEx (WS_EX_CLIENTEDGE, TEXT (“edit”),&lt;br /&gt;TEXT (“”), WS_VISIBLE | WS_CHILD,&lt;br /&gt;0, 0, 10, 10, hWnd, (HMENU)ID_SENDTEXT,&lt;br /&gt;  hInst, NULL);&lt;br /&gt;// Create send text window.&lt;br /&gt;hC3 = CreateWindowEx (WS_EX_CLIENTEDGE, TEXT (“button”),&lt;br /&gt;TEXT (“&amp;amp;Send”), WS_VISIBLE | WS_CHILD |&lt;br /&gt;BS_DEFPUSHBUTTON, 0, 0, 10, 10,&lt;br /&gt;hWnd, (HMENU)ID_SENDBTN, hInst, NULL);&lt;br /&gt;// Destroy frame if window not created.&lt;br /&gt;if (!IsWindow (hC1) || !IsWindow (hC2) || !IsWindow (hC3)) {&lt;br /&gt;DestroyWindow (hWnd);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;// Open a COM port.&lt;br /&gt;for (i = 0; i &lt; 10; i++) {&lt;br /&gt;   if (SendDlgItemMessage (hwndCB, IDC_COMPORT, CB_GETLBTEXT, i,&lt;br /&gt;(LPARAM)szFirstDev) == CB_ERR)&lt;br /&gt;   break;&lt;br /&gt;if (InitCommunication (hWnd, szFirstDev) !=&lt;br /&gt;INVALID_HANDLE_VALUE) {&lt;br /&gt;SendDlgItemMessage (hwndCB, IDC_COMPORT, CB_SETCURSEL, i,&lt;br /&gt;                         (LPARAM)szFirstDev);&lt;br /&gt;      break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoSizeMain - Process WM_SIZE message for window.&lt;br /&gt;//&lt;br /&gt;LRESULT DoSizeMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam){&lt;br /&gt;RECT rect;&lt;br /&gt;// Adjust the size of the client rect to take into account&lt;br /&gt;// the command bar height.&lt;br /&gt;GetClientRect (hWnd, &amp;amp;rect);&lt;br /&gt;rect.top += CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));&lt;br /&gt;SetWindowPos (GetDlgItem (hWnd, ID_RCVTEXT), NULL, rect.left,&lt;br /&gt;          rect.top, (rect.right - rect.left),&lt;br /&gt;  rect.bottom - rect.top - 25, SWP_NOZORDER);&lt;br /&gt;SetWindowPos (GetDlgItem (hWnd, ID_SENDTEXT), NULL, rect.left,&lt;br /&gt;      rect.bottom - 25, (rect.right - rect.left) - 50,&lt;br /&gt;                    25, SWP_NOZORDER);&lt;br /&gt;SetWindowPos (GetDlgItem (hWnd, ID_SENDBTN), NULL,&lt;br /&gt;(rect.right - rect.left) - 50, rect.bottom - 25,&lt;br /&gt;50, 25, SWP_NOZORDER); return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoPocketPCShell - Process Pocket PC required messages.&lt;br /&gt;//&lt;br /&gt;LRESULT DoPocketPCShell (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;     LPARAM lParam) {&lt;br /&gt;#if defined(WIN32_PLATFORM_PSPC)&lt;br /&gt; if (wMsg == WM_SETTINGCHANGE)&lt;br /&gt;     return SHHandleWMSettingChange(hWnd, wParam, lParam, &amp;amp;sai);&lt;br /&gt; if (wMsg == WM_ACTIVATE)&lt;br /&gt;     return SHHandleWMActivate(hWnd, wParam, lParam, &amp;amp;sai, 0);&lt;br /&gt;#endif&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoFocusMain - Process WM_SETFOCUS message for window.&lt;br /&gt;//&lt;br /&gt;LRESULT DoSetFocusMain (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;      LPARAM lParam) {&lt;br /&gt;SetFocus (GetDlgItem (hWnd, ID_SENDTEXT));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoCommandMain - Process WM_COMMAND message for window.&lt;br /&gt;//&lt;br /&gt;LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;      LPARAM lParam) {&lt;br /&gt;WORD idItem, wNotifyCode;&lt;br /&gt;HWND hwndCtl;&lt;br /&gt;int i;&lt;br /&gt;// Parse the parameters.&lt;br /&gt;idItem = (WORD) LOWORD (wParam);&lt;br /&gt;wNotifyCode = (WORD) HIWORD (wParam);&lt;br /&gt;hwndCtl = (HWND) lParam;&lt;br /&gt;// Call routine to handle control message.&lt;br /&gt;for (i = 0; i &lt; dim(MainCommandItems); i++) {&lt;br /&gt;   if (idItem == MainCommandItems[i].Code)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;return (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl,&lt;br /&gt;        wNotifyCode);&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoDestroyMain - Process WM_DESTROY message for window.&lt;br /&gt;//&lt;br /&gt;LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;   LPARAM lParam) {&lt;br /&gt;PostQuitMessage (0);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//======================================================================&lt;br /&gt;// Command handler routines&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoMainCommandExit - Process Program Exit command.&lt;br /&gt;//&lt;br /&gt;LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,&lt;br /&gt;             WORD wNotifyCode) {&lt;br /&gt;SendMessage (hWnd, WM_CLOSE, 0, 0);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoMainCommandComPort - Process the COM port combo box commands.&lt;br /&gt;// LPARAM DoMainCommandComPort (HWND hWnd, WORD idItem, HWND hwndCtl,&lt;br /&gt;WORD wNotifyCode) {&lt;br /&gt;int i;&lt;br /&gt;TCHAR szDev[32];&lt;br /&gt;if (wNotifyCode == CBN_SELCHANGE) {&lt;br /&gt; i = SendMessage (hwndCtl, CB_GETCURSEL, 0, 0);&lt;br /&gt; if (i != nLastDev) {&lt;br /&gt;SendMessage (hwndCtl, CB_GETLBTEXT, i, (LPARAM)szDev);&lt;br /&gt;InitCommunication (hWnd, szDev);&lt;br /&gt;SetFocus (GetDlgItem (hWnd, ID_SENDTEXT));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoMainCommandSendText - Process the Send text button.&lt;br /&gt;//&lt;br /&gt;LPARAM DoMainCommandSendText (HWND hWnd, WORD idItem, HWND hwndCtl,&lt;br /&gt;        WORD wNotifyCode) {&lt;br /&gt;// Set event so that sender thread will send the text.&lt;br /&gt;SetEvent (g_hSendEvent);&lt;br /&gt;SetFocus (GetDlgItem (hWnd, ID_SENDTEXT));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// DoMainCommandAbout - Process the Help | About menu command.&lt;br /&gt;//&lt;br /&gt;LPARAM DoMainCommandAbout(HWND hWnd, WORD idItem, HWND hwndCtl,&lt;br /&gt;                    WORD wNotifyCode) { //&lt;br /&gt;Use DialogBox to create modal dialog.&lt;br /&gt;DialogBox (hInst, TEXT (“aboutbox”), hWnd, AboutDlgProc);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//======================================================================&lt;br /&gt;// About Dialog procedure&lt;br /&gt;//&lt;br /&gt;BOOL CALLBACK AboutDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,&lt;br /&gt;LPARAM lParam) {&lt;br /&gt;switch (wMsg) {&lt;br /&gt;  case WM_COMMAND:&lt;br /&gt;    switch (LOWORD (wParam)) {&lt;br /&gt;      case IDOK:&lt;br /&gt;   case IDCANCEL:&lt;br /&gt;EndDialog (hWnd, 0);&lt;br /&gt;return TRUE;&lt;br /&gt;}&lt;br /&gt;      break;&lt;br /&gt;}&lt;br /&gt;return FALSE;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// FillComComboBox - Fills the COM port combo box&lt;br /&gt;//&lt;br /&gt;int FillComComboBox (HWND hWnd) {&lt;br /&gt; int rc;&lt;br /&gt;WIN32_FIND_DATA fd;&lt;br /&gt;HANDLE hFind;&lt;br /&gt;hFind = FindFirstFileEx (TEXT (“COM?:”), FindExInfoStandard, &amp;amp;fd,&lt;br /&gt;FindExSearchLimitToDevices, NULL, 0);&lt;br /&gt;if (hFind != INVALID_HANDLE_VALUE) {&lt;br /&gt;   do {&lt;br /&gt;SendDlgItemMessage (GetDlgItem (hWnd, IDC_CMDBAR),&lt;br /&gt;       IDC_COMPORT, CB_INSERTSTRING,&lt;br /&gt;      -1, (LPARAM)fd.cFileName);&lt;br /&gt;   rc = FindNextFile (hFind, &amp;amp;fd);&lt;br /&gt;} while (rc);&lt;br /&gt;rc = FindClose (hFind);&lt;br /&gt;}&lt;br /&gt;SendDlgItemMessage (GetDlgItem (hWnd, IDC_CMDBAR), IDC_COMPORT,&lt;br /&gt;         CB_SETCURSEL, 0, 0);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//----------------------------------------------------------------------&lt;br /&gt;// InitCommunication - Open and initialize selected COM port.&lt;br /&gt;//&lt;br /&gt;HANDLE InitCommunication (HWND hWnd, LPTSTR pszDevName) {&lt;br /&gt;DCB dcb;&lt;br /&gt;TCHAR szDbg[128];&lt;br /&gt;COMMTIMEOUTS cto;&lt;br /&gt;HANDLE hLocal;&lt;br /&gt;DWORD dwTStat;&lt;br /&gt;hLocal = hComPort;&lt;br /&gt;hComPort = INVALID_HANDLE_VALUE;&lt;br /&gt;if (hLocal != INVALID_HANDLE_VALUE)&lt;br /&gt;CloseHandle (hLocal); // This causes WaitCommEvent to return.&lt;br /&gt;hLocal = CreateFile (pszDevName, GENERIC_READ | GENERIC_WRITE,&lt;br /&gt;                                   0, NULL, OPEN_EXISTING, 0, NULL);&lt;br /&gt;if (hLocal != INVALID_HANDLE_VALUE) {&lt;br /&gt;// Configure port. dcb.DCBlength = sizeof (dcb);&lt;br /&gt;GetCommState (hLocal, &amp;amp;dcb);&lt;br /&gt;dcb.BaudRate = nSpeed;&lt;br /&gt;dcb.fParity = FALSE;&lt;br /&gt;dcb.fNull = FALSE;&lt;br /&gt;dcb.StopBits = ONESTOPBIT;&lt;br /&gt;dcb.Parity = NOPARITY;&lt;br /&gt;dcb.ByteSize = 8;&lt;br /&gt;SetCommState (hLocal, &amp;amp;dcb);&lt;br /&gt;// Set the timeouts. Set infinite read timeout.&lt;br /&gt;cto.ReadIntervalTimeout = 0;&lt;br /&gt;cto.ReadTotalTimeoutMultiplier = 0;&lt;br /&gt;cto.ReadTotalTimeoutConstant = 0;&lt;br /&gt;cto.WriteTotalTimeoutMultiplier = 0;&lt;br /&gt;cto.WriteTotalTimeoutConstant = 0;&lt;br /&gt;SetCommTimeouts (hLocal, &amp;amp;cto);&lt;br /&gt;wsprintf (szDbg, TEXT (“Port %s opened\r\n”), pszDevName);&lt;br /&gt;SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0,&lt;br /&gt;      (LPARAM)szDbg);&lt;br /&gt;// Start read thread if not already started.&lt;br /&gt;hComPort = hLocal;&lt;br /&gt;if (!GetExitCodeThread (hReadThread, &amp;amp;dwTStat) ||&lt;br /&gt;(dwTStat != STILL_ACTIVE)) {&lt;br /&gt;hReadThread = CreateThread (NULL, 0, ReadThread, hWnd,&lt;br /&gt;                                                   0, &amp;amp;dwTStat);&lt;br /&gt;  if (hReadThread)&lt;br /&gt;CloseHandle (hReadThread);&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt; wsprintf (szDbg, TEXT (“Couldn\’t open port %s. rc=%d\r\n”),&lt;br /&gt;  pszDevName, GetLastError());&lt;br /&gt;SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL,&lt;br /&gt;0, (LPARAM)szDbg);&lt;br /&gt;   }&lt;br /&gt;   return hComPort;&lt;br /&gt;}&lt;br /&gt;//======================================================================&lt;br /&gt;// SendThread - Sends characters to the serial port&lt;br /&gt;//&lt;br /&gt;DWORD WINAPI SendThread (PVOID pArg) {&lt;br /&gt;HWND hWnd, hwndSText;&lt;br /&gt;int rc;&lt;br /&gt;DWORD cBytes;&lt;br /&gt;WCHAR szText[TEXTSIZE];&lt;br /&gt;char szAnsi[TEXTSIZE];&lt;br /&gt;size_t siz;&lt;br /&gt;hWnd = (HWND)pArg;&lt;br /&gt;hwndSText = GetDlgItem (hWnd, ID_SENDTEXT);&lt;br /&gt;while (1) {&lt;br /&gt;   rc = WaitForSingleObject (g_hSendEvent, INFINITE);&lt;br /&gt; if (rc == WAIT_OBJECT_0) {&lt;br /&gt;     if (!fContinue)&lt;br /&gt;     break;&lt;br /&gt;// Disable send button while sending.&lt;br /&gt;EnableWindow (GetDlgItem (hWnd, ID_SENDBTN), FALSE);&lt;br /&gt;// Get the text, terminate the line and convert to ansi&lt;br /&gt;GetWindowText (hwndSText, szText, dim(szText));&lt;br /&gt;StringCchCat (szText, dim(szText), TEXT (“\r\n”));&lt;br /&gt;wcstombs_s (&amp;amp;siz, szAnsi, sizeof (szAnsi), szText, _TRUNCATE);&lt;br /&gt;// Write to the serial port&lt;br /&gt;rc = WriteFile (hComPort, szText,&lt;br /&gt;       lstrlen (szText)*sizeof (TCHAR),&amp;amp;cBytes, 0);&lt;br /&gt;if (rc) {&lt;br /&gt;// Copy sent text to output window.&lt;br /&gt;SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0,&lt;br /&gt;              (LPARAM)TEXT (“ &gt;”));&lt;br /&gt;SetWindowText (hwndSText, TEXT (“”)); // Clear text box&lt;br /&gt;} else {&lt;br /&gt;// Else, print error message.&lt;br /&gt;wsprintf (szText, TEXT (“Send failed rc=%d\r\n”),&lt;br /&gt;         GetLastError());&lt;br /&gt;DWORD dwErr = 0;&lt;br /&gt;COMSTAT Stat;&lt;br /&gt;if (ClearCommError (hComPort, &amp;amp;dwErr, &amp;amp;Stat)) {&lt;br /&gt;    printf (“fail\n”);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;// Put text in receive text box.&lt;br /&gt;SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0,&lt;br /&gt;                        (LPARAM)szText);&lt;br /&gt;EnableWindow (GetDlgItem (hWnd, ID_SENDBTN), TRUE);&lt;br /&gt;} else&lt;br /&gt; break;&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;//======================================================================&lt;br /&gt;// ReadThread - Receives characters from the serial port&lt;br /&gt;//&lt;br /&gt;DWORD WINAPI ReadThread (PVOID pArg) {&lt;br /&gt;HWND hWnd;&lt;br /&gt;DWORD cBytes, i;&lt;br /&gt;WCHAR szText[TEXTSIZE];&lt;br /&gt;char szAnsi[TEXTSIZE];&lt;br /&gt;size_t siz;&lt;br /&gt;hWnd = (HWND)pArg;&lt;br /&gt;while (fContinue) {&lt;br /&gt; for (i = 0; i &lt; sizeof (szAnsi)-1; i++) {&lt;br /&gt;while (!ReadFile (hComPort, &amp;amp;szAnsi[i], 1, &amp;amp;cBytes, 0))&lt;br /&gt; if (hComPort == INVALID_HANDLE_VALUE)&lt;br /&gt;     return 0;&lt;br /&gt;if (szAnsi[i] == ‘\n’) {&lt;br /&gt;   szAnsi[i+1] = ‘\0’;&lt;br /&gt;   break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;// Convert to Unicode&lt;br /&gt;mbstowcs_s (&amp;amp;siz, szText, dim (szText), szAnsi, _TRUNCATE);&lt;br /&gt;SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0,&lt;br /&gt;      (LPARAM)szText);&lt;br /&gt;  }&lt;br /&gt;             return 0;&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;When the CeChat window is created, it sniffs out the COM port names using &lt;i&gt;FindFileEx&lt;/i&gt;. The combo box is then filled, and an attempt is made to open each of the COM ports. The process stops when the first COM port is opened. Once a port is opened, the read thread is created to wait on characters.&lt;/p&gt; &lt;p&gt;The send thread is actually quite simple. All it does is block on an event that was created when CeChat was started. When the event is signaled, it reads the text from the send text edit control and calls &lt;i&gt;WriteFile&lt;/i&gt;. Once that has completed, the send thread clears the text from the edit control and loops back to where it blocks again.&lt;/p&gt; The serial API provides applications with a hardware agnostic method of accessing the serial hardware. But how does the operating system know how to talk to the serial hardware? It doesn’t. Instead, the operating system talks to a device driver that hides the specifics of the serial port implementation. Perhaps it’s time to look at how a driver is implemented. In the final chapter of this book, we will look at&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-8668837811402955498?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/8668837811402955498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=8668837811402955498' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8668837811402955498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8668837811402955498'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/cechat-example-program.html' title='The CeChat Example Program'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-1479807503504796146</id><published>2008-07-18T03:29:00.000-07:00</published><updated>2008-07-18T03:30:59.501-07:00</updated><title type='text'>SerialPort (RS-232 Serial COM Port) in C# .NET</title><content type='html'>SerialPort (RS-232 Serial COM Port) in C# .NET&lt;br /&gt;Published 23 March 5 7:28 PM | coad&lt;br /&gt;&lt;br /&gt;This article is about communicating through the PC's Serial COM RS-232 port using Microsoft .NET 2.0 or later by using the System.IO.Ports.SerialPort class.&lt;br /&gt;&lt;br /&gt;Way in the Past...&lt;br /&gt;&lt;br /&gt;Back in my early (pre C# MVP) days, I had written an article on DevHood titled Serial COM Simply in C#. It became quite popular and is (currently) the top Google search for "serial c#". Now every week I get several e-mails with people asking questions and it is high time for some serious updating.&lt;br /&gt;&lt;br /&gt;The article was (originally) written soon after .NET was introduced to the world, and other .NET serial port controls had not yet been written. So at the time, this was an easy solution. Just use the MSComm.ocx control from VS6 which most Devs had at the time. Now however, there are many easier and preferred methods than dealing with the complexities of interoping with an old legacy (non-.NET) ActiveX OCX control.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A Bright Future is Here!&lt;br /&gt;&lt;br /&gt;Today, the primary solution is to use the new SerialPort control that is part of .NET 2.0 and is freely available in C# Express on MSDN. It is considerably easier to use and is a true .NET component.&lt;br /&gt;&lt;br /&gt;Download Button - Small For loyal fans of the tutorial, I've written a sample code application, SerialPortTerminal.zip, which you can try out to see how the new SerialPort control is used. Requires Visual Studio 2005 &amp;amp; .NET 2.0 or later to compile &amp;amp; run.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Continued Support&lt;br /&gt;&lt;br /&gt;Due to the high volume of e-mail I've been receiving on serial port communication in general, I've wrote this post and added an FAQ section to the bottom of the post.  Check this first if you have questions.  If you post a question as a comment that hasn't been answered in the post, I'll add it to the FAQ section.&lt;br /&gt;&lt;br /&gt;For those of you who I've directed to this blog post, please understand that I'm just another guy working away at a full time job (helping manage the release of Team System) who has worked with serial RS-232 ports in the past (moving on to USB now). I like to help people, hence I wrote the original article, this sample code, and the FAQ, but do not have the resources to answer additional serial port communication questions. Please check out the SerialCom FAQ for other .NET COM Port solutions and technical support options.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get Connected Up&lt;br /&gt;&lt;br /&gt;You can obtain USB to Serial adapters (from NewEgg, search using Froogle) and have just about as many ports on your PC as you like. I carry around two adapters with a null modem (what is it?, search Froogle) between them so I can create a loopback to send &amp;amp; receive through to separate ports on most any computer. I'd recommend doing the same for when writing code for the serial port.&lt;br /&gt;&lt;br /&gt;If you'd like to quickly and easily create your own external devices to communicate with the PC, I recommend starting with the Parallax BASIC Stamp modules. Parallax has lots of easy accessories (such as LCDs, RF, Sounds, AD &amp;amp; DA, etc) for their modules. After that you could migrate to an Atmel Microcontroller (recommended) or Microchip PIC.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let's Have the Code&lt;br /&gt;&lt;br /&gt;Here is an example of how easy it is to use the new SerialPort control.&lt;br /&gt;&lt;br /&gt;Very simply, here is how you can send a bit of data out the port.&lt;br /&gt;&lt;br /&gt;// This is a new namespace in .NET 2.0&lt;br /&gt;// that contains the SerialPort class using System.IO.Ports; private static void SendSampleData() { // Instantiate the communications&lt;br /&gt;// port with some basic settings SerialPort port = new SerialPort(&lt;br /&gt;"COM1", 9600, Parity.None, 8, StopBits.One); // Open the port for communications port.Open(); // Write a string port.Write("Hello World"); // Write a set of bytes port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3); // Close the port port.Close(); }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now let's take a look at what it takes to read data in from the communications port. This demonstrates reading text; for an example of reading binary data, see my SerialPortTerminal.zip sample app.&lt;br /&gt;&lt;br /&gt;  1. Create a new "Console Application" and replace all the default class code with this code&lt;br /&gt;  2. Add a reference to "System.Windows.Forms" to the project&lt;br /&gt;  3. Run w/ F5, to exit the app, press Ctrl-Break.&lt;br /&gt;  4. Get Connected Up with two USB to Serial adapters and a null modem&lt;br /&gt;  5. Use another app, the code above, or the SerialPortTerminal.zip example to send data and watch it come in with this code&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#region Namespace Inclusions using System; using System.IO.Ports; using System.Windows.Forms; #endregion namespace SerialPortExample { class SerialPortProgram { // Create the serial port with basic settings private SerialPort port = new SerialPort("COM1",&lt;br /&gt;9600, Parity.None, 8, StopBits.One); [STAThread] static void Main(string[] args) { // Instatiate this class new SerialPortProgram(); } private SerialPortProgram() { Console.WriteLine("Incoming Data:"); // Attach a method to be called when there&lt;br /&gt;// is data waiting in the port's buffer port.DataReceived += new&lt;br /&gt;SerialDataReceivedEventHandler(port_DataReceived); // Begin communications port.Open(); // Enter an application loop to keep this thread alive Application.Run(); } private void port_DataReceived(object sender,&lt;br /&gt;SerialDataReceivedEventArgs e) { // Show all the incoming data in the port's buffer Console.WriteLine(port.ReadExisting()); } } }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One of the (several) new methods that is supported, and one I'm very glad is finally here, is the ability to obtain a list of the COM ports installed on the computer (ex: COM1, COM2, COM4). This is definately helpful when you want to present the list of ports avalible for the user to select from (as in the SerialPortTerminal.zip Win App example).&lt;br /&gt;&lt;br /&gt;foreach (string s in SerialPort.GetPortNames()) System.Diagnostics.Trace.WriteLine(s);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are two helpful little methods for sending files through the serial port. Of course, these are the bare essentials and as always, you should check to make sure the port is open first (port.IsOpen) and use try/catch around trying to open a file, but you get the gist with this code. The binary sending routine is limited to about 2GB (the size of an int), but this should be okay for most uses.&lt;br /&gt;&lt;br /&gt;using System.IO; private static void SendTextFile(&lt;br /&gt;SerialPort port, string FileName) { port.Write(File.OpenText(FileName).ReadToEnd()); } private static void SendBinaryFile(&lt;br /&gt;SerialPort port, string FileName) { using (FileStream fs = File.OpenRead(FileName)) port.Write((new BinaryReader(fs)).ReadBytes(&lt;br /&gt;(int)fs.Length), 0, (int)fs.Length); }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;RS-232 Project Photos&lt;br /&gt;&lt;br /&gt;Each of these involve RS-232 serial port communications.&lt;br /&gt;Just what's needed to get started with microcontrollers,&lt;br /&gt;a Basic Stamp, mini LCD display, power, and RS-232 port.&lt;br /&gt;&lt;br /&gt;Two USB to Serial adapters with a null modem&lt;br /&gt;to loopback and test your serial software.&lt;br /&gt;&lt;br /&gt;The brains to a mini automated radio station that let me&lt;br /&gt;control my PC &amp;amp; home using my HAM radio from around town.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Port Wiring Notes&lt;br /&gt;&lt;br /&gt;DB9 Male (Pin Side)                   DB9 Female (Pin Side)&lt;br /&gt;DB9 Female (Solder Side)              DB9 Male (Solder Side)&lt;br /&gt;   -------------                          -------------&lt;br /&gt;   \ 1 2 3 4 5 /                          \ 5 4 3 2 1 /&lt;br /&gt;    \ 6 7 8 9 /                            \ 9 8 7 6 /&lt;br /&gt;     ---------                              ---------&lt;br /&gt;&lt;br /&gt;DB9 Female to DB9 Female Null-Modem Wiring&lt;br /&gt;2 |  3 |  7 |  8 | 6&amp;amp;1|  5 |  4&lt;br /&gt;---- ---- ---- ---- ---- ---- ----&lt;br /&gt;3 |  2 |  8 |  7 |  4 |  5 | 6&amp;amp;1&lt;br /&gt;&lt;br /&gt;9-pin   25-pin  Assignment                 From PC&lt;br /&gt;------  ------  -------------------------  ------------&lt;br /&gt;Sheild  1       Case Ground                Gnd&lt;br /&gt;1       8       DCD (Data Carrier Detect)  Input&lt;br /&gt;2       3       RX  (Receive Data)         Input&lt;br /&gt;3       2       TX  (Transmit Data)        Output&lt;br /&gt;4       20      DTR (Data Terminal Ready)  Output&lt;br /&gt;5       7       GND (Signal Ground)        Gnd&lt;br /&gt;6       6       DSR (Data Set Ready)       Input&lt;br /&gt;7       4       RTS (Request To Send)      Output&lt;br /&gt;8       5       CTS (Clear To Send)        Input&lt;br /&gt;9       22      RI  (Ring Indicator)       Input&lt;br /&gt;&lt;br /&gt;- RTS &amp;amp; DTR are binary outputs that can be manually set and held&lt;br /&gt;- DCD, DSR, CTS, and RI are binary inputs that can be read&lt;br /&gt;- RX &amp;amp; TX can not be set manually and are controlled by the UART&lt;br /&gt;- maximum voltages are between -15 volts and +15 volts&lt;br /&gt;- binary outputs are between +5 to +15 volts and -5 to -15 volts&lt;br /&gt;- binary inputs are between +3 to +15 volts and -3 to -15 volts&lt;br /&gt;- input voltages between -3 to +3 are undefined while output voltages&lt;br /&gt; between -5 and +5 are undefined&lt;br /&gt;- positive voltages indicate ON or SPACE, negative voltages indicate&lt;br /&gt; OFF or MARK&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Other Resources&lt;br /&gt;&lt;br /&gt;Here are some additional sites, libraries, tutorials, etc. These are links that I just found around the net and am providing for convenience (they are not endorsed).&lt;br /&gt;&lt;br /&gt;   * SerialPort on MSDN&lt;br /&gt;   * Search on Google #1, #2, #3&lt;br /&gt;   * CFSerialIO&lt;br /&gt;   * OpenNETCF Port&lt;br /&gt;&lt;br /&gt;Where CF = Compact Framework&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Final Say (aka Conclusion)&lt;br /&gt;&lt;br /&gt;The new SerialPort class in .NET 2.0 rocks! It is much easier to use than getting the old MSComm.ocx control going in a .NET app, contains new functionality, is a 'native' .NET control, has docs built into the MSDN Library, and is easy to use.&lt;br /&gt;&lt;br /&gt;Frequently Asked Questions (FAQ)&lt;br /&gt;&lt;br /&gt;I'm adding this section (as of 8/10/06) to address the common questions I get on this post and through e-mail.  Chances are, if you ask a good question in the comments here, I'll post it here for others to see easily.&lt;br /&gt;&lt;br /&gt;  1. Q: When updating a control (like a text box) while in the DataRecieved event, I get an error.&lt;br /&gt;     A: The SerialPort class raises events on a separate thread than the main form was create on.  Windows Forms controls must be modified only on their original thread.  Thankfully there is an easy way to do this.  Each Windows control has a "Invoke" method which will run code on the control's original thread.  So to put the recently received data into a text box (txtLog), this would do it:   txtLog.Invoke(new EventHandler(delegate { txtLog.Text += comport.ReadExisting(); });   You can see this more in action in the "Log" event of "Terminal.cs" my sample code project, SerialPortTerminal.zip.&lt;br /&gt;     &lt;br /&gt;  2. Q: I can't find the System.IO.Ports namespace.&lt;br /&gt;     A: Using Visual Studio 2003?  The new namespace, and SerialPort class, is part of .NET 2.0 and Visual Studio 2005.  It is not included in .NET 1.x (and Visual Studio 2003).  Even if you have .NET 2.0 or Visual Studio 2005 installed, you can not access the class from within Visual Studio 2003.&lt;br /&gt;     &lt;br /&gt;  3. Q: I only have .NET 1.1, what can I do?&lt;br /&gt;     A: Upgrade to .NET 2.0.  Seriously, it's free.  In fact, you can get the great C# and VB Visual Studio Interactive Development Environment (IDE) editors for FREE now with C# Express and VB Express.  The .NET 2.0 Software Development Kit (SDK) for command-line development is also free.  If you really must stay in .NET 1.1, you can use the technique I talk about in Serial COM Simply in C# or a 3rd party library.&lt;br /&gt;     &lt;br /&gt;  4. Q: I'm sending data to my device, but it is not responding.&lt;br /&gt;     A: First make sure the device will respond using a standard app like Hyperterminal.  Check the settings (baud rate, data bits, stop bits, etc) and make sure they match with your code.  Try sending binary data via binary arrays.  Many devices expect a carriage return at the end of a command, so be sure to send 0x0D or \n.  String data can be easily converted to a binary array using:&lt;br /&gt;     byte[] data = System.Text.ASCIIEncoding.Default.GetBytes("Hello World\n");&lt;br /&gt;     com.Write(data, 0, data.Length);&lt;br /&gt;     Many devices require several carriage returns first to sync baud rates, so send several, like: com.Output("".PadLeft(9, '\n'));  It you're communicating with a modem, make sure Echo Back is turned on.  Send "ATE1\n".  Other than this, just keep trying and playing around with it.  It can be hard because you don't see the response from the device as easily as you would with a terminal app.&lt;br /&gt;     &lt;br /&gt;  5. Q: When I put received data to a text box or rich text box, I get a strange symbols.&lt;br /&gt;     A: The default font of text boxes is designed only to show standard characters.  Try using "CharMap" (a free tool in WinXP, click "Start", "Run", type "CharMap", enter).  "Terminal" is a font designed to show classic ASCII characters and is what most terminal apps (like my sample code and Hyperterminal) use.  There are also many ASCII codes that won't display correctly.  This is why I choose to show the hex data instead of an ASCII string a lot of the time.  System.Convert.ToString(mybyte, 16) will convert a byte to a string hex code, for example: byte b = 13; string s = Convert.ToStrong(b, 16).PadLeft(2, '0'), then s will contain "0D".  See the "ByteArrayToHexString" and "HexStringToByteArray" methods in my sample app, SerialPortTerminal.zip.&lt;br /&gt;     &lt;br /&gt;  6. Q: What about USB communications?  How can I do USB?&lt;br /&gt;     This post isn't about USB.  Believe me, I wish the .NET framework supported USB natively, and I'm doing what I can here at Microsoft to see USB get into the framework in the future.  For now, you can use a USB to Serial adapter.  I use a lot of these.  They plug into the USB port, then appear just as a SerialPort to the PC.  Microcontroller vendors such as Microchip, Atmel, and TI make chips that do this for projects.  There is a lot of info on USB and C# out there too (such as this great article).&lt;br /&gt;     &lt;br /&gt;  7. Q: Can I use the sample code here in my own projects (commercial or not)?&lt;br /&gt;     Yes!  All sample code on my blog is free public domain material.  I'm not a legal guy so I don't know the exact words to use, but I'll try...  I'm not responsible for any problems!  Use at your own rick etc.  However, have at it, if it helps you out, fantastic, that's what it's here for.&lt;br /&gt;     &lt;br /&gt;  8. Q: When using SerialPort.Open() (or SerialPort.PortOpen = true) I get the exception "UnauthorizedAccessException" or the error "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in axinterop.mscommlib.dll"&lt;br /&gt;     It may be one of a few factors:&lt;br /&gt;         * It may require Administrative privileges to use the port.&lt;br /&gt;         * The port may already be open by another program, only one app can use a port at a time.&lt;br /&gt;         * The port may not exist on the computer (this happens a lot).  Verify the port you're trying to open is listed in the Device Manager (FAQ #9).&lt;br /&gt;         * The name being provided is not exactly correct.&lt;br /&gt;           Use the full name of the port when opening, like "COM1" (not "1")&lt;br /&gt;  9. Q: How do I know what COM ports are on my PC?&lt;br /&gt;     Use the Device Manager ("Start", "Run", "devmgmt.msc") and look for the "Ports" node (see below).  If you don't see a Ports node, it's because there are not Serial or Parallel ports installed in the PC.  Many laptops these day's don't have a serial port.  You can get more serial ports very easily today with USB to Serial adapters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;br /&gt; 10. Q: How do I communicate with my specific device?  Modem, Mobile Phone, LED/LCD Display, Scanner, etc&lt;br /&gt;     This post is specific to general, device independent, serial port communications.  You will need to find information about the protocol used for your specific device elsewhere.  Comments that ask about specific devices will be deleted (to reduce spam).  I'd recommend looking on the manufacture's website, writing/calling the manufacture, or searching online for your specific device, like "Motorola Razor Serial Protocol".&lt;br /&gt;     &lt;br /&gt; 11. Q: What pins can I use for powering devices, a high signal, or for boolean input &amp;amp; output?&lt;br /&gt;     The TX &amp;amp; RX pins carry the standard serial signal, but the other pins can be used as high/low input/output pins.  The output pins (4 DTR or 8 CTS), supply 5 to 15 volts (15v is proper RS-232 standard) when high and 0 to -15 volts when low.  They only supply flea current so they're not meant to be used for powering any devices (like USB is designed for).  However, they can be used as a reference voltage or for switching to one of the input pins for a high or low signal.  The input pins (1 DCD, 6 DSR, 8 CTS, and 9 RI) can be used to detect a high or low signal.  Proper RS-232 signal levels are -15v for a low and +15v for a high (compared to ground, pin 5).  A MAX232 or similar chip takes a TTL 0-5v input and produces the -15v to +15v levels.  However, most PC RS-232 COM ports will accept a 0v for low and 5v for high, but it is not guaranteed and alters from PC to PC.  If you want a simple "toggle high", just hold pin 4 DTR high, and switch it to pin 1 DCD.  The .NET SerialPort class has easy to use properties for switching the output pins high or low and for detecting the current level of the input pins.  I have been able to use pin 4 DTR for a very low current (20ma max) PIC processors, but not reliably.  I prefer to always supply external power and use pin 4 as a signal to turn on or off my device.  I'll attach pin 4 to a transistor that switches my power source to my PIC to turn it on or off.&lt;br /&gt;     &lt;br /&gt; 12. Q: What about ‘packets’?  Does RS-232 support any commands or data segregation?&lt;br /&gt;     No.  Serial data flow through RS-232 has nothing to do with ‘packets’. It’s just a stream of bytes in and out. Any notion of data compartmentalization (packets) would have to be coded by you for your unique use.  Much of my time working with serial has been spent on defining useful packet like protocols, that usually include some type of header, command structure, and CRC check.  For example, the first two bytes are the packet length, the next two bytes is the command, next two bytes are parameters, and the last byte is a CRC.  Then my apps would buffer incoming data and look in the buffer for valid packets.  Of course it differs depending on the device you’re working with and your specific needs.  USB does have specific communications protocol defined, one of them being command based, like the little packet just mentioned.  But with USB, you’re able to get the whole command and parameter together at once, with serial you have to create the protocol yourself, buffer, and parse the data.  My previous serial post has more info under the header “Protocol Development”.&lt;br /&gt;     &lt;br /&gt; 13. Q: How do you detect when a device is connected or disconnected?&lt;br /&gt;     Simply put, the device usually start or stop sending data.  There is no built in events on a connect or disconnect.  But there are a few tricks you can do, if you’re creating the serial device you have more options.  I’ve had my devices (and PC apps) send a constant “are you there” set of bytes, like 00 00 11 11 00 00 hex (I’d use a ‘are you there’ custom ‘packet’ as in Q12 above) till a device on the other end responds.  You could also use hardware, that’s what some of the other signals lines are for (CDC, DSR, RTS, CTS, RI), you can tie one of these high and then catch an event when the line goes high you know there’s a device there, when it goes low the device is gone.&lt;br /&gt;     &lt;br /&gt; 14. Q: How can I get more support?  What are my support options?&lt;br /&gt;         * Read this FAQ section!  :)&lt;br /&gt;         * You can try leaving a comment below.  Perhaps someone knows the answer&lt;br /&gt;         * Try doing a search and look for other content.  "SerialPort C#", "Serial Com C#", "serial port .net"&lt;br /&gt;         * Post a question in the .NET Base Class Library in MSDN Forums&lt;br /&gt;&lt;br /&gt;Filed under: C#&lt;br /&gt;Comments&lt;br /&gt;&lt;br /&gt;# coad said on March 27, 2005 5:28 PM:&lt;br /&gt;&lt;br /&gt;   Nice!&lt;br /&gt;   And for devs searching for rs232 for the Compact Framework feel free to come here:&lt;br /&gt;   http://www.danielmoth.com/Blog/2004/09/serial-rs232-communications-in-net.html&lt;br /&gt;# coad said on April 24, 2005 10:29 PM:&lt;br /&gt;&lt;br /&gt;   Cool stuff.&lt;br /&gt;# coad said on May 4, 2005 1:30 AM:&lt;br /&gt;&lt;br /&gt;   hey&lt;br /&gt;&lt;br /&gt;   i cant find the name space&lt;br /&gt;   using System.IO.Ports&lt;br /&gt;   there is nothing like Ports.&lt;br /&gt;   i'm using Visual Studio.net 2003&lt;br /&gt;   Please help me urgently&lt;br /&gt;   my email ID is arun5_appu@yahoo.com&lt;br /&gt;# coad said on May 5, 2005 8:54 AM:&lt;br /&gt;&lt;br /&gt;   &gt;I cant find the name space&lt;br /&gt;&lt;br /&gt;   Check this phrase near the start of this posting:&lt;br /&gt;&lt;br /&gt;   "the new SerialPort control that is part of .NET 2.0 (currently in Beta)"&lt;br /&gt;# coad said on June 6, 2005 12:45 AM:&lt;br /&gt;&lt;br /&gt;   Hi,&lt;br /&gt;&lt;br /&gt;   I really thank you for being the only mangaed .Net source of seial comm.:)&lt;br /&gt;   I have .Net 2.0 Beta installed. And can compile your hello world! example. But when it tries to Open the port. Exception says there is no COM1 port.&lt;br /&gt;&lt;br /&gt;   Any Comments !&lt;br /&gt;# coad said on June 6, 2005 12:57 AM:&lt;br /&gt;&lt;br /&gt;   You may not have a COM1 installed on your system, or it may already be in use.&lt;br /&gt;# coad said on June 8, 2005 3:07 PM:&lt;br /&gt;&lt;br /&gt;   Nice Article..quite informative&lt;br /&gt;# coad said on June 8, 2005 3:13 PM:&lt;br /&gt;&lt;br /&gt;   if I set the port.ReceivedBytesThreshold to 5 would the following event&lt;br /&gt;   port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);&lt;br /&gt;   be called after there is 5 bytes in the buffer...&lt;br /&gt;&lt;br /&gt;   Also can you show how to use port.Read(buff,0,5) where buff is defined as&lt;br /&gt;&lt;br /&gt;   byte buff = new byte[5];&lt;br /&gt;&lt;br /&gt;   I am calling the port.Read function after the event is called 5 times to make sure there are 5 bytes in the buffer but still it doesn't work.&lt;br /&gt;# coad said on June 8, 2005 11:09 PM:&lt;br /&gt;&lt;br /&gt;   The method's parameters are port.Read(byte[], int, int), so the first parameter is a byte array (byte[]). Try: byte[] buf = new byte[5];&lt;br /&gt;&lt;br /&gt;   But I don't recommend reading a fixed # of bytes if possible since it is very easy to get one or two bytes off in the incoming buffer and hence not receive the data when expected or get unexpected results.&lt;br /&gt;&lt;br /&gt;   This is much preferred since it handles any amount of incoming data. Just process what ends up in the PortBuffer and remember to clean it out from time to time to prevent memory creep.&lt;br /&gt;&lt;br /&gt;   private List&lt;byte&gt; PortBuffer = new List&lt;byte&gt;();&lt;br /&gt;&lt;br /&gt;   private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;   {&lt;br /&gt;   SerialPort port = (SerialPort)sender;&lt;br /&gt;&lt;br /&gt;   byte[] data = new byte[port.BytesToRead];&lt;br /&gt;&lt;br /&gt;   port.Read(data, 0, data.Length);&lt;br /&gt;&lt;br /&gt;   PortBuffer.AddRange(data);&lt;br /&gt;&lt;br /&gt;   ProcessIncomingData(PortBuffer);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void ProcessIncomingData(List&lt;byte&gt; PortBuffer)&lt;br /&gt;   {&lt;br /&gt;   // Search through the bytes to find the data you want&lt;br /&gt;   // then remove the data from the list. It is good to&lt;br /&gt;   // clean up unused bytes (usually everything before&lt;br /&gt;   // what you're looking for)&lt;br /&gt;   }&lt;br /&gt;# coad said on June 9, 2005 9:55 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for your help man....&lt;br /&gt;&lt;br /&gt;   One question.... I have data coming through bus in sets of 5 bytes at a time at very high speeds...about 1.5ms delay. Is there anyway I can force the program to call SerialDataReceivedEventHandler after it gets 5 bytes of data.... by setting port.ReceivedBytesThreshold to 5 do it????&lt;br /&gt;# coad said on June 9, 2005 1:51 PM:&lt;br /&gt;&lt;br /&gt;   I'd suppose so, have you tried it? I use the technique above so I've never tried triggering the event on x # of bytes. The purpose of changing the ReceivedBytesThreshold is not to capture little 'packets' like that, but to reduce the # of times the method is called if large amounts of data are streaming in.&lt;br /&gt;# coad said on June 10, 2005 4:53 AM:&lt;br /&gt;&lt;br /&gt;   i cant find the name space&lt;br /&gt;   "System.IO.Ports"&lt;br /&gt;   i'm using Visual Studio.net 2003&lt;br /&gt;   Please help me, its urgent&lt;br /&gt;   my email ID is kapildvyas@yahoo.co.in&lt;br /&gt;# coad said on June 10, 2005 11:51 AM:&lt;br /&gt;&lt;br /&gt;   thanks Noah... I'll try it if doesn't work i'll try the othe way ...&lt;br /&gt;&lt;br /&gt;   Kapil system.io.ports comes with visual studio 2005 beta version.&lt;br /&gt;# coad said on June 11, 2005 6:24 PM:&lt;br /&gt;&lt;br /&gt;   I guess any client applications will need to upgrade to .net2.0 ? I am skeptical about this as .net is still in .net.&lt;br /&gt;&lt;br /&gt;   Can any one share any experience about this.&lt;br /&gt;&lt;br /&gt;   Seshagiri&lt;br /&gt;# coad said on June 14, 2005 2:55 PM:&lt;br /&gt;&lt;br /&gt;   What I was thinking was would client applications need to install .net 2.0 if I used the new feature in my application. If it is so, in that case is it recommendable as .net 2.0 is still in beta stage and there could be compatibility issues with the final release.&lt;br /&gt;&lt;br /&gt;   Seshagiri&lt;br /&gt;# coad said on June 14, 2005 5:50 PM:&lt;br /&gt;&lt;br /&gt;   Seshagiri: Yes, clients must be running .NET 2.0. The deployment version from Beta2 will be different than that for RTM. VS05 Beta2 is not for public release yet, that's for when the product is finalized and released to market the second week of November. In the mean time, it is for testing and deployment to select targets (w/ a Go Live licence, see MSDN).&lt;br /&gt;# coad said on June 21, 2005 10:31 AM:&lt;br /&gt;&lt;br /&gt;   Hi Noah!&lt;br /&gt;&lt;br /&gt;   I'm trying to send a simple "ati4" command to a modem and receive its response, but all I get back is whatever ati command I send.&lt;br /&gt;&lt;br /&gt;   If I Send: ati4&lt;br /&gt;&lt;br /&gt;   I Expect To Get Back:&lt;br /&gt;   USRobotics Sportster 28800 V.34 Fax Settings...&lt;br /&gt;&lt;br /&gt;   B0 E1 F1 M1 Q0 V1 X4 Y0&lt;br /&gt;   BAUD=38400 PARITY=N WORDLEN=8&lt;br /&gt;   DIAL=PULSE ON HOOK, etc..&lt;br /&gt;&lt;br /&gt;   But Instead I Get Back: ati4&lt;br /&gt;&lt;br /&gt;   I've tried both my own test application as well as the one you created. Any ideas? Thanks so much!&lt;br /&gt;# coad said on June 22, 2005 9:34 AM:&lt;br /&gt;&lt;br /&gt;   Update&lt;br /&gt;   ------&lt;br /&gt;   Hi Noah!&lt;br /&gt;&lt;br /&gt;   After further debugging, I observe that the port_DataReceived function in your SerialPort Terminal example is never being called. I see the function being added as an EventHandler earlier:&lt;br /&gt;&lt;br /&gt;   comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);&lt;br /&gt;&lt;br /&gt;   I can't figure for the life of me why it's never reaching the function though. All I know is this is why, for example, I only receive an echo of my "at" command and not the actual "ok" response I'm expecting. I didnt change any of the code, so why would this be happening?&lt;br /&gt;&lt;br /&gt;   Cheers!&lt;br /&gt;# coad said on July 7, 2005 11:30 PM:&lt;br /&gt;&lt;br /&gt;   This is a reply to 'Nathan Ie' question about the ATI4 question.&lt;br /&gt;&lt;br /&gt;   I had the same problem and found out, that if you use WriteLine() method to write the "ATI4" string it will echo the sting back.&lt;br /&gt;&lt;br /&gt;   You have to use the Write() method and specify the file feed "\r". If you call method Write("ATI4\r") you will get the expected result. You can also change the SerialPort.NewLine Property from "\r\n" to "\r" to make it work.&lt;br /&gt;&lt;br /&gt;   Hope that helped&lt;br /&gt;# coad said on July 8, 2005 5:23 PM:&lt;br /&gt;&lt;br /&gt;   when i do "port.Open()", it says&lt;br /&gt;&lt;br /&gt;   UnauthorizedAccessException was unhandled.&lt;br /&gt;   Access to the port "COM1" is denied.&lt;br /&gt;   Make sure you have sufficient privileges to access this resource&lt;br /&gt;&lt;br /&gt;   I just put your code segment into a button1_Click handler. What should I do to make it work?&lt;br /&gt;# coad said on July 8, 2005 5:44 PM:&lt;br /&gt;&lt;br /&gt;   Actually nevermind my previous post, i solved the problem. But i have a new question :)&lt;br /&gt;&lt;br /&gt;   How can I manually send bit signals to RTS &amp;amp; DTR?&lt;br /&gt;&lt;br /&gt;   I need to send something like "0110000011010000" to RTS and at the same time (synchronized) send its logic inverses to DTR.&lt;br /&gt;&lt;br /&gt;   I am a student from university of toronto and very new to serial programming. please help me!!&lt;br /&gt;# coad said on July 12, 2005 2:05 PM:&lt;br /&gt;&lt;br /&gt;   I run your program on my desktop (Windows XP Professional with SP2 and Visual Studio.NET 2005 Beta 2), the port can't be opened. The IDE said that "Access to the port 'COM1' is denied." It is UnauthorizedAccessException. Please tell me how to solve the problem? Thank you very much!&lt;br /&gt;# coad said on July 12, 2005 2:49 PM:&lt;br /&gt;&lt;br /&gt;   The port may not exist on your computer or may be in use by another application (like for a modem). Change "COM1" in the code to another port, like "COM2" and try that. You can also check to see what ports are avalible on your machine through the Device Manager (press Windows-Break, "Hardware" tab, "Device Manager" button, "Ports (COM &amp;amp; LPT)" node).&lt;br /&gt;# coad said on July 14, 2005 11:34 AM:&lt;br /&gt;&lt;br /&gt;   You are right. I install ActiveSyn 4.0 which uses COM1. After I delete it, the program works very well. I have another question. I modify you program in DataReceive event handler:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;   {&lt;br /&gt;   int intBytes = serialPort.BytesToRead;&lt;br /&gt;   byte[] bytes = new byte[intBytes];&lt;br /&gt;   serialPort.Read(bytes, 0, intBytes);&lt;br /&gt;&lt;br /&gt;   tbReceive.Text += intBytes.ToString() + ";";&lt;br /&gt;   }&lt;br /&gt;   The tbReceive is a TextBox control. When the program excutes at the last line,&lt;br /&gt;&lt;br /&gt;   tbReceive.Text += intBytes.ToString() + ";";&lt;br /&gt;&lt;br /&gt;   there is an exception, System.InvalidOperationException was unhandled. The error message is "Cross-thread operation not valid: Control 'tbReceive' accessed from a thread other than the thread it was created on." Please tell me what's reason and how to solve it. Thanks!&lt;br /&gt;&lt;br /&gt;# coad said on July 16, 2005 9:40 AM:&lt;br /&gt;&lt;br /&gt;   Hi Charlie!&lt;br /&gt;&lt;br /&gt;   int intBytes;&lt;br /&gt;   void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;   {&lt;br /&gt;   intBytes = serialPort.BytesToRead;&lt;br /&gt;   byte[] bytes = new byte[intBytes];&lt;br /&gt;   serialPort.Read(bytes, 0, intBytes);&lt;br /&gt;&lt;br /&gt;   this.Invoke(new EventHandler(SetText));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;   void SetText()&lt;br /&gt;   {&lt;br /&gt;   tbReceive.Text += intBytes.ToString() + ";";&lt;br /&gt;   }&lt;br /&gt;# coad said on July 25, 2005 5:40 PM:&lt;br /&gt;&lt;br /&gt;   Hi Noah,&lt;br /&gt;&lt;br /&gt;   I read your article on System.IO.Ports.SerialPort class of new&lt;br /&gt;   C# Express. I tried to achieve a basic communication between my pc and the lab instrument with the following code:&lt;br /&gt;&lt;br /&gt;   After the usual port initialization,&lt;br /&gt;&lt;br /&gt;   if (com.IsOpen) com.Close();&lt;br /&gt;   com.Open();&lt;br /&gt;&lt;br /&gt;   // send char 34,14,192,51,0,0&lt;br /&gt;   com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51, (char)0, (char)0 }, 0, 6));&lt;br /&gt;&lt;br /&gt;   // for testing purposes I connected TX and RX pins of the port...&lt;br /&gt;&lt;br /&gt;   // receive routine:&lt;br /&gt;   private void com_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // This method will be called when there is data waiting in the port's buffer&lt;br /&gt;&lt;br /&gt;   // Obtain the number of bytes waiting in the port's buffer&lt;br /&gt;   bytes = com.BytesToRead;&lt;br /&gt;&lt;br /&gt;   // Create a byte array buffer to hold the incoming data&lt;br /&gt;   buffer = new char[bytes];&lt;br /&gt;&lt;br /&gt;   // Read the data from the port and store it in our buffer&lt;br /&gt;   com.Read(buffer, 0, bytes);&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   After I activate the send routine, 6 bytes of data is received by pc but with some difference to the originally sent data.&lt;br /&gt;&lt;br /&gt;   I receive : 34,14,63,51,0,0 everytime instead of 34,14,192,51,0,0&lt;br /&gt;&lt;br /&gt;   I tried to transmit 34,14,127,51,0,0 and received the same data sequence...&lt;br /&gt;&lt;br /&gt;   As I try to tranmit anything bigger than 127 I receive 63 instead of the original data...&lt;br /&gt;&lt;br /&gt;   Do you have any idea why this is happening consistently?&lt;br /&gt;&lt;br /&gt;   Regards,&lt;br /&gt;   Haluk Gokmen&lt;br /&gt;# coad said on July 25, 2005 10:47 PM:&lt;br /&gt;&lt;br /&gt;   Haluk: Have you tried using a byte array instead of a character array?&lt;br /&gt;   byte[] buffer = new byte[com.BytesToRead];&lt;br /&gt;# coad said on July 25, 2005 10:53 PM:&lt;br /&gt;&lt;br /&gt;   Green,&lt;br /&gt;   Thanks for the update to charlie's post. The reason for this is that WinForms controls' properties must be modified on the same thread that they were created on. By using this.Invoke (where "this" is the form the control is on), it asks the form to run another method on the same thread the form is on. serialPort_DataReceived could be triggered at anytime (not just when the form is avalible) since the SerialPort control runs outside of the form's thread. This is a big advantage in that it will always be responsive to incoming serial data even if the form is busy with an intensive redraw or update.&lt;br /&gt;# coad said on July 26, 2005 2:44 AM:&lt;br /&gt;&lt;br /&gt;   Dear Noah,&lt;br /&gt;   I tried byte array on the receiving side without a difference on the result.&lt;br /&gt;&lt;br /&gt;   I was succeding on a similar operation in VS.NET by utilizing MSComm OCX as suggested in your article at www.devhood.com/tutorials/ tutorial_details.aspx?tutorial_id=320&lt;br /&gt;   The following is the code:&lt;br /&gt;&lt;br /&gt;   private byte[] recdata = new byte[40]; //received data array&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   public void InitComPort()&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;   // Set the com port to be 1&lt;br /&gt;   com.CommPort = 1;&lt;br /&gt;&lt;br /&gt;   // This port is already open, close it to reset it.&lt;br /&gt;   if (com.PortOpen) com.PortOpen = false;&lt;br /&gt;&lt;br /&gt;   // Trigger the OnComm event whenever data is received&lt;br /&gt;   // Loop based receieve activated...&lt;br /&gt;   com.RThreshold = 0;&lt;br /&gt;&lt;br /&gt;   // Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)&lt;br /&gt;   com.Settings = "9600,n,8,1";&lt;br /&gt;&lt;br /&gt;   // Force the DTR line high, used sometimes to hang up modems&lt;br /&gt;   com.DTREnable = true;&lt;br /&gt;&lt;br /&gt;   // No handshaking is used&lt;br /&gt;   com.Handshaking = MSCommLib.HandshakeConstants.comNone;&lt;br /&gt;&lt;br /&gt;   // Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)&lt;br /&gt;   com.InputMode = MSCommLib.InputModeConstants.comInputModeBinary;&lt;br /&gt;&lt;br /&gt;   // Use this line instead for byte array input, best for most communications&lt;br /&gt;   //com.InputMode = MSCommLib.InputModeConstants.comInputModeText;&lt;br /&gt;&lt;br /&gt;   // Read the entire waiting data when com.Input is used&lt;br /&gt;   com.InputLen = 0;&lt;br /&gt;&lt;br /&gt;   // Don't discard nulls, 0x00 is a useful byte&lt;br /&gt;   com.NullDiscard = false;&lt;br /&gt;&lt;br /&gt;   // Open the com port&lt;br /&gt;   com.PortOpen = true;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void cmdRead_Start_Click(object sender, System.EventArgs e)&lt;br /&gt;   {&lt;br /&gt;   long TimeStamp = DateTime.Now.Ticks; // Time Stamp for Time-out&lt;br /&gt;   bool ElapsedTime;&lt;br /&gt;&lt;br /&gt;   com.Output = new string(new char[]{(char) 34, (char) 14, (char) 192, (char) 51, (char) 0, (char) 0});&lt;br /&gt;&lt;br /&gt;   // collect data during the first one second period...&lt;br /&gt;   do&lt;br /&gt;   {&lt;br /&gt;   // Dont lock up the entire application&lt;br /&gt;   // release control to process other messages.&lt;br /&gt;   System.Windows.Forms.Application.DoEvents();&lt;br /&gt;&lt;br /&gt;   // If there is data waiting, buffer it in our own byte array...&lt;br /&gt;   if (com.InBufferCount &gt;= 34) recdata = (byte[])com.Input;&lt;br /&gt;&lt;br /&gt;   // Look for the Elapsed Time&lt;br /&gt;   ElapsedTime = DateTime.Now.Ticks - TimeStamp &gt; TimeSpan.TicksPerSecond * 1;&lt;br /&gt;&lt;br /&gt;   // Keep waiting for 1 second before processing incoming data stream...&lt;br /&gt;   }&lt;br /&gt;   while (!ElapsedTime);&lt;br /&gt;&lt;br /&gt;   Global.samplescounter = recdata[27] * 100 + recdata[26];&lt;br /&gt;   lblRead_RecordNo.Text = Global.samplescounter.ToString();&lt;br /&gt;   .&lt;br /&gt;   .&lt;br /&gt;   .&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   My instrumentation which is target to this communication action is responding to data sent in char format. It doesnt respond to byte arrays.&lt;br /&gt;   This previous code is still working but I cant get the new one working.&lt;br /&gt;   Regards..&lt;br /&gt;# coad said on July 27, 2005 7:50 AM:&lt;br /&gt;&lt;br /&gt;   Briefly, I would like to transmit Unicode 192 (u\192) from the serial port and read it back again. How can I do this in C# 2005 Express?&lt;br /&gt;# coad said on July 28, 2005 9:52 PM:&lt;br /&gt;&lt;br /&gt;   You're right.. it's much easier!&lt;br /&gt;&lt;br /&gt;   but i have a little problem&lt;br /&gt;&lt;br /&gt;   I get this from the serial port:&lt;br /&gt;&lt;br /&gt;   U001W1 N 1,852 kg&lt;br /&gt;   U001W1 N 1,852 kg&lt;br /&gt;   U001W1 N 1,852 kg&lt;br /&gt;   U001W1 N 1,852 kg&lt;br /&gt;   U001W1 N 1,852 kg&lt;br /&gt;&lt;br /&gt;   How can i fix it, that i just geht the "1,852" from it?&lt;br /&gt;&lt;br /&gt;   thanxx&lt;br /&gt;# coad said on July 29, 2005 4:59 PM:&lt;br /&gt;&lt;br /&gt;   Hello Noah and every visitor. Thanks for the great introduction to the SerialPort.&lt;br /&gt;   I have written a simple code, and to test i have used a cross over cable from COM1 to COM2. If I run 2 instances of the code on the 2 ports it works (send and receive) perfectly. But if I use Hyper Terminal on one end (say for example Hyper terminal on COM2 and my code on COM1) my code can send and hyper terminal receives it but if hyper terminal sends my code do not see anything. The same thing happended when i used your sample code. But of course when i test two instances of hyper terminal can eailty talk to each other.&lt;br /&gt;   What am I missing here?&lt;br /&gt;# coad said on August 1, 2005 2:59 AM:&lt;br /&gt;&lt;br /&gt;   How do you set serial port encoding?&lt;br /&gt;# coad said on August 1, 2005 9:46 AM:&lt;br /&gt;&lt;br /&gt;   Haluk,&lt;br /&gt;   Try using the SerialPort.Encoding property. For example: port.Encoding = System.Text.Encoding.UTF8;&lt;br /&gt;# coad said on August 4, 2005 6:52 AM:&lt;br /&gt;&lt;br /&gt;   Great intro maan.&lt;br /&gt;&lt;br /&gt;   I tried reading from COM1 using VB.NET (2005 beta 2). I am not able to get the DataReceived event to get triggered. The data from a connected scale transmits whenever its weight is stable.&lt;br /&gt;&lt;br /&gt;   I coded this in a form. Does it have to be a console application instead ?&lt;br /&gt;   I am using ReadExisting(). Do you need to use ReadByte() ? If yes, does that code need to be in a thread to avoid sync/no-timeout ?&lt;br /&gt;&lt;br /&gt;   Thanks for any advice.&lt;br /&gt;# coad said on September 1, 2005 7:42 AM:&lt;br /&gt;&lt;br /&gt;   I have written a program that sends commands to and receives the responses from a serial device. This work normaly. However the device is also outputing data every .x seconds. I am having a very difficult time receiving this data and getting it onto my form. Your suggestions and advice are greatly appreciated.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Write.Click&lt;br /&gt;&lt;br /&gt;   Dim gxTXDBuffer As String&lt;br /&gt;   Dim sInput As String&lt;br /&gt;&lt;br /&gt;   Dim lTimeout As Long&lt;br /&gt;   Dim Time As Long&lt;br /&gt;&lt;br /&gt;   'clear input buffer counter&lt;br /&gt;   AxMSComm1.InBufferCount = 0&lt;br /&gt;&lt;br /&gt;   'setup command to send&lt;br /&gt;   gxTXDBuffer = sendtext.Text &amp;amp; Chr(10)&lt;br /&gt;&lt;br /&gt;   'send command&lt;br /&gt;   AxMSComm1.Output = gxTXDBuffer&lt;br /&gt;&lt;br /&gt;   '-----------------------------------------------------------------------&lt;br /&gt;   'not sure how to get data when counting&lt;br /&gt;   '&lt;br /&gt;   'While sendtext.Text = "C"&lt;br /&gt;   ' Microsoft.VisualBasic.Timer &gt; lTimeout&lt;br /&gt;   '&lt;br /&gt;   'read in response&lt;br /&gt;   'sInput = AxMSComm1.Input&lt;br /&gt;   ' receivetext.Text = sInput&lt;br /&gt;   ' End While&lt;br /&gt;   '-----------------------------------------------------------&lt;br /&gt;&lt;br /&gt;   'wait for response or timeout&lt;br /&gt;   lTimeout = Microsoft.VisualBasic.Timer + 5&lt;br /&gt;&lt;br /&gt;   Do&lt;br /&gt;   Application.DoEvents()&lt;br /&gt;&lt;br /&gt;   Loop Until AxMSComm1.InBufferCount &gt;= 8 Or Microsoft.VisualBasic.Timer &gt; lTimeout&lt;br /&gt;   '&lt;br /&gt;   'read in response&lt;br /&gt;   sInput = AxMSComm1.Input&lt;br /&gt;   receivetext.Text = sInput&lt;br /&gt;&lt;br /&gt;   End Sub&lt;br /&gt;   'another attempt at reading counts when com event&lt;br /&gt;   '&lt;br /&gt;   ' Private Sub AxMSComm1_OnComm()&lt;br /&gt;   ' Dim sInput As String&lt;br /&gt;   ' commevent 2 = Received RThreshold number of characters. This event is generated continuously&lt;br /&gt;   ' until you use the Input property to remove the data from the receive buffer.&lt;br /&gt;   ' If AxMSComm1.CommEvent() = 2 And AxMSComm1.InBufferCount &gt; 0 Then&lt;br /&gt;   ' sInput = AxMSComm1.Input&lt;br /&gt;   ' ' receivetext.Text = sInput&lt;br /&gt;   ' End If&lt;br /&gt;   '' End Sub&lt;br /&gt;# coad said on September 1, 2005 10:23 PM:&lt;br /&gt;&lt;br /&gt;   How do you program the Basic Stamp to output a string that you sent from your PC?&lt;br /&gt;&lt;br /&gt;   Anyone can help?&lt;br /&gt;&lt;br /&gt;   Thanks!!!&lt;br /&gt;# coad said on September 5, 2005 10:59 PM:&lt;br /&gt;&lt;br /&gt;   I am using VS.Net 2003, Actually i ve to do hardware interface in which i need to recieve data and plot it as graph and save it in database. Can anyone help me out...&lt;br /&gt;   Thanks&lt;br /&gt;# coad said on September 8, 2005 3:55 PM:&lt;br /&gt;&lt;br /&gt;   Hi All,&lt;br /&gt;&lt;br /&gt;   I have the following problem:&lt;br /&gt;&lt;br /&gt;   After sending a Write command to a device, directly followed by a Read command it seems that the data on the device is not yet available.&lt;br /&gt;&lt;br /&gt;   It seems that the write/read part is too fast for the device to 'generate' the data.&lt;br /&gt;&lt;br /&gt;   The baudrate is 9600 and cannot be higher. Also i would not like to add a pause.&lt;br /&gt;&lt;br /&gt;   Does anyone have a solution here ?&lt;br /&gt;&lt;br /&gt;   Thanx,&lt;br /&gt;&lt;br /&gt;   Jan&lt;br /&gt;# coad said on September 14, 2005 12:59 AM:&lt;br /&gt;&lt;br /&gt;   What about the Timer in windows forms, for data arriving at any time and various durations?&lt;br /&gt;   does firing an event during reading current event would cause problems?&lt;br /&gt;&lt;br /&gt;   thanks for your efforts&lt;br /&gt;&lt;br /&gt;   thanks,&lt;br /&gt;&lt;br /&gt;   elwolv&lt;br /&gt;# TrackBack said on September 25, 2005 1:55 AM:&lt;br /&gt;&lt;br /&gt;# coad said on September 26, 2005 6:26 AM:&lt;br /&gt;&lt;br /&gt;   Hi All,&lt;br /&gt;&lt;br /&gt;   Noha - a great article!&lt;br /&gt;&lt;br /&gt;   For some reason I'm not reaching the 'port_DataReceived' function. Any ideas why?&lt;br /&gt;   I'm running the 'SerialPortTerminal' application on my computer with the 'Portmon' application monitoring all data at the serial port so nothing is physically connected to the COM. May this be the reason?&lt;br /&gt;&lt;br /&gt;   Thanks for your help.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Elad&lt;br /&gt;# coad said on October 12, 2005 3:27 AM:&lt;br /&gt;&lt;br /&gt;   Hi there,&lt;br /&gt;&lt;br /&gt;   Your article is awesome and the information is so great and very useful.&lt;br /&gt;&lt;br /&gt;   However, I have a problem when I tried to write a software to communicate to bluetooth ports(COM4 and COM7) in PDA. The .NET 2.0 does not provide a platform for mobile device.&lt;br /&gt;&lt;br /&gt;   Suggestions please.&lt;br /&gt;&lt;br /&gt;   Thanks a lot,&lt;br /&gt;   Ikkyusan ;)&lt;br /&gt;# coad said on October 17, 2005 8:53 PM:&lt;br /&gt;&lt;br /&gt;   Ikkyusan:&lt;br /&gt;   The .NET Compact Framework does not have built in support for serial communications. There are many third-party controls available. Try a Google search like:&lt;br /&gt;   http://www.google.com/search?hl=en&amp;amp;q=serial+com+compact+framework&lt;br /&gt;# coad said on October 28, 2005 3:07 PM:&lt;br /&gt;&lt;br /&gt;   This is an awesome and extremely useful article! My one suggestion is that you add some minor clarifications on the DtrEnable property. I'm connecting to an Ultra 5 Sun box and was having a lot of troubles with my commands just getting echoed back to me. Setting the DtrEnable = true solved that problem. My understanding is that it tells the serial port that you're talking from one data transmitter to another data transmitter.&lt;br /&gt;# coad said on November 12, 2005 10:21 AM:&lt;br /&gt;&lt;br /&gt;   Im trying to contact my sony wavehawk scanner with.&lt;br /&gt;   port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);&lt;br /&gt;   port.Encoding = System.Text.Encoding.Default;&lt;br /&gt;   port.NewLine = "\r";&lt;br /&gt;   port.ReceivedBytesThreshold = 1;&lt;br /&gt;&lt;br /&gt;   port.DtrEnable = true;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   It reacts, but I dont get the "ok." that I'm expecting... Any ideas?&lt;br /&gt;&lt;br /&gt;   I use Serial monitor so that I see what goes in and out.&lt;br /&gt;&lt;br /&gt;   //J&lt;br /&gt;# coad said on November 13, 2005 8:29 PM:&lt;br /&gt;&lt;br /&gt;   I am try to get exactly Method that line the Hexa Method using for sending data throught RS232, that I want is the function fo sendding binary. How can I slove this problem, thank for helping!&lt;br /&gt;# TrackBack said on November 19, 2005 4:53 PM:&lt;br /&gt;&lt;br /&gt;# coad said on November 25, 2005 2:14 PM:&lt;br /&gt;&lt;br /&gt;   Jimmy:&lt;br /&gt;   Don't forget to attach a delegate to the DataReceived event, open the port (.Open), and send data (.Write). Beyond that, it may be something specific to your scanner device.&lt;br /&gt;# coad said on November 28, 2005 10:42 AM:&lt;br /&gt;&lt;br /&gt;   The .NET 2.0 class library does not seem to support devices powered by the serial port.&lt;br /&gt;&lt;br /&gt;   I have a couple different magstripe readers here at work which will work correctly after making a connection with HyperTerminal or opening the port in a similar .NET 1.1 library, but the device will not function after SerialPort.Open() on .NET 2.0, whether I write a driver program from scratch or try something like Noah's Serial Terminal. No exception is thrown and SerialPort.PortOpen return True so I know at least, the class library thinks it is funnctional. The light on the device, however, is off, so I know it's not getting power.&lt;br /&gt;&lt;br /&gt;   Does anyone have a serial port powered device working?&lt;br /&gt;# coad said on November 28, 2005 11:19 AM:&lt;br /&gt;&lt;br /&gt;   Great tutorial. I really want to read data from the com port using managed c++ rather than C#. Can't find a sample anywhere, Heeellllp!!!&lt;br /&gt;# coad said on December 8, 2005 7:15 AM:&lt;br /&gt;&lt;br /&gt;   I am trying to open a connection to COM3 on my machine. I have a USB device attached to the computer and its drivers emulate a serial port on COM3.&lt;br /&gt;&lt;br /&gt;   SerialPort.GetPortNames() returns "COM1" and "COM3" and if i connect to the port using TeraTerm its fully functional and i can see the data.&lt;br /&gt;&lt;br /&gt;   When i invoke open on the port after having set the port name to "COM3" i get an argument exception that the name doesn't start with COM or that there is no such port. The name DOES start with COM and as i said, GetPortNames() includes COM3.&lt;br /&gt;&lt;br /&gt;   Anyone experienced this? Solutions?&lt;br /&gt;&lt;br /&gt;   I am using VS 2005 Final on Win XP SP2.&lt;br /&gt;&lt;br /&gt;   /// Isak&lt;br /&gt;# TJ said on December 13, 2005 5:10 PM:&lt;br /&gt;&lt;br /&gt;   Does anyone know how to send a special character over the serial connection? Specifically I'm trying to send a ctrl+c.&lt;br /&gt;&lt;br /&gt;   Thanks!&lt;br /&gt;# TJ said on December 23, 2005 11:09 AM:&lt;br /&gt;&lt;br /&gt;   How would I send a ctrl+c (break) via serial?&lt;br /&gt;&lt;br /&gt;   Thanks!&lt;br /&gt;# Daniel said on January 5, 2006 6:43 PM:&lt;br /&gt;&lt;br /&gt;   Ive written a Serial Port monitoring app that reads data from the COM port real time and displays it to a Rich Text Box (along with any special characters such as Carridge Returns, Line Feeds etc). This program works perfectly on Windows XP however when I transfer it to my Server running Windows Server 2003 Standard Edition, it doesnt work. I have installed the NET.Framework 2 on the Server.&lt;br /&gt;&lt;br /&gt;   Further troubleshooting I redesigned the program to write a line of text to a text file when the method is called for Data waiting at the Serial Port Buffer. That line of code is :-&lt;br /&gt;&lt;br /&gt;   port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);&lt;br /&gt;&lt;br /&gt;   So it appears to me that the method is never being called. The text file also logs when the Serial port is opened and close and when any exceptions are thrown.&lt;br /&gt;&lt;br /&gt;   I know the device attached to the serial port is working as I fire up a 3rd Party Serial Port Monitor &amp;amp;/or Hyperterminal and I see the data continuously coming through.&lt;br /&gt;&lt;br /&gt;   Can anyone offer any assistance with this problem?&lt;br /&gt;&lt;br /&gt;   Thanks,&lt;br /&gt;   Daniel.&lt;br /&gt;# Kintesh Patel said on January 13, 2006 4:30 PM:&lt;br /&gt;&lt;br /&gt;   Those who are using Serial to USB convertor, Please check article "USB-to-RS232 Hurdle Race" published in elektor electronics Sept. 2005.&lt;br /&gt;&lt;br /&gt;   It describe behind the scene effect and it's reason.&lt;br /&gt;# Ashley said on January 17, 2006 6:16 AM:&lt;br /&gt;&lt;br /&gt;   Hi guys,&lt;br /&gt;&lt;br /&gt;   Many terminal programs that are available (Hyperterminal being one of them) do not implement handshaking correctly.&lt;br /&gt;&lt;br /&gt;   A normal 232 connection will most likely require DTR enabled as well as RTS as well.&lt;br /&gt;&lt;br /&gt;   For you apps try setting your serialport with&lt;br /&gt;&lt;br /&gt;   port.Handshake = System.IO.Ports.Handshake.RequestToSend;&lt;br /&gt;&lt;br /&gt;   This is what most terminal programs call hardware flow control. It will enable RTS/CTS flow control which most devices rely on for transmission timing.&lt;br /&gt;&lt;br /&gt;   You may have played with the handshaking in HyperTerminal but if you use a 232 hardware analyser you will notice that it does not change any lines on your port. Changing these setting with a .net v2 app certainly will&lt;br /&gt;&lt;br /&gt;   Setting DTR to enabled and handshaking to hardware should power the pin that manufacturers use for power robbing as well.&lt;br /&gt;&lt;br /&gt;   Hope that made sense and is of some use&lt;br /&gt;&lt;br /&gt;   Ashley&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Gan esh said on January 18, 2006 3:41 AM:&lt;br /&gt;&lt;br /&gt;   Hi, I am using Visual Studio .NET 2005 which has serial port class built with it.&lt;br /&gt;   I am developing a Web Application in which i require to do serial communication. and i just wanted to know how exactly to include the SerialDataReceivedEventHandler Event in my web application, please help me out.&lt;br /&gt;&lt;br /&gt;   Thanks in advance&lt;br /&gt;   gan esh&lt;br /&gt;# Mark said on February 1, 2006 2:31 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for the article Noah! I've run the sample as it is and have been unable to get a response from the Wavecom GSM Modem that I am trying to talk to - the port_DataReceived() event is never fired.&lt;br /&gt;&lt;br /&gt;   This is driving me nuts! Any ideas? I'm running this on a Windows 2003 Server using VC# Express 2005.&lt;br /&gt;&lt;br /&gt;   Regards,&lt;br /&gt;   Mark.&lt;br /&gt;# Tim Nguyen said on February 3, 2006 7:46 PM:&lt;br /&gt;&lt;br /&gt;   If you are having trouble with this, remember to send a "\r\n" command. It works perfectly if you do this.&lt;br /&gt;# LarsPetter said on February 4, 2006 11:21 AM:&lt;br /&gt;&lt;br /&gt;   I have connected my PC to a BS2 sitting on a Board of Education(using an USB to Serial adapter). When i write something to the BS2, it gets there, but it also ends up in the input buffer. Why does this happen, and how can i prevent it from happening?&lt;br /&gt;# Glenn said on February 13, 2006 5:18 PM:&lt;br /&gt;&lt;br /&gt;   Using your code:&lt;br /&gt;   -----------------------------------------------&lt;br /&gt;   private List&lt;byte&gt; PortBuffer = new List&lt;byte&gt;();&lt;br /&gt;&lt;br /&gt;   private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;   {&lt;br /&gt;   SerialPort port = (SerialPort)sender;&lt;br /&gt;&lt;br /&gt;   byte[] data = new byte[port.BytesToRead];&lt;br /&gt;&lt;br /&gt;   port.Read(data, 0, data.Length);&lt;br /&gt;&lt;br /&gt;   PortBuffer.AddRange(data);&lt;br /&gt;&lt;br /&gt;   ProcessIncomingData(PortBuffer);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void ProcessIncomingData(List&lt;byte&gt; PortBuffer)&lt;br /&gt;   {&lt;br /&gt;   // Search through the bytes to find the data you want&lt;br /&gt;   // then remove the data from the list. It is good to&lt;br /&gt;   // clean up unused bytes (usually everything before&lt;br /&gt;   // what you're looking for)&lt;br /&gt;   }&lt;br /&gt;   -------------------------------------------------&lt;br /&gt;   I need to find a two byte sequence (E0 80) in the data. I can find one byte or the other with something like this:&lt;br /&gt;   ----------------------------------------------&lt;br /&gt;   int found = PortBuffer.FindIndex(delegate(byte i)&lt;br /&gt;   {return i==0xE0;}&lt;br /&gt;   );&lt;br /&gt;&lt;br /&gt;   Console.WriteLine(found);&lt;br /&gt;   ----------------------------------------------&lt;br /&gt;   But how can I find the index of a exact sequence? Thanks.&lt;br /&gt;# Mark Holt said on February 14, 2006 11:36 AM:&lt;br /&gt;&lt;br /&gt;   The SerialPort Terminal worked fine for me...that is if I was communicating with another SerialPort Terminal app.&lt;br /&gt;   When I tried to communicate with HyperTerminal I had to change the handshaking.&lt;br /&gt;&lt;br /&gt;   After:&lt;br /&gt;   comport.PortName = cmbPortName.Text;&lt;br /&gt;&lt;br /&gt;   Add:&lt;br /&gt;   comport.Handshake = Handshake.RequestToSend;&lt;br /&gt;&lt;br /&gt;   Or:&lt;br /&gt;   comport.Handshake = Handshake.RequestToSendXOnXOff;&lt;br /&gt;&lt;br /&gt;   I used SysInternals' Portmon to compare how HyperTerminal connects to the COM port vs. the .Net 2.0 SerialPort class and noticed quite a few differences that I cannot control via the SerialPort class such as:&lt;br /&gt;&lt;br /&gt;   IOCTL_SERIAL_SET_HANDFLOW has a different XonLimit and XoffLimit (1024 instead of 80 and 1024 instead of 200, respectively)&lt;br /&gt;&lt;br /&gt;   IOCTL_SERIAL_SET_TIMEOUTS has a different RI, RM, RC and WC (-1 instead of 10, -1 instead of 0, -2 instead of 0 and 0 instead of 5000, respectively)&lt;br /&gt;&lt;br /&gt;   IOCTL_SERIAL_SET_WAIT_MASK checks for RLSD and ERR (like HyperT) but also checks for RXCHAR, RXFLAG, CTS, DSR, BRK, and RING.&lt;br /&gt;&lt;br /&gt;   IOCTL_SERIAL_SET_QUEUE_SIZE has an InSize of 4096 (instead of 8192) and OutSize of 2048 (instead of 8192).&lt;br /&gt;# Leslie Viljoen said on March 16, 2006 8:54 AM:&lt;br /&gt;&lt;br /&gt;   You probably have something else using that com port and it's locked. Make sure your terminal program is closed.&lt;br /&gt;# Vincent Collin said on March 30, 2006 2:35 PM:&lt;br /&gt;&lt;br /&gt;   Thanks alot Noah,&lt;br /&gt;&lt;br /&gt;   Great tutorial, was very very useful in my project.&lt;br /&gt;&lt;br /&gt;   Framework 2.0 is pretty useful when you need to use those good old serial port.&lt;br /&gt;# Carlos said on April 11, 2006 12:33 PM:&lt;br /&gt;&lt;br /&gt;   Hi, I am trying to read the data on COM7 (USB) on my machine.&lt;br /&gt;   When add the event handler to the progam i get an JIT debugging error: Class not registered.&lt;br /&gt;&lt;br /&gt;   Anyone expirienced this?&lt;br /&gt;&lt;br /&gt;   I'm using Visual C# Express ed. on Win XP SP2&lt;br /&gt;# rachel said on May 11, 2006 1:15 AM:&lt;br /&gt;&lt;br /&gt;   port = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);&lt;br /&gt;   port.Open();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   USB Cable Off - &gt; CPU 100%&lt;br /&gt;&lt;br /&gt;   Help me&lt;br /&gt;# EP said on May 29, 2006 10:50 AM:&lt;br /&gt;&lt;br /&gt;   what is the source codes for RS232 connection in framework 1.0 ? please help me!!!!!&lt;br /&gt;# Srikanta said on June 9, 2006 6:56 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for this article.i am new to .net development.i am fresher in development.&lt;br /&gt;   i want to learn more deep in serial programming.&lt;br /&gt;   i have connected to com1.&lt;br /&gt;   i am able to check whether bonus card is present or not,but i want to raed data from card from a particular byte to n byte.&lt;br /&gt;   so which method i have to use and how to use.plz reply me with syntax and code&lt;br /&gt;# hassan said on June 19, 2006 10:35 AM:&lt;br /&gt;&lt;br /&gt;   thinks for these information ,i want do this ,but in Visual Studio2003 . I mean open Port COM3  and  have a communication with a modem and call from My Pocket PC&lt;br /&gt;# hitesh said on June 20, 2006 1:24 AM:&lt;br /&gt;&lt;br /&gt;   hello,i want to require vb.net code for reading stream of data asynchronously  from serial port using multithreading as a background thread,so that is required,if more than one RFID tag read by serial port at a time.so how i can store all the tag read by serial port.&lt;br /&gt;# Ahmet Vehbi said on June 26, 2006 3:23 AM:&lt;br /&gt;&lt;br /&gt;   Dear All ;&lt;br /&gt;   Would you please send me the tha samples data's to compile in my own pc.&lt;br /&gt;   Because i couldn't achive to make the form in the appropriate shape,size or position.&lt;br /&gt;   Thanks to whom it may concern..&lt;br /&gt;# Punx said on June 29, 2006 1:35 PM:&lt;br /&gt;&lt;br /&gt;   Why does my timer dont start when I use timer1.Enable=true inside the DataReceived event handler?&lt;br /&gt;# TheRunningBoard said on June 29, 2006 8:14 PM:&lt;br /&gt;&lt;br /&gt;   Great work!&lt;br /&gt;# Zak said on July 3, 2006 6:07 AM:&lt;br /&gt;&lt;br /&gt;   hi&lt;br /&gt;   I'm using Visual Studio.net 2003&lt;br /&gt;   I have installed the .NET 2.0 (not the beta version)&lt;br /&gt;   and I cant find the name space&lt;br /&gt;   System.IO.Ports&lt;br /&gt;   any idea why&lt;br /&gt;   please help me&lt;br /&gt;# coad said on July 7, 2006 7:40 PM:&lt;br /&gt;&lt;br /&gt;   Zak:&lt;br /&gt;&lt;br /&gt;   Visual Studio 2003 is only for writing code against the .NET 1.1 framework.  Even if you have .NET 2.0 installed, you won't see it in VS 2003.  You need VS 2005.  You can write the code with a plain text editor and compile it through the .NET 2.0 command line compiler.&lt;br /&gt;# David Briggs said on July 9, 2006 8:41 PM:&lt;br /&gt;&lt;br /&gt;   I am doing some serial communication to a divice using .NET 2.0.  The device has a set of simple commands, each command and responce is a fix size. Each command will generate a responce and a new command can not be sent until the responce from the previous command has been recived.  I have set the DataReceived event handler to a method that will read the responce data. That part works OK.  There is a flag in the event handler that I set when I read the response. I poll for that flag to see when I can sent the next command. My question is is there any way I can know when it is OK to send the next command without polling? The DataReceived event is raised on a secondary thread. If there was some way to get the thread Id of the event handler I could do a thread Join to tell when the data reading is done.&lt;br /&gt;# De IT y cosas peores » Java vs .NET: Puerto Serie (Parte II) said on July 10, 2006 2:14 PM:&lt;br /&gt;&lt;br /&gt;   PingBack from http://cesarolea.com/index.php/archives/157&lt;br /&gt;# shinoy said on July 20, 2006 11:49 PM:&lt;br /&gt;&lt;br /&gt;   it is good. But if some one could explain about if someone need to get data from an epbx, wat method can be used.&lt;br /&gt;# silibug said on July 23, 2006 1:43 AM:&lt;br /&gt;&lt;br /&gt;   Hi... nice article :)&lt;br /&gt;&lt;br /&gt;   btw..&lt;br /&gt;&lt;br /&gt;   How can  we  communicate with our serials port on LAN environment.?.&lt;br /&gt;   any idea how to convert rs232 output for tcp/ip input?&lt;br /&gt;&lt;br /&gt;   PC &lt;-&gt; LAN/switch &lt;-&gt; Microcontroller &lt;-&gt; Rs232 &lt;-&gt; devices&lt;br /&gt;&lt;br /&gt;   thanks:)&lt;br /&gt;# Noah Coad [MS] said on July 24, 2006 11:33 AM:&lt;br /&gt;&lt;br /&gt;   silibug,&lt;br /&gt;   There are devices that let you control RS232 ports remotely over an ethernet network.  For example, the $99 LS100 by Aaxeon at http://www.aaxeon.com/products/Productdetail.aspx?cate=2&amp;amp;modelno=LS100    A Google search on "ethernet rs232" (without quotes) shows some more such devices. &lt;br /&gt;# SR said on July 27, 2006 12:48 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for creating this, it has helped me greatly.  This is my first day using visual C# express and tutorials like this are making progress possible.  Hopefully I can contribute in the future.&lt;br /&gt;&lt;br /&gt;   One note:  In order to build, I had to comment the line //File.WriteAll(TempFile, html); out as I got an error "'System.IO.File' does not contain a definition for 'WriteAll'.  Not sure if I am an isolated case, but it doesn't seem to affect the program.&lt;br /&gt;# Allan said on August 9, 2006 8:53 AM:&lt;br /&gt;&lt;br /&gt;   I'm sending commands ATs for modem port, and the modem do not receive the commands. I use (SerialPort Terminal) .... HELP me&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   thanks&lt;br /&gt;# Noah Coad [MS] said on August 10, 2006 12:22 PM:&lt;br /&gt;&lt;br /&gt;   Allan,&lt;br /&gt;   There isn't enough info in your comment to figure out what's going on.  Try [ENTER] [ENTER] [ENTER] ATE1 [ENTER]      The first set of [ENTER] commands is for the modem to detect the baud rate.  ATE1 turns on echoing back commands so you can see if the modem is responding.  Good luck.&lt;br /&gt;# Noah Coad [MS] said on August 10, 2006 12:22 PM:&lt;br /&gt;&lt;br /&gt;   SR,&lt;br /&gt;   Thanks for the pointer! :)&lt;br /&gt;# Julio Silva said on August 10, 2006 3:15 PM:&lt;br /&gt;&lt;br /&gt;   Hello,&lt;br /&gt;&lt;br /&gt;   I'm a begginer, and I'm tring to do a simple terminal (receive only) for my&lt;br /&gt;   pocket pc, built in C#, with CF.Net 2.0.&lt;br /&gt;&lt;br /&gt;   I have 2 bottons, one for serialport.open, other serialport.close.&lt;br /&gt;   And works fine, since it's for a GPS connection, and I see it&lt;br /&gt;   connecting/disconnecting.&lt;br /&gt;&lt;br /&gt;   I have a label, that if I do a label1.text=serialport.readexisting(); it&lt;br /&gt;   displays all.&lt;br /&gt;   but if I do it in serialport.datareceived event, it get's an runtime&lt;br /&gt;   error...&lt;br /&gt;   If I do anything like label1.text=serialport.readchar(); it get's the same&lt;br /&gt;   error.&lt;br /&gt;   What I'm doing wrong?&lt;br /&gt;   I only have some programming experience in Delphi and C++...&lt;br /&gt;&lt;br /&gt;   Thanks for your help,&lt;br /&gt;&lt;br /&gt;   jS&lt;br /&gt;# Noah Coad [MS] said on August 10, 2006 7:24 PM:&lt;br /&gt;&lt;br /&gt;   jS,&lt;br /&gt;   I've answered your question in the (new) FAQ section:&lt;br /&gt;   http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ&lt;br /&gt;# Julio Silva said on August 11, 2006 6:41 AM:&lt;br /&gt;&lt;br /&gt;   Sorry I missed it.&lt;br /&gt;   The problem it's now solved, thanks.&lt;br /&gt;&lt;br /&gt;   BTW there is an link error in SerialPort Terminal, the filename has a space, SerialPort Terminal.zip, and the link doesnt, so it say's it's not found...&lt;br /&gt;&lt;br /&gt;   Thanks again for the help,&lt;br /&gt;&lt;br /&gt;   jS&lt;br /&gt;# coad said on August 14, 2006 5:39 PM:&lt;br /&gt;&lt;br /&gt;   Julio,&lt;br /&gt;   I agree the file name is confusing with the space (and has been for a long time).  I've removed the space from all the links in the post and the filename.&lt;br /&gt;# Seng said on August 16, 2006 8:46 PM:&lt;br /&gt;&lt;br /&gt;   Hi All&lt;br /&gt;&lt;br /&gt;   I try to use this example to send a ATDT6129 command to dial an extension number. I got an error message from my Modem. If I try to use Microsoft Hyper termanal it works. Any ideas?&lt;br /&gt;&lt;br /&gt;   Thanks&lt;br /&gt;# Sheng Zhou said on August 16, 2006 9:33 PM:&lt;br /&gt;&lt;br /&gt;   Hi Coad&lt;br /&gt;&lt;br /&gt;   This example is very good, but atd or atdt command doesn't work. I have try other commands such as 'at', 'ati4' etc. they works. I don't know how to send a atd or atdt command to my modem. At moment, when I send atd or atdt command to my modem it got 'error' message back. Any ideas?&lt;br /&gt;&lt;br /&gt;   Thanks&lt;br /&gt;# NAFF said on August 17, 2006 9:08 AM:&lt;br /&gt;&lt;br /&gt;   I am looking to setup serialport in VC++.NET V2.  Do you have an example. All I wnt is to be able to read data from a microcontroller. I an new to VC++ and cant understand the c# example.&lt;br /&gt;&lt;br /&gt;   many thanks&lt;br /&gt;# Bill - WV7G said on August 18, 2006 2:06 PM:&lt;br /&gt;&lt;br /&gt;   I've been searching for the simplest way of coding the deligate to send received text to a textbox.  I should have known it would be a fellow HAM who had the answer!&lt;br /&gt;   Great stuff and very well done!&lt;br /&gt;# Todor’s Weblog » Serial Communication said on August 22, 2006 2:53 PM:&lt;br /&gt;&lt;br /&gt;   PingBack from http://todor.be/blog/?p=45&lt;br /&gt;# prem said on August 23, 2006 12:23 AM:&lt;br /&gt;&lt;br /&gt;   hi,&lt;br /&gt;   iam using visual studio3.0 and framework version is 1.1&lt;br /&gt;   Now ia want to access the serial prot using c#.&lt;br /&gt;&lt;br /&gt;   in this version SerialPort namespace can't use&lt;br /&gt;&lt;br /&gt;   how can i use API to access the serial port in C#(version1.1)&lt;br /&gt;   or&lt;br /&gt;   any method top access the SerialPort namespace in this version&lt;br /&gt;&lt;br /&gt;   plz help me&lt;br /&gt;   i want this very urgent&lt;br /&gt;   plz send&lt;br /&gt;   my email.id is&lt;br /&gt;   gpremkamal@yahoo.co.in&lt;br /&gt;# coad said on August 29, 2006 5:44 PM:&lt;br /&gt;&lt;br /&gt;   Hey prem, I just wrote an answer to your question in the FAQ portion of this post as question #3. See: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ&lt;br /&gt;# Tsahi said on September 3, 2006 3:20 PM:&lt;br /&gt;&lt;br /&gt;   hi, regarding .net 2.0 being free, well, the sdk is free, but who wants to code in notepad? you will have to pay for visual studio 2005 lot's of dollars, and my understanding is that the "express" editions are only free until november 2006. but there's a free open souce alternative called SharpDevelop, at http://www.icsharpcode.net/OpenSource/SD/Default.aspx . i tried their version 1.1 a while back and it was not bad, except for a few bugs. i hope their version 2.0 (for .net 2.0) is better, but i didn't try.&lt;br /&gt;# rajnish said on September 4, 2006 10:44 PM:&lt;br /&gt;&lt;br /&gt;   Dear Coad, I am an MCA student and need your help in , in Bi Directional interfacing an instrument, wherein I have to send some Delimited String to the instrument with certain commands Like ACK NAK STX etc. and Take the Data Instrument sends, So far I have been able to receive the data from the instrument, but while sending the data I don't get any reply, and nothing reaches to the instrument, where as the cable I have made is correct, and I know there is something wrong with the code it self please help me I am posting the details below please guide me how I can send the string to the Instrument i am using c# 2005 Please guide me Thanking you in anticipation Rajnish&lt;br /&gt;# SilentDawn said on September 5, 2006 7:10 AM:&lt;br /&gt;&lt;br /&gt;   .net 2.0串口通信新控件－－(serialPort)&lt;br /&gt;# Gaurav said on September 11, 2006 6:18 AM:&lt;br /&gt;&lt;br /&gt;   Hello Sir, The code you have provided is very appreciable to me coz almost all my problems have been solved. But only one problem is there i m explaining you: I m using a RichTextBox to display all the data that is in Buffer, But while displaying that data that is coming to textbox is some symbols not the actual text data. Like as if we use HYPERTERMINAL a windows program where it will display all the calls,duration,Number etc. I want to display the same data in RichTextBox. Only the textual data. Plz Help????? Urgent??????????&lt;br /&gt;# Noah Coad [MS] said on September 11, 2006 12:32 PM:&lt;br /&gt;&lt;br /&gt;   rajnish,&lt;br /&gt;   I just wrote an answer to your question in the FAQ portion of this post as question #4.&lt;br /&gt;   See: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ&lt;br /&gt;# Pockey said on September 13, 2006 8:56 PM:&lt;br /&gt;&lt;br /&gt;   Hi, thanks for your article!&lt;br /&gt;&lt;br /&gt;   I have a problem.  In your demo program, after I click the "Close Port" when there are still data sending from the Serial Port, the application will die. And I have to use "Ctrl + Shift + Delete" to end it. Any method to solve this? With "comport.close()" and data still in process, where all the data will be sent to?&lt;br /&gt;# coad said on September 22, 2006 12:23 AM:&lt;br /&gt;&lt;br /&gt;   Pockey,&lt;br /&gt;&lt;br /&gt;   In a case like this, you can do something like when the user clicks "close", in the form's closing event handler, make a loop that check's the comport's sending buffer, when it is 0, then allow the close to contine.  I'd also set the cursor to a wait hourglass and add a timeout (in case it takes too long).&lt;br /&gt;# Huy Tran said on October 4, 2006 12:03 AM:&lt;br /&gt;&lt;br /&gt;   hi Coad,&lt;br /&gt;&lt;br /&gt;   I am using serialport in framework 2.0 to make a connection to another port.I have some problem, some attribute in serialport are not has like AxInterop.MSCommLib.dll's attribute, such as : in AxInterop.MSCommLib.dll, there are have EOF enable, Sthreshold, Inputlen, InputMode. But in serialport, there is no these attributes.&lt;br /&gt;&lt;br /&gt;   One more question : Is serialport just suppose for Smart device (POCKET PC, WINDOWN CE)?&lt;br /&gt;&lt;br /&gt;   I am writing a app to connect another machine to send/receive data.&lt;br /&gt;&lt;br /&gt;   Please give me some advice!!&lt;br /&gt;&lt;br /&gt;   Thanx for reading.&lt;br /&gt;# Jon said on October 16, 2006 9:08 AM:&lt;br /&gt;&lt;br /&gt;   Coad, thanks for the excellet article.&lt;br /&gt;&lt;br /&gt;   I have tried to implement it in C++.NET 2 and below is some of the code in question which I am having problems with, when I run this it gives me exception which says BUFFER CAN NOT BE NULL.&lt;br /&gt;&lt;br /&gt;   Any help would be greatly appreciated. I am working on a PIC MCU, I will make my work public on your blog once it works hopefully.&lt;br /&gt;&lt;br /&gt;   void SendRs232Data()&lt;br /&gt;&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;    // Instantiate the communications port - this is done in //the form properties of serialPort control from the toolbox&lt;br /&gt;&lt;br /&gt;    // Open the port for communications&lt;br /&gt;&lt;br /&gt;    serialPort-&gt;Open();&lt;br /&gt;&lt;br /&gt;    // Write a string&lt;br /&gt;&lt;br /&gt;    serialPort-&gt;Write("Hello World");&lt;br /&gt;&lt;br /&gt;    int offset = 1;//The offset in the buffer array to begin //writing.&lt;br /&gt;&lt;br /&gt;    int count = 1; //The number of bytes to read.&lt;br /&gt;&lt;br /&gt;    array&lt;unsigned char=""&gt;^ buffer ;//The buffer array to write //the input to.&lt;br /&gt;&lt;br /&gt;   serialPort-&gt;Read(buffer, offset, count);&lt;br /&gt;&lt;br /&gt;    serialPort-&gt;Close();&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;# Mach said on October 17, 2006 2:23 AM:&lt;br /&gt;&lt;br /&gt;   hi,&lt;br /&gt;&lt;br /&gt;   I want to have  local resources (COM1, COM2) available to a terminal server.&lt;br /&gt;&lt;br /&gt;   I made my local serial port available in a session in Remote Desktop Connection window.&lt;br /&gt;&lt;br /&gt;   On terminal server I can see my serial port mapped to some TS033 and TS034 ports.&lt;br /&gt;&lt;br /&gt;   How can I open/use/connect these ports?&lt;br /&gt;&lt;br /&gt;   private SerialPort port = new SerialPort("TS033", 9600, Parity.None, 8, StopBits.One);  deasn't work.&lt;br /&gt;&lt;br /&gt;   On WinServer2003 it says:  The given port name does not start with COM/com or does not resolve to a valid serial port.&lt;br /&gt;&lt;br /&gt;   Thanks for any help.&lt;br /&gt;# coad said on October 17, 2006 11:14 AM:&lt;br /&gt;&lt;br /&gt;   Jon,&lt;br /&gt;&lt;br /&gt;   You've defined the variable for the buffer, but you need to create an array as well.  In C#, it would look like this:&lt;br /&gt;&lt;br /&gt;   byte[] buffer = new byte[10];&lt;br /&gt;# coad said on October 17, 2006 11:15 AM:&lt;br /&gt;&lt;br /&gt;   Mach,&lt;br /&gt;&lt;br /&gt;   Usually ports are mapped to COMx, sometimes as high as COM32.  Please see if you can map them to a COM number like this.&lt;br /&gt;# coad said on October 17, 2006 11:17 AM:&lt;br /&gt;&lt;br /&gt;   Huy Tran,&lt;br /&gt;&lt;br /&gt;   The .NET 2.0 SerialPort class is not for devices, only full PCs.  There are 3rd party serial classes for mobile devices.  The .NET classes are wrappers around the Win32 APIs, so some of the members are renamed and they may not all be avalible.&lt;br /&gt;# jon said on October 18, 2006 8:46 AM:&lt;br /&gt;&lt;br /&gt;   coed,&lt;br /&gt;&lt;br /&gt;   thanks for pointing me in the right direction. as you said buffer was not defined as an array correctly.&lt;br /&gt;&lt;br /&gt;   the program sort of works but does no print hello world, it prints the numbber 5, which is the byte size i am looking to print.  i expected hello to print. any ideas as to where i am going wrong?  many thanks.&lt;br /&gt;&lt;br /&gt;   void SendRs232Data()&lt;br /&gt;&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;    serialPort-&gt;Open();&lt;br /&gt;&lt;br /&gt;     serialPort-&gt;Write("Hello World");&lt;br /&gt;&lt;br /&gt;    int offset = 0;//The offset in the buffer array to begin writing.&lt;br /&gt;&lt;br /&gt;    int count = 5; //The number of bytes to read.&lt;br /&gt;&lt;br /&gt;     array&lt;unsigned char=""&gt;^ buffer = gcnew array&lt;unsigned char=""&gt; (10);//The buffer array to write the input to.&lt;br /&gt;&lt;br /&gt;    serialPort-&gt;Read(buffer, offset, count);&lt;br /&gt;&lt;br /&gt;   lblSerial-&gt;Text= (serialPort-&gt;Read(buffer, offset, count)).ToString();&lt;br /&gt;&lt;br /&gt;     serialPort-&gt;Close();&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;# Dejan said on October 20, 2006 6:44 AM:&lt;br /&gt;&lt;br /&gt;   My project requires external GPRS modem attached to serial port to send and receive SMS messages.&lt;br /&gt;&lt;br /&gt;   In addition to original Noah's code at the start of the blog, I've laso added and changed some things according to hints in the blog (thanx, guys); following i s a short summary of my add-ons to make the modem work:&lt;br /&gt;&lt;br /&gt;   1. Set modem handshake, like:&lt;br /&gt;&lt;br /&gt;   serialPort1.Handshake = Handshake.RequestToSend;&lt;br /&gt;&lt;br /&gt;   2. Prior to send first command, try to synchronize modem by sending "\r\n" after port.Open(), like:&lt;br /&gt;&lt;br /&gt;   serialPort1.Write("\r\n"); // sync purpose only&lt;br /&gt;&lt;br /&gt;   3. Always use "\r\n" at the end of the command, like:&lt;br /&gt;&lt;br /&gt;   serialPort1.Write("AT+CMGF=1\r\n");&lt;br /&gt;&lt;br /&gt;   (just in the case of sending SMS message itself, I use something like:&lt;br /&gt;&lt;br /&gt;   serialPort1.Write(textBox1.Text + "\u000D\u000A\u001A\n");&lt;br /&gt;&lt;br /&gt;   )&lt;br /&gt;&lt;br /&gt;   4. As described in FAQ (Q1), use Invoke and event delegation, like:&lt;br /&gt;&lt;br /&gt;   private void MyLog(string msg)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;              listBox1.Invoke(new EventHandler(delegate&lt;br /&gt;&lt;br /&gt;              {&lt;br /&gt;&lt;br /&gt;                  listBox1.Items.Add(msg);&lt;br /&gt;&lt;br /&gt;              }));&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;   private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;              // Read data&lt;br /&gt;&lt;br /&gt;              string data = serialPort1.ReadExisting();&lt;br /&gt;&lt;br /&gt;              // Display the text to the user in the terminal&lt;br /&gt;&lt;br /&gt;              MyLog(data);&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;   And this is it. After a couple of hours of being frustrated because of simplicity of using SerialPort class in .NET 2.0, but no result, it finally works. &lt;br /&gt;# Yonas said on October 23, 2006 9:08 AM:&lt;br /&gt;&lt;br /&gt;   RE: Test,&lt;br /&gt;&lt;br /&gt;   you dont say what programe you are using, but if you are sending and receiving data from the same port for a test, i suggest you wire up a NULL MODEM cable with one end connected to your COM2 port and at the other end connect PIN2 and PIN 3 using a wire. This will send what ever is in the Tx line to Rx line and you should be able to send TEST and read TEST on you monitor. A quick test to verify your cable is wired right would be to use hyperterminal. I hope I understood what you are trying to do correctly. &lt;br /&gt;# Matthias said on October 31, 2006 3:59 AM:&lt;br /&gt;&lt;br /&gt;   I need to send/recieve data to/from a uC using rs485 as protocol. I use a transducer to get the PC's rs232 and the uC's rs485 connected and therefore I need to have the RTS signal set at the start of writing data and unset it after all bytes have been written.&lt;br /&gt;&lt;br /&gt;   Unforutnately the given Handshakes set the RTS line but don't unset them after write.&lt;br /&gt;&lt;br /&gt;   Manually setting and unsetting RTS causes the RTS to be unset before all data have been written (although while loop until writebuffer is empty)&lt;br /&gt;&lt;br /&gt;   P.S.:&lt;br /&gt;&lt;br /&gt;   I can get it working if I run the obsolete c++ program, that was used for the same purpose, and send a command to the uC once. After that the RTS handling with the c# prog works fine. But there has to be a way to get it working directly from c#.&lt;br /&gt;&lt;br /&gt;   Regards&lt;br /&gt;&lt;br /&gt;   Matthias&lt;br /&gt;# pegah said on November 8, 2006 1:12 AM:&lt;br /&gt;&lt;br /&gt;   how can i access to pin ??? i want set CTS or ...???&lt;br /&gt;# Vinay said on November 8, 2006 6:32 AM:&lt;br /&gt;&lt;br /&gt;   Hi...&lt;br /&gt;&lt;br /&gt;   Your demo project is very good.&lt;br /&gt;&lt;br /&gt;   In my application i want to read text recieived on PC comport upto a string and after that i've to transmit some data on my port. So can you tell me how i can do this.&lt;br /&gt;&lt;br /&gt;   (e.g. I want to set the date &amp;amp; for that i have to wait until i receive text "Set Date :". )&lt;br /&gt;&lt;br /&gt;   Thanks,&lt;br /&gt;&lt;br /&gt;   Vinay&lt;br /&gt;# Jack said on November 21, 2006 2:07 PM:&lt;br /&gt;&lt;br /&gt;   ClosePort() is also sending a byte '00' to receiver, how avoid it? I can't set DiscardNull=true because I am using rs232 for binary data communication.&lt;br /&gt;&lt;br /&gt;   Thanks!&lt;br /&gt;# bidi said on November 27, 2006 11:04 AM:&lt;br /&gt;&lt;br /&gt;   i have a problem when i use GetPortName , i take port name for Com like this Com4, and i use the following code&lt;br /&gt;&lt;br /&gt;   --------------&lt;br /&gt;&lt;br /&gt;   foreach (string s in SerialPort.GetPortNames())&lt;br /&gt;&lt;br /&gt;              {&lt;br /&gt;&lt;br /&gt;                  cmbCom.Items.Add(s);&lt;br /&gt;&lt;br /&gt;              }&lt;br /&gt;&lt;br /&gt;   ------------------------&lt;br /&gt;&lt;br /&gt;   the com4 is bluetooth . is  anyonethat have any ideea about this?&lt;br /&gt;&lt;br /&gt;   thks bidi&lt;br /&gt;# zanis said on November 28, 2006 10:54 AM:&lt;br /&gt;&lt;br /&gt;   Hello,&lt;br /&gt;&lt;br /&gt;   I have a zebra printer connected to the com1 port, i use&lt;br /&gt;&lt;br /&gt;   the serial port class to send command to the printer but an exception is thrown on the Open method&lt;br /&gt;&lt;br /&gt;   "The given port name does not start with COM/com or does not resolve to a valid serial port"&lt;br /&gt;&lt;br /&gt;   Can someone help me please!!!&lt;br /&gt;# Onur Gorgulu said on November 30, 2006 12:12 PM:&lt;br /&gt;&lt;br /&gt;   Hi friends;&lt;br /&gt;&lt;br /&gt;   In my program I am calculating a number in Int16 type between 0 and 255, and then I want to send this number to my microcontroller via serial port in 1 byte. for example 139 = 10001011. But the command comport.write(string  s) only accepts string format to send. if I convert byte = 139 to string type and then send, the ascii codes of 1 3 and 9 are going separetly. I want to send the byte as a whole- the Hex equivalent of 139 in one byte. How can I do that? please explain me with useful commands. I am very newbie in this subject but I have a little time to do this project. Please response ASAP. Thanks alot for your help.&lt;br /&gt;&lt;br /&gt;   Best Regards&lt;br /&gt;&lt;br /&gt;   Onur&lt;br /&gt;# seval said on December 12, 2006 12:40 PM:&lt;br /&gt;&lt;br /&gt;   if DataReceived event dos not trigger&lt;br /&gt;&lt;br /&gt;   try&lt;br /&gt;&lt;br /&gt;   port.Handshake = System.IO.Ports.Handshake.RequestToSend;&lt;br /&gt;&lt;br /&gt;   it solved my problem&lt;br /&gt;&lt;br /&gt;   good luck&lt;br /&gt;# trichloramine said on December 13, 2006 1:25 AM:&lt;br /&gt;&lt;br /&gt;   My bad. It works.&lt;br /&gt;# zxf92183 said on December 13, 2006 1:41 AM:&lt;br /&gt;&lt;br /&gt;   hello,&lt;br /&gt;&lt;br /&gt;   I just use the  sample program from SerialPortTerminal to get data from a machine, it can received data at first time, but if the machine make a new test, and the program can't receive the data any more, after i restart the PC, the program can receive the data again. can someone help me.&lt;br /&gt;&lt;br /&gt;   thank you.&lt;br /&gt;# Reddie said on December 13, 2006 5:12 PM:&lt;br /&gt;&lt;br /&gt;   I have the same problem as Matthias, some body already got a solution?&lt;br /&gt;# Reddie said on December 15, 2006 4:19 AM:&lt;br /&gt;&lt;br /&gt;   @satya_chaitanya pleaze RTFM.&lt;br /&gt;&lt;br /&gt;   @Matthias on http://www.gotdotnet.com/ there is a serial port project which contains a sendI() function who direct sends a byte to the device. I've try'ed it and it works fine for our purpose.&lt;br /&gt;# Sergey said on December 15, 2006 10:02 AM:&lt;br /&gt;&lt;br /&gt;   Need send to com1 command "{$04A$03$46}". If send this commant on Terminal - all work. If send command in c# - dont work. Please Help me !&lt;br /&gt;# Reddie said on December 15, 2006 12:01 PM:&lt;br /&gt;&lt;br /&gt;   @Sergey: something like&lt;br /&gt;&lt;br /&gt;   byte[] b = {0x4a, 0x03, 0x46};&lt;br /&gt;&lt;br /&gt;   Serialport.Write(b,0,b.Length);&lt;br /&gt;&lt;br /&gt;   Is there a possibility to reach the Serialport handle???&lt;br /&gt;# zxf92183 said on December 18, 2006 11:28 PM:&lt;br /&gt;&lt;br /&gt;   hello,&lt;br /&gt;&lt;br /&gt;   I just use the  sample program from SerialPortTerminal to get data from a machine, it can received data at first time, but if the machine make a new test, and the program can't receive the data any more, after i restart the PC, the program can receive the data again. can someone help me.&lt;br /&gt;&lt;br /&gt;   thank you.&lt;br /&gt;# Sergey said on December 19, 2006 1:37 AM:&lt;br /&gt;&lt;br /&gt;   May be motheboard or servise havs the "Time out" for you port or connect.&lt;br /&gt;# Mark said on December 23, 2006 3:03 AM:&lt;br /&gt;&lt;br /&gt;   Thank you!! After trying to make sense of MSDN tutorials, I landed here, and let me tell you this is much better. But the SerialCom FAQ.zip can't be accesses... Can you help? Or for the others that were able to access it before, please send it to ltl_piggies@yahoo.com. Thanks much!&lt;br /&gt;# tesha said on January 5, 2007 12:24 AM:&lt;br /&gt;&lt;br /&gt;   when i do "port.Open()", it says&lt;br /&gt;&lt;br /&gt;   UnauthorizedAccessException was unhandled.&lt;br /&gt;&lt;br /&gt;   Access to the port "COM1" is denied.&lt;br /&gt;&lt;br /&gt;   Make sure you have sufficient privileges to access this resource&lt;br /&gt;# Muhammad Sajid said on January 10, 2007 10:55 AM:&lt;br /&gt;&lt;br /&gt;   Hi&lt;br /&gt;&lt;br /&gt;   Your Project is Excellent in every aspect&lt;br /&gt;&lt;br /&gt;   I want to use some part of ur code in my industrial project i request for a permission please !!!!!!!!!!!!!&lt;br /&gt;# Ravichandran said on January 11, 2007 9:37 AM:&lt;br /&gt;&lt;br /&gt;   hi everyone,&lt;br /&gt;&lt;br /&gt;   i don't  know how to connect usb port in c# 2003,&lt;br /&gt;&lt;br /&gt;   i can't able to use 2005 because my projects are already developed in 1.1 ,any can help me&lt;br /&gt;&lt;br /&gt;   thanks&lt;br /&gt;# helpstudent said on January 17, 2007 8:29 AM:&lt;br /&gt;&lt;br /&gt;   does anyone know how to set StopBits to None ????&lt;br /&gt;&lt;br /&gt;   I always get a runtime error!&lt;br /&gt;&lt;br /&gt;   thanks in advance&lt;br /&gt;# coad said on January 19, 2007 11:32 AM:&lt;br /&gt;&lt;br /&gt;   Ravichandran, This isn't about USB, it's about SerialPort.  You can get a USB to Serial adapter:&lt;br /&gt;&lt;br /&gt;   http://www.google.com/search?hl=en&amp;amp;q=USB+Serial+Adapter&lt;br /&gt;&lt;br /&gt;   If you have to use .NET 1.1, you can use info from my old post:&lt;br /&gt;&lt;br /&gt;   http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320&lt;br /&gt;# coad said on January 19, 2007 11:34 AM:&lt;br /&gt;&lt;br /&gt;   Muhammad Sajid,&lt;br /&gt;&lt;br /&gt;   Sure!  Feel free to use any code you find on my blog for any project.  This goes for any and everyone here.&lt;br /&gt;# coad said on January 19, 2007 12:31 PM:&lt;br /&gt;&lt;br /&gt;   Muhammad Sajid, Ravichandran, tesha, Mark, and others,&lt;br /&gt;&lt;br /&gt;   I've updated the FAQ section of the post to answer many of your questions, as well as added more support options.  Hope it helps!&lt;br /&gt;&lt;br /&gt;   FAQ Section: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq &lt;br /&gt;# Noah Coad said on January 20, 2007 8:50 PM:&lt;br /&gt;&lt;br /&gt;   Onur Gorgulu,&lt;br /&gt;&lt;br /&gt;   Try: com.Write(new byte[] { (byte)(new Random().Next(0, 255)) }, 0, 1);&lt;br /&gt;# Traverer said on January 23, 2007 8:52 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for such resourceful material on c# serial tutorial!&lt;br /&gt;&lt;br /&gt;   I am just a beginner to c# and serial port programming, after download the SerialPortTerminal.zip and try with TC35i terminal, I discover the reason that causing "my modem not responce to my at command".&lt;br /&gt;&lt;br /&gt;   It seem to me that the comport.Write method does not send the "\r\n" I type in txtSendData textbox. Thus i add the "\r\n" string to the SendData() function as shown below and it works !!&lt;br /&gt;&lt;br /&gt;   ==================================&lt;br /&gt;&lt;br /&gt;     private void SendData()&lt;br /&gt;&lt;br /&gt;      {&lt;br /&gt;&lt;br /&gt;        if (CurrentDataMode == DataMode.Text)&lt;br /&gt;&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;          // Send the user's text straight out the port&lt;br /&gt;&lt;br /&gt;            comport.Write(txtSendData.Text + "\r\n");   // &lt;-- add "\r\n" here             // Show in the terminal window the user's text             Log(LogMsgType.Outgoing, txtSendData.Text + "\r\n");   // &lt;-- add "\r\n" here           }      =====================================      Hope this could help those newbie like me to have a good starting experience in dealling the C# SerialPort and GSM terminal..... # sth_Weird said on January 25, 2007 4:15 AM:      hello,      thanx for this article, it helps a lot and is much better than anything else I found on the net!      I have a question...      I have two  classes "MyMainClass" (let's call it A to make it shorter...) and "MySerialConnectionClass" (A). A instanciates B and calls function SendToSerial. SendToSerial opens the connection and I add the event. then I send data to the device, and after some time the device is supposed to answer. the problem is that SendToSerial does not wait for this answer. How does the code have to look to make the function wait for the answer? I already tried a while-loop in the function which will only exit if a variable is true, and the variable is set to true by the data-receive event, but it didn't help, if I do that the programm stays in this loop forever. I also tried Application.DoEvents() inside the loop but it doesn't work. Any ideas? # Noah Coad said on January 27, 2007 11:17 AM:      Traverer,      Thanks for posting this back!  This is a question a lot of people have asked and it's good to see an answer posted. # Noah Coad said on January 27, 2007 11:20 AM:      sth_Weird,      What you need to do is attach to the SerialPort class' DataRecieved event that will call your code whenever there's incoming data.  See the 2nd block of code on this post, that what it does.  You can create the SerialPort class in your MySerialConnectionClass and put the DataRecieved event code there too. # Phil said on February 3, 2007 1:21 PM:      Hello,          I am new to C# and this article has been very informative and helpful in the startup of my serial port coding. I was wondering if anyone knew how to parse the data coming from the serial port. I want to enter the data into 3 textboxs. I've been looking up information on how to do this, but haven't found much. A sample code to startoff would be very helpful. Thanks for your time. # Jim Mason said on February 9, 2007 6:14 AM:      Thanks to your article titled "Serial Com Simply in C#", I was finally able to communicate with a serial device that I struggled with for quite some time.  I was trying to use old C++ dlls that even though they worked in C++ .NET, they would not work in C#.  Your article saved me!      I learned alot about serial communications in the process too.  I will definitely be studying the info posted on this web site.      Thanks Again.      Best Regards,      Jim # coad said on February 12, 2007 11:02 PM:      Phil,      There is a sample application that does something simular to this linked to above in the post. # Georges said on February 13, 2007 2:58 AM:      Hi, i'm trying connecting to aCisco Catalyst 3560, when I use the port.Open(); after setting all the properties, the port.CDHolding is False, so i cannot transmit data to the Serial Port If someone have the same problem. # balaji said on February 13, 2007 6:04 AM:      sir      ur article is awesome      im incorporating the same concept in my proj      without using interfaces i should get the data from the port connected and      convert it to the form compatible to the cimplicity      software      plz give the suggestion to do that      revert imediately # balaji said on February 13, 2007 6:06 AM:      my id is balaji_sairam@rediffmail.com # silibug said on February 13, 2007 9:29 PM:      hi...      your project seems interesting..      can u give us a link of ur schematic design..etcs..      so.. we can build/learn almost like u did...      thanks.. :) # balaji said on February 14, 2007 7:48 AM:      hi      ill give that tommoro # Tim said on February 14, 2007 10:29 AM:      When I try to make the example project I get an error. In the file about.cs the System.IO.File.WriteAll method is referenced, but this is not a valid method. The valid ones are listed here:      http://msdn2.microsoft.com/en-us/library/system.io.file_methods.aspx      I'm using C# Express, .Net v2. Anyone else have this problem? I fixed it by changing the call to File.WriteAllText      My previous post on this disappeared...... # altan said on February 14, 2007 4:52 PM:      hi guys      currently i m trying to program PP- 6750 Access Controller      but i only have a vb6.0 source code not the instruction set. the problem is i m writing code in c#. when i investigated the vb6 source code , it seems that it  s too complex and too long approximately 35000 lines! do you think that i can do it in a short way by using c#?      my mail: altantoksoz@myne.com      thanks # balaji said on February 14, 2007 10:22 PM:      hi folks iam in halfway to finish my project. as i use 1.1 i wrote code on my own i can read the data from the port but unable to write that into a file in csv format. here i can create the file but iam unable to write the data received into the file; # Gemballa said on February 17, 2007 5:05 AM:      Hi,      I currently programming an atmega168 which is connected to my computer. The communication between the 2 devices works but c# doesnt always take the correct things. For instance if i send with my atmel 123,456,789 (100ms between each number) then my c# application sometimes gets 123,45,78      He just looses some numbers. Is 100ms to fast for a serial port? So that the buffer is full and he cant get any data ? While if i listen to my serial port with hyperterminal i receive all my data correct.      Something weird.      Thanks for helping. # Karabulut said on February 20, 2007 4:12 AM:      Hi Dear Noah,     Thank you very much Noah! It was a very nice and helpful tutorial for me. I have jumped to C# in Visual Studio 2005 nowadays. But I have a problem with showing the incoming data on my textBox. It works with MessageBox, but not with my textBox. It gives error with my textBox. It gives yellow line and says something like, How to make Cross-Thread Call.... Could you help me? # Santos said on February 20, 2007 8:44 PM:      Hi I just wanna know if the DataReceived event of SerialPort in C# .Net 2.0 also works in USB to USB?if yes how could I make it work thanks # Noah Coad's Code : Post 100 - Blog Stats and Post Highlights said on February 21, 2007 11:56 AM:      PingBack from http://blogs.msdn.com/noahc/archive/2007/02/21/post-100-blog-stats-and-post-highlights.aspx # coad said on February 21, 2007 6:00 PM:      Santos,      See question #6 in the FAQ:      http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq # coad said on February 21, 2007 6:09 PM:      Karabulut,      See question #1 in the FAQ:      http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq # coad said on February 21, 2007 6:11 PM:      Tim,      Perhaps it is deprecated method?  The project still compiles so it shouldn't be too bad. # coad said on February 21, 2007 6:13 PM:      silibug,      If you buy a Parallax BASIC Stamp starter kit, it comes with schematics and parts to get you started.  http://basicstamp.com # coad said on February 21, 2007 6:14 PM:      Gemballa,      Keep in mind that data comes in to the serial port's buffer whenever it is avalible and not in nice easy to use packets.  It can be a challange to parse the data correctly to where it appears you have it all. # Jan Axelson said on February 22, 2007 10:44 AM:      For anyone who would like a look at another .NET SerialPort example, my COM Port Terminal application is available here:      http://www.lvr.com/serport.htm      It includes exception handling, detecting newly attached ports, support for user-selected handshaking/flow control, and more. There are C# and Visual Basic versions. # karabulut said on February 23, 2007 3:47 AM:      Thanks Noah!      It works now well. This was what I want. # balaji said on February 26, 2007 12:35 AM:      hi noah                i had cached the incoming data from the rs232 port             into the csv file format.            now i need to convert this into a cimplicity file format.            i have explored cimplicity in many ways.            but cant convert to the cimplicity compatible format.           Is there any provision for it noah.           i need to convert the csv file raw data(#12$0$0$0) and so on.          plz give any suggestion so that i could finish as soon as possible.         revert immediately anyone # raghu said on February 28, 2007 9:25 AM:      i am doing a project on railway signalling in vb.net.      my requirement is i have to control or adjust the form designed in my computer from another computer connected through a serial port cable.      to be in detail i have designed a track circuit with some picture boxes and buttons.so i need to change the color of the picture boxes and buttons through xl sheet in another computer by changing the status from 1 to 0 and viceversa.      first i tested for the communication between two systems by writing a chatting application which is working fine but i am not getting the idea to do the main task      please help me out in this # balaji said on February 28, 2007 10:47 PM:      hi raghu      ur project seems interesting      could u send me the project details and      codes so that i can help you # raghu said on March 1, 2007 12:51 AM:      hi balaji thanks for offering  me help.      i dont know whether i can send u the whole details but i will try to send to send atleast the main code.      first of all i just want a confirmation whether is it possible to change the status of a programm in one computer with xl sheet or some sought of table in another computer through serial port.      as i said in my previous post, communication between the two systems is possible.in that we can only send and receive text strings. # Chris said on March 5, 2007 7:00 AM:      Your posts were very helpful.      "Access to the port COM4"  was being denied and I have absolute and total authority over this computer! Simply switching to a different USB, which also changed the name to COM6 worked for me! # Miguel said on March 5, 2007 12:21 PM:      Hi, i´m from Argentina. This page was very usefull for me to make my modem make a call. Now i want to know how to know when the other side pick up the phone and answer the call i make or when is busy??      this is my simplified code to make a call:                     SerialPort myport = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);                     myport.NewLine = "\n";                     myport.DiscardNull = false;                     myport.Handshake = Handshake.XOnXOff;                                     myport.Open();                     myport.Write("atdt xxxx\r"); //xxx phone number      ...       ...      Now, how can i know if is busy o someone answer my call?      Thanks for your support, all of you!!! # Luke said on March 13, 2007 4:16 PM:      Hello,      Is it possible to develop a code that enables the COM port to send and receive data at the same time (bi-directional communication)? and if the answer is yes, how is it possible to develop such a code?      many thanks. # coad said on March 14, 2007 12:01 PM:      Miguel,      Does the modem give a signal/command back if it detects a busy signal?  Can you look for this response from the modem? # coad said on March 14, 2007 12:08 PM:      Luke,      You can think of the send and receive as two completely separate operations.  So you can definitely do "bi-directional" communications, just send data whenever you need to and receive data whenever it comes in.  Whether your device support bi-directional communications is another story entirely and up to the device. # Luke said on March 14, 2007 2:28 PM:      Well i have created two infrared devices that can send and receive data (using infrared LED to transmitt and Photo detector to receive the data on each device) each device i connected to computer using RS232 in order to do a bi-directional communication between the two computers using the infrared devices that i created. I used hyperterminal to test the devices and they are working except that the letters being received have different symbols than the key pressed! what i am trying to acheive is to use c# in order to send a "hello" word for example from one computer to the other and to make the second computer send an acknowledgement back saying "the word have been received" as an example. So how can i acheive that? is it actually possible? # ahmed gad said on March 15, 2007 9:47 AM:      hi all      i need one to help me about the interfacing the at89c52 to the pc . i finished the connection of MAX232 AND AT89C52 BUT THE PROBLEM IS HOW TO INRTERFAC PC TO IT.i think that i must have vesual basic software in my pc  i thik that,      but i dont have it.      please help me      thanks all # zafar said on March 16, 2007 9:07 AM:      hi.      its nice to see such competent people on net.      but i am still not satisfied bcz my requirements are still not fulfilled.bcz i wants to have input from my 8051 uc  and process that data in c++ programme.for example if i press a button on keypad of uc then pc should show a message well come if i press any other button it sholud say good bye      .or ican do numeriacel calcualtion.so kindly guide me.my email is      soheel_657@yahoo.coml # Saeed said on March 17, 2007 1:38 AM:      Hi Miguel and All:      First of all thanks for such a nice article. Secondly i want to dial my ISP to connect to internet using Modem on Serial Port...      Miguel i think u have worked on this.. can u give me some more help      Waiting ,      n thanks once more..      SAEED # oliver456 said on March 19, 2007 6:57 AM:      hi all       very nice article!       I have a problem , a serialPort is in use by an another application , I want to  monitor its data ,how can I do that      thanks # Miguel said on March 19, 2007 7:50 AM:      Saeed, i´ve been in vacations. First i have to check something that coad askme about my problem. In your question, i don´t understand very well what you want to do, but the code i write up in the post works very fine to dial any number you want. I´m using VS2005 with Serv Pack and a internal modem on my notebook. I recommend you to use the static method: string[] myPorts = SerialPort.GetPortNames(); so you can see what aviable ports your pc have. Then you can use my code post up here to make your modem dial a phone number. I think that if you want to handle the internet connection you will have to use the      void myport_DataReceived(object sender, SerialDataReceivedEventArgs e) method to handle what you want. The code up load by Coad is very help full. Just remember to make phone call via the modem you have to use AT commands and have all your connection cables set well (i mean the line cables with the modem). my mail is: miguelb_fiuba2@hotmail.com bye and thank every one for all the post. # ghalip said on March 21, 2007 5:48 AM:      now i face to the problem that ..      when i change the baund rate from 38400 to 9600 and begin initialize the port (serial port sp1;)it dosn't work?      why? # mark said on March 28, 2007 10:40 AM:      the device manager on my laptop doesn't show any serial ports, but getportnames() returns "com3". what does that mean? # JohnH said on March 29, 2007 8:11 AM:      mark, com3 could just be the port used by an internal modem. You can check your modem properties to be sure. # JohnH said on March 29, 2007 8:21 AM:      Has anyone managed to get the SerialPort class to work using redirected com ports on a Remote Desktop Connection?      I'm running the SerialPortTerminal example app on the server (using RDC to connect to the server) and trying to send/receive data through the client PC's com port.      Sending data to the client port seems to work okay but no data is received. I know MSComm (VB6) had problems with Remote Desktop but I was hoping that framework 2.0 serial driver would do the job. # Good said on March 30, 2007 6:19 AM:      Hi Noah, first of all thanks for this tutorial, it's very useful for me, a newbie of C#.NET.      I've encountered some problems with serial port communications between PC and a reader, hopefully can get some help from you.      I just wrote a simple program to send a byte array from PC to reader and the reader will send back another byte array to the PC. here is the code:      private void button1_Click(object sender, EventArgs e)             {                 open_serialPort1();                 byte[] data = new byte[7];                 serialPort1.Write(addCheckSum(resetReader), 0, 4);                 serialPort1.Read(data, 0, data.Length);                 close_serialPort1();                 string str = BitConverter.ToString(data);                 richTextBox1.Text = str;             }      When I first time press the button1, the reader can receive the byte array correctly from the PC and the PC also can receive the data which is sent back by the reader, everything is correct.      But when i press again the button1, only the reader can receive the data from PC, but PC cannot receive any data from reader, the richTextBox1 showing 7 bytes of 00.      Can you pls help me to figure out the problem, is there anything wrong with my program? # ... said on March 31, 2007 2:02 AM:      Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast! # jithen said on April 13, 2007 8:54 AM:      Hi im trying to get my c#.net app to work the problem is that when using      SerialDataReceivedEventArgs it echos all bytes/strings that is sent to the      port. If I send the AT command it always echos the AT and OK I just want it      to echo the OK. # SWAPNIL M GHOLAP said on April 15, 2007 8:35 AM:      RESPECTED SIR ,          I AM STUDENT OF THIRD YEAR,STUDYING IN INSTRUMENTATION AND CONTROL ENG.      SIR,I AM DOING PROJECT, IN WHICH I WANT TO READ THE SIGNAL FROM COM PORT1 THROUGH RS232 PARALLEL(DB25)AND THEN WITH RESPECT TO TIME,I WANT TO DISPLAY GRAPH ON VISUAL BASIC 6.0 SOFTWARE.          I WANT CODE IN VB,WHICH WILL DISPLAY THE GRAPH WHEN THE INPUT WILL CHANGE,GRAPH ALSO CHANGE FROM RS232(DB25). I HOPE U WILL DEFINEATELY SOLVE MY PROBLEM.I AM WAITING      FOR UR RESPONSE TILL WEDNESDAY. # wiwi develop said on April 16, 2007 7:10 PM:      i need some help i have a bluetooth printer and send the string to the port COM9 example puerto.WriteLine("something");      but a need send to the printer code for barcodes is send it by hexadecimal code o how? # Ngoc Lan said on April 19, 2007 1:53 AM:      Pls help me!      I am learning programing for Serial Port in C# and I have encountered  a problem. I don't understand why SerialPort.Write method don't act. I used that method , but I didn't receive data from the port.      Pls show the reason! # David Howell said on April 29, 2007 2:41 PM:      Thanks for the useful post on serialport. I am making a program for reading numbers and a newline trigger from serial connected balances.      Just a note on your SerialPortTerminal program. There seems to be no System.IO.File.Writeall method anymore, and I think .WriteAllText is what you need there.      I get the part about setting a buffer and reading it and writing it, but how do I write it to any active field on screen? I don't want to write to file or console, but rather to an information management system that can take key entries. Somewhat like a keyboard wedge. # kranthi said on April 30, 2007 5:42 AM:      am kranthi      am working a project in small company      am fresher so please give me code about my problem.      what am saying my sir one modem(that is one type of modem) connected to com1 port(serial port) in my pc.      am using .net 1.1 with c#.net , so i will created one form.      am used one text box and one button in that form ,      we will type some message in that textbox and click button.      how will send that messge to one any mobile number through comport settings(serial port).      please give me that code.please u can solve my problem. # girija said on May 2, 2007 2:10 AM:      how will know the receiver is availabel or not?      we sended the data to receiver but that is availlabel or not how will know.that is not availabel how much time will wait and how will display receiver not found. # girijapakala said on May 2, 2007 2:13 AM:      we send the data to reciver but that is not found how much time wait and how will display receiver not found message      please tell that anwser # Carmelo said on May 3, 2007 4:09 AM:      Thank you very much for the code...if I could ever return the favour feel free.  Recieving serial was not as straightforward as sending.      But using invoke and the way you've demonstrated has really really help...cant thank you enough. # Dean said on May 4, 2007 9:03 AM:      I used this code as a starting point for interacting with an old barcode scanner that connected via RS232.  Only real thing to add to what can be found here is that I needed to set RtsEnable to TRUE in order to receive data, otherwise the scanner just hung.      Oh, and if anyone's looking for info on a Handheld Products (formerly Welch Allyn) 3400 scanner, don't believe the defaults given in the user guide - it's 9600 baud, 8 data, 2 stop and no parity!  ;-) # Yasser said on May 7, 2007 11:15 PM:      Hi, Folks,      Can anyone help me with next probem      I have notebook with 1 Com (rs232) port.      On this laptop also have modem and infrared device.      I d'like to create from modem or infrared another COM rs232 port, So bi visible under pure dos withouth any drivers.      Some of programs under dosr does not working when using PCMCIA - rs232 ot USB - rs232 adapters.      Best regards      Yasser # Syntax76 said on May 8, 2007 6:30 AM:      Thanks for the great site. Intresting thing was i was looking for a tutorial for SerialPort, since my try went somehow wrong (i thought).      Im experimenting with serial communication between BASIC Stamp (BS2 for now) and PC; i already found the SerialPort class in .NET and was really glad for that. Unfortunatly the DataReceived event handler  isn't willing to work, neither at my code nor at yours (SerialPortTerminal) ; when using e.g.  PuTTY it displays my data sent.      I tried both in PBASIC: SEROUT and DEBUG      SEROUT 16, $4054, ["100 GET", 13]      as well as      DEBUG "100 GET", 13      (of course both are equal, but you never know...)      that sending both ways works is, as written, visible in PuTTY      in all 3 testing apps (my, yours and PuTTY) the serial settings were the same (9600 baud, 8 bit, 1 stopbit, no parity, no flow control)      and the .NET apps don't even jump into the event-handler (it never stops at the breakpoint inside).      Maybe you have a hint for me?      Best regards      Syntax76 # Syntax76 said on May 8, 2007 6:35 AM:      oh yes, to mention:      i use Win XP x64 may be this is the reason? But in the docs for this class is explicitly written, that it works under XP x64... # Clement said on May 9, 2007 4:55 PM:      I get an "Access to the port 'COM1' is denied" when I run the GUI version of my C# program, but when I run the console equivalent, I don't get the error and everything works perfectly.      I did the testing with the console and put the cs file in the other project, renaming the namespace of course. Why is that? I don't have a similiar problems with the other COM ports, but I need to use COM1 since the others are taken. # Ryan Dutton said on May 10, 2007 10:09 AM:      I had the "UnauthorizedAccessException" error.  It turned out that running the application from a mapped network drive was the problem.  If you have this issue, ensure its running from your C: drive and see what happens. # Clement said on May 15, 2007 3:08 PM:      I do run it from the C drive. I think there is a problem with using the serial port in other forms other than the main form. If I put the code in the main form, it works fine.      Whatever works. LOL. # Surya said on May 16, 2007 8:18 AM:      Hi,      I am sending data in bytes over serial port using .net 2.0.      problem is I am not getting the response from the device. # behkian said on May 20, 2007 4:50 AM:      Hi I have writen apog by using MSCOMM.ocx in vc++.net(windows application form) but I can not get numbers more than 127      if u can help me about this my prog must get this valuse and put them in thier text boxex and thier showers and I 'm getting data from 3 ports at one time .      if i can't use mscomm in vc++.net please guide me to use serial port component      thanks a lot # Michae said on May 24, 2007 7:17 AM:      Hello their developers..  can you help me with my problem... i'm using a foot pedal device and i want to read the data it sends, so i use the serial port in VS2005 but i dont know what code for it to recieve the data from the foot pedal??... can anyone help me.. pls # Surender Rawat said on May 25, 2007 2:02 AM:      Hello all developers      i have to develop an application in dot net which communicate with a infrared sensor which count the number of people passing away from. there is need of serial communication.      Dot net know how to start of it.      How to detectet by the application whether device is connected or net, how to receive and sent data. # Joesy said on June 1, 2007 5:36 AM:      Hey,      I found your article which is an execellent one. I implemented okie but I got problem with receiving reply message:      In order to receive reply, I changed a little bit in your send button event:      port.RtsEnable = true;      SendData();      port.RtsEnable = false;      But with the same command send, I received diffrent reply messages:      &lt;&lt;&lt;&gt;&gt;&gt; Received: 60 83 06 AF 4C 36 56 76 0C 00&lt;br /&gt;&lt;br /&gt;   &lt;&lt;&lt;&gt;&gt;&gt; Received: 60 E8 15 32 33 35 17 00 00&lt;br /&gt;&lt;br /&gt;   Could you please help me? I uploaded my code here: download.yousendit.com/BEF9777251C1D8EF&lt;br /&gt;&lt;br /&gt;   This is very urgent project of mine, Can you please spend some time to help me? Could I have your email, I will contact you?&lt;br /&gt;&lt;br /&gt;   Thank you very much,&lt;br /&gt;&lt;br /&gt;   Joesy&lt;br /&gt;# Jun said on June 3, 2007 1:45 AM:&lt;br /&gt;&lt;br /&gt;   I need to to simultaneously open and use 8 Comport!&lt;br /&gt;&lt;br /&gt;   Hello there,&lt;br /&gt;&lt;br /&gt;   Im communicating with 8 serial devices (Atmel 89S52 microcontroller) using usb2RS232 adapter connected in usb hub. Enumerated port are Com1 to Com8.&lt;br /&gt;&lt;br /&gt;   In order to send and receive data, i have to open and close each comport and sequently move to next comport.&lt;br /&gt;&lt;br /&gt;   I can exchanged data to and from serial devices however most of the time it throw an exception  " access denied to Comx". And eventualy my application would hang up.&lt;br /&gt;&lt;br /&gt;   I figure its hard to close and dispose serial port resources in moving from i.e. Com3 to another Com4.&lt;br /&gt;&lt;br /&gt;   Even I give enough time to Close the comport using timer.&lt;br /&gt;&lt;br /&gt;   I would like to Open and Use 8 Comport (Com1 to Com8) simultaneously.&lt;br /&gt;&lt;br /&gt;   I would deeply appreciate any hints, clue, HELP from anyone!&lt;br /&gt;&lt;br /&gt;   Jun&lt;br /&gt;# Joesy said on June 4, 2007 8:38 AM:&lt;br /&gt;&lt;br /&gt;   I got a probem when event fires: DataReceived:&lt;br /&gt;&lt;br /&gt;   Frame: The hardware detected a framing error.&lt;br /&gt;&lt;br /&gt;   Can you help me to explain about this error: When, how and where this error ocurrs?&lt;br /&gt;&lt;br /&gt;   Thanks,&lt;br /&gt;&lt;br /&gt;   Joesy&lt;br /&gt;# JD said on June 5, 2007 3:35 PM:&lt;br /&gt;&lt;br /&gt;   Hi,&lt;br /&gt;&lt;br /&gt;   I'm working a project using audio data gathered with a mic, using C# and DirectSound, that I'm trying to send to a device via serial, however because I'm so new to this, I cant get the audio to stream.  I can send files already recorded, but the goal is a "live" transmission of sorts.&lt;br /&gt;&lt;br /&gt;   Can anyone possibly help me? &lt;br /&gt;&lt;br /&gt;   I'm new to C# (like 5 or 6 days new...), so code with an explanation would be a great big help!  Thanks!&lt;br /&gt;&lt;br /&gt;   JD&lt;br /&gt;# Phillipe said on June 7, 2007 3:37 AM:&lt;br /&gt;&lt;br /&gt;   Hey Everybody! i think this is a little more complicated but maybe someone could help me, am working on a PIC - 18F258, i am sending data between the PIC and the program that Noah created, but every time my PIC send data it only appear 3F for every hex that my pic send, the weird thing is when i test the pic with terminal v1.09 because it works perfect, every hex that my pic send appear on terminal but can't do this with the program in c#, could someone give me some help? plz........... my e-mai is pcasorla124@gmail.com&lt;br /&gt;# Abebe said on June 8, 2007 2:48 PM:&lt;br /&gt;&lt;br /&gt;   Currently I am doing my final year project  and I came across Serial C# interfacing . I want to generate 40khz,50% duty ctcle square wave. Can any one help me PLZ?&lt;br /&gt;# kiwi said on June 10, 2007 10:20 PM:&lt;br /&gt;&lt;br /&gt;   hi guys.. i need to read tags using rfid reader. the reader is connected to the computer using serial port. can anyone advise me the codes for receving the tags data?&lt;br /&gt;&lt;br /&gt;   thanks&lt;br /&gt;# kiwi said on June 10, 2007 10:25 PM:&lt;br /&gt;&lt;br /&gt;   hi guys.. i need to read tags using rfid reader. the reader is connected to the computer using serial port. can anyone advise me the codes for receving the tags data? i'm using microsoft visual studio 2005.&lt;br /&gt;&lt;br /&gt;   thanks. your help is appreciated.&lt;br /&gt;# andrew said on June 13, 2007 5:53 AM:&lt;br /&gt;&lt;br /&gt;   hi just wondered if you had ever tried coding to something like this&lt;br /&gt;&lt;br /&gt;   www.mp3car.com/.../102176-need-advice-obd-c-net-app.html&lt;br /&gt;&lt;br /&gt;   it connecting to a cars computer&lt;br /&gt;&lt;br /&gt;   andrew&lt;br /&gt;# dan said on June 14, 2007 9:48 AM:&lt;br /&gt;&lt;br /&gt;   upon receiving properly formatted data according to a given protocol, i need to send back an ACK message within 2ms. is there any way this is possible using the SerialPort class? or is this only possible with drivers? i would really like to keep my implementation as simple and high-level as possible. i really don't want to have to write a driver to do this.&lt;br /&gt;&lt;br /&gt;   any suggestions?&lt;br /&gt;# vishnu said on June 19, 2007 12:38 AM:&lt;br /&gt;&lt;br /&gt;   Hi Noah,&lt;br /&gt;&lt;br /&gt;   Great article..... it help me lots of think........&lt;br /&gt;&lt;br /&gt;   keep it up......&lt;br /&gt;&lt;br /&gt;   Cheers........!&lt;br /&gt;# Chris said on June 20, 2007 9:39 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for sharing your great info - I have a VS2005 .Net2.0 app which is reading a Truck Scale.  It works great with 1 huge exception - the datareceived event is not firing soon enough.  I am running a port monitor along with my application and realize my application lags about 20 lines (roughly 12 characters each line) behind the actual data being read in the port.  Is there a way to speed the datareceived event to trigger faster?  Each line being received from the scale ends with a CRLF.  Thanks for your help!!!&lt;br /&gt;# Miguel said on July 4, 2007 4:56 AM:&lt;br /&gt;&lt;br /&gt;   Thanks a lot for this article.&lt;br /&gt;# kumaran said on July 5, 2007 4:35 AM:&lt;br /&gt;&lt;br /&gt;   Can anyonr guide me on writing barcode scanner(PT2000 TopGun) program. Just to download data from it&lt;br /&gt;# Miha said on July 6, 2007 8:44 AM:&lt;br /&gt;&lt;br /&gt;   Hello, I am new to Serial Port Programming. Liked your article. I have bought two usb to com adapters and gender changer (is this the same stuff as null modem adapter?). I setup everything, and I now have COM3 and COM4 ports (USB2COM adapters). If i programaticaly send writeline on com3 port the light on the port blinks. My question is how to loopback these two connections, so I can test software with it.... I think the problem is, that  do not have null modem adapter. Please if anyone has any ideas and comments please, let me know. Thanks!&lt;br /&gt;# hussein said on July 6, 2007 10:21 AM:&lt;br /&gt;&lt;br /&gt;   Thanks for the great sample. I have one issue, I used the code provided to lsiten to a port that has a card reader attached to it, I am receiving the data in the receive event but it gets split, so i receive part of the message and then receive the rest. Your assistance is much appreciated.&lt;br /&gt;# Miha said on July 6, 2007 11:02 AM:&lt;br /&gt;&lt;br /&gt;   OK, I have resolved my issue. I've created Loopback adapter and connected it to USB2COM cable and stuff now works!!!&lt;br /&gt;&lt;br /&gt;   Here is how to connect pins to create loopback adapter.&lt;br /&gt;&lt;br /&gt;   www.passmark.com/.../loopback.htm&lt;br /&gt;# logki said on July 9, 2007 1:29 PM:&lt;br /&gt;&lt;br /&gt;   Hi I am trying to write to a serial port  using a protocol which looks like this&lt;br /&gt;&lt;br /&gt;   &lt;/unsigned&gt;&lt;/unsigned&gt;&lt;/unsigned&gt;&lt;/byte&gt;&lt;/byte&gt;&lt;/byte&gt;&lt;/byte&gt;&lt;/byte&gt;&lt;/byte&gt;&lt;address&gt; &lt;length&gt; &lt;commd&gt; &lt;&gt;&lt;checksum&gt;&lt;br /&gt;&lt;br /&gt;   and heres is how i am writing it&lt;br /&gt;&lt;br /&gt;   public void SendDatathruPort(int addr, int length, int comd, int checksum)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;              byte[] data7 = new byte[17];&lt;br /&gt;&lt;br /&gt;              //byte[] data1 = datainuput();&lt;br /&gt;&lt;br /&gt;   int totalsum = data7[0] + data7[1] + data7[2] + data7[3] + data7[4] + data7[5] + data7Devil + data7[7] + data7Music + data7Music + data7[9] + data7[10] + data7[11] + data7[12] + data7[13] + data7[14] + data7[15];&lt;br /&gt;&lt;br /&gt;              checksum = (totalsum) &amp;amp; (0xFF);&lt;br /&gt;&lt;br /&gt;              data7[0] = (byte)addr;&lt;br /&gt;&lt;br /&gt;              data7[1] = (byte)length;&lt;br /&gt;&lt;br /&gt;              data7[2] = (byte)comd;&lt;br /&gt;&lt;br /&gt;              data7[3] = Convert.ToByte("1");&lt;br /&gt;&lt;br /&gt;              data7[4] = Convert.ToByte(txBxP1.Text);&lt;br /&gt;&lt;br /&gt;              data7[5] = Convert.ToByte(txBxP2.Text);&lt;br /&gt;&lt;br /&gt;              data7Devil = Convert.ToByte(txBxP3.Text);&lt;br /&gt;&lt;br /&gt;              data7[7] = Convert.ToByte(txBxP4.Text);&lt;br /&gt;&lt;br /&gt;              data7Music = Convert.ToByte(txBxP5.Text);&lt;br /&gt;&lt;br /&gt;              data7[9] = Convert.ToByte(txBxP6.Text);&lt;br /&gt;&lt;br /&gt;              data7[10] = Convert.ToByte(txBxP7.Text);&lt;br /&gt;&lt;br /&gt;              data7[11] = Convert.ToByte(txBxP8.Text);&lt;br /&gt;&lt;br /&gt;              data7[12] = Convert.ToByte(txBxP9.Text);&lt;br /&gt;&lt;br /&gt;              data7[13] = Convert.ToByte(txBxP10.Text);&lt;br /&gt;&lt;br /&gt;              data7[14] = Convert.ToByte(txBxP11.Text);&lt;br /&gt;&lt;br /&gt;              data7[15] = Convert.ToByte(txBxP12.Text);&lt;br /&gt;&lt;br /&gt;              data7[16] = (byte)checksum;&lt;br /&gt;&lt;br /&gt;              comport.Write(data7, 0, data7.Length); &lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;   and this is how i call it&lt;br /&gt;&lt;br /&gt;   private void setvalue_Click(object sender, EventArgs e)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;              // Send the user's text straight out the port&lt;br /&gt;&lt;br /&gt;              //comport.Write(txtSendData.Text)&lt;br /&gt;&lt;br /&gt;              //SendData();&lt;br /&gt;&lt;br /&gt;              SendDatathruPort(0x7B, 14,0x0A,0);&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;# logki said on July 9, 2007 1:30 PM:&lt;br /&gt;&lt;br /&gt;   When I set the values it doesnt seem to be seeting the values on the controller ,... any help is appreciated&lt;br /&gt;# ahmad said on July 10, 2007 2:04 AM:&lt;br /&gt;&lt;br /&gt;   hi;&lt;br /&gt;&lt;br /&gt;   Is there any way for me to use my .net 2 .exe aplication in other PCs (or platforms) which has not .net frame work?&lt;br /&gt;&lt;br /&gt;   regards&lt;br /&gt;# Geoff said on July 12, 2007 7:28 AM:&lt;br /&gt;&lt;br /&gt;   Hi Noah and all&lt;br /&gt;&lt;br /&gt;   This is a very useful page and has helped me greatly.&lt;br /&gt;&lt;br /&gt;   As a matter of interest has anyone had issues with&lt;br /&gt;&lt;br /&gt;   SerialErrorReceivedEventHandler on a windows XP pro&lt;br /&gt;&lt;br /&gt;   SP2 laptop using USB serial converters?.&lt;br /&gt;&lt;br /&gt;   My code displays framing and parity errors ,but will not&lt;br /&gt;&lt;br /&gt;   generate any events using USB on XP.&lt;br /&gt;&lt;br /&gt;   A PCMCIA serial card port on the same laptop works fine.&lt;br /&gt;&lt;br /&gt;   The same code also works well on Win 2k pro using either PCI or USB ports.&lt;br /&gt;&lt;br /&gt;   Best Regards&lt;br /&gt;&lt;br /&gt;   Geoff&lt;br /&gt;# Rafael said on July 19, 2007 5:41 PM:&lt;br /&gt;&lt;br /&gt;   I' am trying to control a power suply using RS-232 interface&lt;br /&gt;&lt;br /&gt;   But the power suply has a frame of 26 bytes&lt;br /&gt;&lt;br /&gt;   I am newbie and I just now hot to send strings through serial port, not how to sent bytes,&lt;br /&gt;&lt;br /&gt;   Please help me&lt;br /&gt;&lt;br /&gt;   rac28_03@hotmail.com&lt;br /&gt;# Georgi said on July 20, 2007 1:51 PM:&lt;br /&gt;&lt;br /&gt;   Hi,&lt;br /&gt;&lt;br /&gt;   I need to read binary data from comp port on C#, do I can use&lt;br /&gt;&lt;br /&gt;   byte[] signal;&lt;br /&gt;&lt;br /&gt;   signal = new byte[5000];&lt;br /&gt;&lt;br /&gt;   port.Read(signal, 0, 500);&lt;br /&gt;&lt;br /&gt;   And how to be able to read binary frames?&lt;br /&gt;# Georgi said on July 20, 2007 1:51 PM:&lt;br /&gt;&lt;br /&gt;   very interesting article&lt;br /&gt;&lt;br /&gt;   gwtt@abv.bg&lt;br /&gt;# Chris said on July 22, 2007 3:34 PM:&lt;br /&gt;&lt;br /&gt;   Hey Guys,&lt;br /&gt;&lt;br /&gt;   I can get a list of com ports in use to print out to the command window but i would like more information than just "com1, com2" i would like to see for example  "com1 Max Stream UVG, com2 4G cruiser mini" get my drift?&lt;br /&gt;&lt;br /&gt;   Any one have an idea how to do that?&lt;br /&gt;&lt;br /&gt;   Thanks!!!&lt;br /&gt;# Jones said on July 26, 2007 5:20 AM:&lt;br /&gt;&lt;br /&gt;   Hey nice site!&lt;br /&gt;&lt;br /&gt;   Am currently doing a project with CS and USB to UART controller (Virtual COM port), my aim at the moment is to be able to write a string of data from one from COM1 port to COM3, then get a reply back acknowledging reciept.&lt;br /&gt;&lt;br /&gt;   what have done so far is use some "if and else if" statment in my OUTPUT  box (textbox)  so that if the input we require is inside the textbox, we get a reply in the other COM port saying recieved.&lt;br /&gt;&lt;br /&gt;   This works fine, BUT AFTER RECIEVEING THE 1ST TEXT, I CAN'T READ NEW TEXT INPUT, BECAUSE MY READ COMMAND READS ALL THE TEXT IN THE OUTPUT TEXTBOX, I HAVE TRIED READLINE, IT DOESNT WORK NEITHER.&lt;br /&gt;&lt;br /&gt;   Can someone advise on what method i can call to read new string from my output textbox rather that reading everything, and also how can i go to a new line automatically inside a text box. (this doesnt work \r\n)&lt;br /&gt;&lt;br /&gt;   if (this.txtData.Text == "Hello")&lt;br /&gt;&lt;br /&gt;              {&lt;br /&gt;&lt;br /&gt;                  serialPort1.WriteLine("recieved\r\n");&lt;br /&gt;&lt;br /&gt;                              }&lt;br /&gt;&lt;br /&gt;              else if (this.txtData.Text == "Hiya")&lt;br /&gt;&lt;br /&gt;              {               &lt;br /&gt;&lt;br /&gt;                  serialPort1.WriteLine("hey");&lt;br /&gt;&lt;br /&gt;              }&lt;br /&gt;&lt;br /&gt;   so what am saying is that "Hello" goes into the output text box and "Recieved" is printed out, but when "Hiya" goes into the same output box, the readExisting() or readLine() method reads everything inside the text box and doesnt print/writes out "Hey"&lt;br /&gt;&lt;br /&gt;   Please help if you can!&lt;br /&gt;&lt;br /&gt;   Regards&lt;br /&gt;&lt;br /&gt;   Jones&lt;br /&gt;# mina said on July 31, 2007 2:16 AM:&lt;br /&gt;&lt;br /&gt;   hi.what i can connect 2 pc whit port usb whit c#?&lt;br /&gt;# mina said on July 31, 2007 3:15 AM:&lt;br /&gt;&lt;br /&gt;   hi&lt;br /&gt;&lt;br /&gt;   what i can connect 2 pc whit port usb?&lt;br /&gt;&lt;br /&gt;   i need code c#!&lt;br /&gt;&lt;br /&gt;   please help me!!&lt;br /&gt;# junied said on August 1, 2007 2:18 PM:&lt;br /&gt;&lt;br /&gt;   Excellent artical&lt;br /&gt;&lt;br /&gt;   i was searching for serial communication example using .net2005 v2&lt;br /&gt;&lt;br /&gt;   but this was the best&lt;br /&gt;# Adrian said on August 2, 2007 7:29 AM:&lt;br /&gt;&lt;br /&gt;   Nice article.&lt;br /&gt;&lt;br /&gt;   May you help me with a question?&lt;br /&gt;&lt;br /&gt;   Can i set DTR value? I need this signal to reset a PIC mcu.&lt;br /&gt;# YZ said on August 16, 2007 5:06 PM:&lt;br /&gt;&lt;br /&gt;   I  can get SerialDataReceivedEventHandler to work if I send a command to a serial device in a timer or click botton event. However, if I use a while-loop to continue send comands with a Thread.Sleep(1000) in between, the receive event does not even fire once. Why cannot I use while-loop in this case?&lt;br /&gt;&lt;br /&gt;   I would greatly appeciate your help.&lt;br /&gt;# krishna said on August 18, 2007 1:09 AM:&lt;br /&gt;&lt;br /&gt;   i want connect foot padel through comm port.&lt;br /&gt;&lt;br /&gt;   if pin change then how to call pin change event ?&lt;br /&gt;# krishna said on August 20, 2007 7:34 AM:&lt;br /&gt;&lt;br /&gt;   if i change comm port pin then auto working as foot padel for use in wav file.&lt;br /&gt;&lt;br /&gt;   how to work&lt;br /&gt;&lt;br /&gt;   send me&lt;br /&gt;&lt;br /&gt;   krishna551@gmail.com&lt;br /&gt;# hassan said on August 24, 2007 2:53 PM:&lt;br /&gt;&lt;br /&gt;   hi i want make a dailing with modem with c# code but i dont what work i must to do please help me thanks&lt;br /&gt;# vissu said on August 28, 2007 12:04 AM:&lt;br /&gt;&lt;br /&gt;   HI i am also trying the same thing with vs.net 2005.&lt;br /&gt;&lt;br /&gt;   what i am looking for?&lt;br /&gt;&lt;br /&gt;   I am having a weighting scale which will give lt/wt/depth/hgt etc.&lt;br /&gt;&lt;br /&gt;   I am a system with .net 2005&lt;br /&gt;&lt;br /&gt;   using RS 232 cable i am trying to get those data from scale to my application.&lt;br /&gt;&lt;br /&gt;   for that using serialport class i am configuring the com and then i am taking the data from scale.&lt;br /&gt;&lt;br /&gt;   Problem facing:&lt;br /&gt;&lt;br /&gt;   step1: In my .net windows applcation i click an Activate button.In this i had written a code&lt;br /&gt;&lt;br /&gt;   a.send a request to scale&lt;br /&gt;&lt;br /&gt;   b.sclae will send an acknowledgement as * to my application.&lt;br /&gt;&lt;br /&gt;   c.then user will keep an weight in scale and click print button in device.&lt;br /&gt;&lt;br /&gt;   d. In my application i kept a message button which user can peform above step.&lt;br /&gt;&lt;br /&gt;   e. then i am getting the bytes of data to my application and am storing thta information into my database.&lt;br /&gt;&lt;br /&gt;   Now problem is&lt;br /&gt;&lt;br /&gt;   In 2nd time if user has kept another weight in scale and user click a print button then its not getting that data. Even i kept a while(True) loop.&lt;br /&gt;&lt;br /&gt;   How can i achieve this in my application.&lt;br /&gt;&lt;br /&gt;   is there any way to achieve that 2nd, 3rd ... data from scale with out restarting comport repeatedly.&lt;br /&gt;&lt;br /&gt;   if u had give code it will be very helpful to me.&lt;br /&gt;# sam said on September 6, 2007 10:35 AM:&lt;br /&gt;&lt;br /&gt;   Hi, I am using VS 2005 and have a Thermal Printer connected to COM1.  I am trying to sniff text being send to the printer but every time I try to open COM1 it will give me the following exception:&lt;br /&gt;&lt;br /&gt;   {"The given port name does not start with COM/com or does not resolve to a valid serial port.\r\nParameter name: portName"}&lt;br /&gt;&lt;br /&gt;   My printer is plugged in and turned on, the driver is installed... I'm not sure how to get rid of the exception. &lt;br /&gt;&lt;br /&gt;   Thanks for anyone's help in advance!&lt;br /&gt;# sundar said on September 8, 2007 9:53 AM:&lt;br /&gt;&lt;br /&gt;   Hi,&lt;br /&gt;&lt;br /&gt;   How to send and receive data from com1(port)?&lt;br /&gt;&lt;br /&gt;   any dll files add   to the port  access?&lt;br /&gt;&lt;br /&gt;   can you replay clearly?&lt;br /&gt;&lt;br /&gt;   Many thanks s s s s s  s s s s sssssssssssssssss&lt;br /&gt;# jenny said on September 9, 2007 9:03 PM:&lt;br /&gt;&lt;br /&gt;   Hi, I would like to ask the same question as Haluk.&lt;br /&gt;&lt;br /&gt;   I am running the serialport transmitting program very fine in computer which using english language for non-unicode, and also standard and format, but when I change them to Chinese PRC, I got problem to send unicode 192.&lt;br /&gt;&lt;br /&gt;   I am using VB .net,&lt;br /&gt;&lt;br /&gt;   Dim buff() As Byte&lt;br /&gt;&lt;br /&gt;          Dim i As Integer&lt;br /&gt;&lt;br /&gt;          If SerialPort1.IsOpen Then&lt;br /&gt;&lt;br /&gt;              ReDim buff(2)&lt;br /&gt;&lt;br /&gt;              buff(0) = 192&lt;br /&gt;&lt;br /&gt;              buff(1) = 80&lt;br /&gt;&lt;br /&gt;              buff(2) = 192   &lt;br /&gt;&lt;br /&gt;              SerialPort1.Write(buff, i, 3)&lt;br /&gt;&lt;br /&gt;          End If&lt;br /&gt;&lt;br /&gt;   when I tried to capture with hyperterminal, i will get 192 192 80. Why this happend, and how to solve?&lt;br /&gt;&lt;br /&gt;   I really hope you can help me.. Thanks&lt;br /&gt;# ali said on September 11, 2007 3:03 AM:&lt;br /&gt;&lt;br /&gt;   hi&lt;br /&gt;&lt;br /&gt;   I write a Pocket PC program with c# and use it's serial port to communicate with my device. I have a problem with serial port. I defined a "static" class for serial port&lt;br /&gt;&lt;br /&gt;   communication. I have several form and used serial&lt;br /&gt;&lt;br /&gt;   class in most of them. When I run program, for firs time&lt;br /&gt;&lt;br /&gt;   I can connect via serial port. after first communication&lt;br /&gt;&lt;br /&gt;   I never can send or transmit data with serial port.&lt;br /&gt;&lt;br /&gt;   I checked serial port to be open. It open but do not response.&lt;br /&gt;# rajini said on September 17, 2007 4:42 AM:&lt;br /&gt;&lt;br /&gt;   hey all,&lt;br /&gt;&lt;br /&gt;   i need to receive a file from pos terminal to system in vb.net any body can help me........&lt;br /&gt;# rajesh patel said on September 19, 2007 2:09 AM:&lt;br /&gt;&lt;br /&gt;   Hi&lt;br /&gt;&lt;br /&gt;    i need add swipecard device into my project (asp.net c#) so which step i follow for this task pls help&lt;br /&gt;# Ajay Khatri said on September 19, 2007 11:59 PM:&lt;br /&gt;&lt;br /&gt;   very nice ...............!!!!!&lt;br /&gt;# David Amyotte said on October 1, 2007 10:53 AM:&lt;br /&gt;&lt;br /&gt;   Hello,&lt;br /&gt;&lt;br /&gt;   I have a question about programming in C# and .net 2.0 with serial ports..&lt;br /&gt;&lt;br /&gt;   I'm writing an application to read data from a micro controller. I know the data array the controller spits back is 24 bytes.&lt;br /&gt;&lt;br /&gt;   I used the bytethreshold property and set it to 24. What the program does it sends a hex 93 command and its spits back data. Problem is when I started using the bytethreshold property and if I hit the send command for  a second time the data in the array comes back isnt in the order it should be.&lt;br /&gt;&lt;br /&gt;   The reason why i used the bytethreshold property is to prevent the datarecieved event from firing until I have all the data in the buffer then I can store the data in my byte buffer.&lt;br /&gt;&lt;br /&gt;   What is the issue? Should I be clearing my buffer after each send command?&lt;br /&gt;# Darshan said on October 4, 2007 1:29 PM:&lt;br /&gt;&lt;br /&gt;   Hey I was just wondering if there was away around opening COM ports (more than one app).  Thanks&lt;br /&gt;# cute-solutions said on October 9, 2007 6:58 AM:&lt;br /&gt;&lt;br /&gt;   very nice tutorial!!&lt;br /&gt;# Rodrigo Silva said on October 9, 2007 11:48 AM:&lt;br /&gt;&lt;br /&gt;   Dear,   &lt;br /&gt;&lt;br /&gt;   the application usually works, when I open first in the hyperterminal and closed.   &lt;br /&gt;&lt;br /&gt;   Else makes this procedure the application doesn't work.   &lt;br /&gt;&lt;br /&gt;   Did anybody already go by this problem?   &lt;br /&gt;&lt;br /&gt;   I am using C #. Net 2.0   &lt;br /&gt;&lt;br /&gt;   Thanks&lt;br /&gt;# Stefan Matokic said on October 12, 2007 4:51 AM:&lt;br /&gt;&lt;br /&gt;   hello,&lt;br /&gt;&lt;br /&gt;   i've got a problem with comports, too. i need a way to close a opened comport in c# after the device on it already were turned of. it's not enough for me just to catch the exceptions, for regulare it would be myPort.Close(); but if the device is missed at the comport you'll recive a unauthorizedaccess exception.&lt;br /&gt;&lt;br /&gt;   someone an idea?&lt;br /&gt;&lt;br /&gt;   i would be very happy about some ideas --&gt; stefan(at)matokic.de&lt;br /&gt;&lt;br /&gt;   thanks...&lt;br /&gt;# krishna said on October 12, 2007 5:07 AM:&lt;br /&gt;&lt;br /&gt;   i have connect comm port and also call pinchange event but does not able to connect DataReceiveEvent.&lt;br /&gt;&lt;br /&gt;   so pls help code how to connect .&lt;br /&gt;&lt;br /&gt;   krishna551@gmail.com&lt;br /&gt;&lt;br /&gt;   thanks&lt;br /&gt;# german said on October 12, 2007 1:20 PM:&lt;br /&gt;&lt;br /&gt;   hi i'm working  with serialport1 and i send to an aplication in C#  10 bytes and the aplicacion receive just 8 byte always, my buffer rx is of 20 bytes, what is wrong&lt;br /&gt;&lt;br /&gt;   this is reception&lt;br /&gt;&lt;br /&gt;   private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;             int total = serialPort1.BytesToRead;// here always read 8 just bytes and bufer_rx is a20 bytes&lt;br /&gt;&lt;br /&gt;              serialPort1.Read(bufer_rx, 0, total);&lt;br /&gt;# NloGoloMRaR // Yuhn said on October 13, 2007 3:22 AM:&lt;br /&gt;&lt;br /&gt;   Hi German ... Check this out&lt;br /&gt;&lt;br /&gt;   Just put in a Thread.Sleep(250); in the start of the method, then it haves time to read all the incomming date in the buffer before empty it.&lt;br /&gt;&lt;br /&gt;   private void port_DataReceived(Object sender, System.IO.Ports.SerialDataReceivedEventArgs e)&lt;br /&gt;&lt;br /&gt;          {&lt;br /&gt;&lt;br /&gt;              Thread.Sleep(250);&lt;br /&gt;&lt;br /&gt;              int total = sp.BytesToRead &lt;br /&gt;&lt;br /&gt;              buffer_rx = new char[total];&lt;br /&gt;&lt;br /&gt;              sp.Read(buffer_rx, 0, total);&lt;br /&gt;&lt;br /&gt;              for (int i = 0; i &lt; buffer_rx.Length; i++)&lt;br /&gt;&lt;br /&gt;              {&lt;br /&gt;&lt;br /&gt;                  sB.Append(buffer_rxIdea.ToString());&lt;br /&gt;&lt;br /&gt;              }&lt;br /&gt;&lt;br /&gt;              MessageBox.Show(sB.ToString());&lt;br /&gt;&lt;br /&gt;              sB.Remove(0, sB.Length); //sB is a StringBuilder&lt;br /&gt;&lt;br /&gt;          }&lt;br /&gt;# paper said on October 18, 2007 11:44 PM:&lt;br /&gt;&lt;br /&gt;   hi,&lt;br /&gt;&lt;br /&gt;   I need help in a serialport communication program. i will have 2 form. form1 and form2, form1 will allow user to select their comport, baudrate,parity etc in a combobox. when i click ok, a connection should be establish in order for me to run form2. i have no idea how i shd write it, therefore i need some help here.&lt;br /&gt;# Randy Douglas said on October 19, 2007 12:29 AM:&lt;br /&gt;&lt;br /&gt;   Ashley nailed the problem for me here: "Setting DTR to enabled and handshaking to hardware should power the pin that manufacturers use for power robbing as well. "&lt;br /&gt;&lt;br /&gt;   I added "comport.DtrEnable = true;" and that solved my DataReceived problem where it would output the result after passing an AT command to my ISU to send SMS messages.&lt;br /&gt;&lt;br /&gt;   Thanks Ash ;-)&lt;br /&gt;# german said on October 19, 2007 1:50 PM:&lt;br /&gt;&lt;br /&gt;   hi Yuhn&lt;br /&gt;&lt;br /&gt;   thank you, it's working fine&lt;br /&gt;# german said on October 19, 2007 1:52 PM:&lt;br /&gt;&lt;br /&gt;   hi Yuhn, thank you it's working fine&lt;br /&gt;# mohsen said on October 29, 2007 3:22 PM:&lt;br /&gt;&lt;br /&gt;   hi&lt;br /&gt;&lt;br /&gt;   i want to make mens that cheng USB to com&lt;br /&gt;&lt;br /&gt;   please send for me shematic and file hex about it.&lt;br /&gt;&lt;br /&gt;   thank&lt;br /&gt;# Meme Team · S2MIDI: Open Source Serial to MIDI Converter for Windows said on November 7, 2007 2:43 PM:&lt;br /&gt;&lt;br /&gt;   Pingback from  Meme Team  ·  S2MIDI: Open Source Serial to MIDI Converter for Windows&lt;br /&gt;# Kai said on November 15, 2007 10:51 PM:&lt;br /&gt;&lt;br /&gt;   Hi mister, i doing my final year project which will link up to a solar panel to accuqire the voltage reading , it will go through the analog to digital conversion , so the signal( voltage reading becomes digital) , it will then send to a wireless transmitter , and send to the receiver which will then be interface to the computer thru rs232 to usb converter to comp.&lt;br /&gt;&lt;br /&gt;   currently i using C# , do u have any sample program to plot graph of the voltage reading against time ?, and since the voltage reading from solar panel varies, do i need a timer or so ? thanks alot for your kind attention , i using visual studio 2005&lt;br /&gt;# kai said on November 15, 2007 10:53 PM:&lt;br /&gt;&lt;br /&gt;   my email is rawdy_502@hotmail.com if u need to send me any sample data thanks alot...&lt;br /&gt;# Sri said on November 16, 2007 5:30 AM:&lt;br /&gt;&lt;br /&gt;   Hi,&lt;br /&gt;&lt;br /&gt;          I Have to Pass ctrl + D thru my Serial Port Connection Can any body say how is it possible, bit urgent pls&lt;br /&gt;# Vibhor Goswami said on November 18, 2007 11:56 PM:&lt;br /&gt;&lt;br /&gt;   Hi!&lt;br /&gt;&lt;br /&gt;   I'm using C# to create an interface between my card reader and my PC. I usually got Access denied but when i booted the system without my device connected to it, the error didn't appear when i run the program. Is there any way to prevent windows from accessing the 'COM1'? i also require some help to further communicate with my card reader as my establishment with the reader is done using methods from its dll but the reader doesn't respod. Pls guide me in some direction on how to proceed further? Any help is appreciated.&lt;br /&gt;# Thai Do said on November 19, 2007 2:47 PM:&lt;br /&gt;&lt;br /&gt;   Hello Noah,&lt;br /&gt;&lt;br /&gt;   Is it possible to access a remote com port using c#, a com port that is on another computer?&lt;br /&gt;# seph said on November 22, 2007 2:49 PM:&lt;br /&gt;&lt;br /&gt;   msdn says:&lt;br /&gt;&lt;br /&gt;   PinChanged, DataReceived, and ErrorReceived events may be called out of order, and there may be a slight delay between when the underlying stream reports the error and when the event handler is executed. Only one event handler can execute at a time.&lt;br /&gt;&lt;br /&gt;   quote&lt;br /&gt;&lt;br /&gt;   Only one event handler can execute at a time...&lt;br /&gt;&lt;br /&gt;   does this mean that if a 1st serialport event is executing and have not  yet returned while a second event fires.. the second event is lost to oblivion...&lt;br /&gt;&lt;br /&gt;   I've setup a microcontroller to send 2 parity errors but only one error receive event fires..&lt;br /&gt;&lt;br /&gt;   also is the pinchange event can only fire in the breakstate i.e. when the port is not sending and receiving..&lt;br /&gt;# Anil said on November 28, 2007 11:25 PM:&lt;br /&gt;&lt;br /&gt;   I want to send Ctrl+A on serial port....How can I send the Ctrl+A... Please help me... Its very urgent.&lt;br /&gt;&lt;br /&gt;   Anil&lt;br /&gt;# bahar said on December 3, 2007 2:06 AM:&lt;br /&gt;&lt;br /&gt;   Hi&lt;br /&gt;&lt;br /&gt;     I want to use Image scanner in my project with c#.net.&lt;br /&gt;&lt;br /&gt;   so how can I send and recieve data to/from image scanner with c#.net&lt;br /&gt;&lt;br /&gt;   thanks&lt;/checksum&gt;&lt;/commd&gt;&lt;/length&gt;&lt;/address&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-1479807503504796146?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/1479807503504796146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=1479807503504796146' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/1479807503504796146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/1479807503504796146'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/serialport-rs-232-serial-com-port-in-c.html' title='SerialPort (RS-232 Serial COM Port) in C# .NET'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-8254008382320435663</id><published>2008-07-18T03:27:00.000-07:00</published><updated>2008-07-18T03:28:44.500-07:00</updated><title type='text'>Keyspan Developer Documentation USB to Serial Programming</title><content type='html'>Accessing USB Serial Adapters:&lt;br /&gt; &lt;br /&gt;We attempted to support as much as possible of the "Microsoft Win32 Serial Communications" functionality. Please read "Serial Communications in Win32"( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp ) for an in depth description. &lt;br /&gt; &lt;br /&gt;The following fields (features) of the DCB structure are not supported:&lt;br /&gt;      fBinary&lt;br /&gt;      fNullStrip (will be added to an upcoming software release)&lt;br /&gt;      EofChar&lt;br /&gt;      fAbortOnError&lt;br /&gt;      fDsrSensitivity (will be added to an upcoming software release)&lt;br /&gt;      XonLim (this value is fixed at an appropriate value for the Keyspan Adapters)&lt;br /&gt;      XoffLim (this value is fixed at an appropriate value for the Keyspan Adapters)&lt;br /&gt; &lt;br /&gt;The TransmitCommChar() function is also not supported. However, we are hoping to add this feature to products released in the future.&lt;br /&gt; &lt;br /&gt;Latency:&lt;br /&gt;Due to the nature of usb to serial hardware, there is an inherent latency between when data is written to the driver and when it is sent over USB to the adapter and then written to the serial port. Applications should not depend on timing behavior that is unique to a 16550 compatible UART on the motherboard. While we try to emulate those devices as best as possible, the details of USB make it impossible to preserve the same timing. Further, applications wishing to obtain optimum data transfer should not make single byte "Writes" to the driver. This results in a separate 1-byte USB packet issued for each individual write. If the device is running in "Interrupt mode" (see adapter documentation for explanation of Interrupt versus Bulk mode) the minimum granularity for each packet is 1ms. This would significantly slow down the overall data transfer. Larger "writes" will utilize the USB stack more efficiently and take advantage of its greater transfer speeds. This also ensures that there is always data at the adapter to be sent on the serial port.&lt;br /&gt; &lt;br /&gt;High Speed Baud Rates:&lt;br /&gt;The Keyspan High Speed USB Serial Adapter (USA19W/USA19QW) and the 4-Port USB Serial Adapter (USA49W/USA49WLC) support baud rates above 115200. The following table shows supported extended baud rates by product part number.&lt;br /&gt; &lt;br /&gt;USA19W                   230400&lt;br /&gt;USA19QW                230400&lt;br /&gt;USA49W                   230400, 460800, 921600&lt;br /&gt;USA49WLC              230400 *&lt;br /&gt; &lt;br /&gt;* While the USA49WLC is not rated nor do we support using 460800 or 921600, our testing has shown that stable communication can be made at these speeds.&lt;br /&gt; &lt;br /&gt;Detecting Keyspan Serial Ports:&lt;br /&gt; The serial port driver for each Keyspan USB Serial Adapter will publish its "COM" port in the device registry under:&lt;br /&gt; &lt;br /&gt;HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM&lt;br /&gt; &lt;br /&gt;If the adapter is not plugged in, there will be no entry for the device. In this way, applications can locate serial ports that are in fact present.&lt;br /&gt; &lt;br /&gt;Applications may also use the Setup Device Manager API to locate Serial Port devices. The following is sample code demonstrating how to find Keyspan serial ports and extract the "COMxx" name.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;#include &lt;setupapi.h&gt;&lt;br /&gt;#include &lt;initguid.h&gt;&lt;br /&gt; &lt;br /&gt;#define MAX_PORTS 256&lt;br /&gt; &lt;br /&gt;char m_PortArray[MAX_PORTS][10];&lt;br /&gt;unsigned char m_PortCount = 0;&lt;br /&gt; &lt;br /&gt;// 4d36e978-e325-11ce-bfc1-08002be10318}&lt;br /&gt;DEFINE_GUID(GUID_PORTSDEVS, 0x4d36e978, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00,&lt;br /&gt;0x2b, 0xe1, 0x03, 0x18);&lt;br /&gt; &lt;br /&gt;void EnumerateKeyspanPorts()&lt;br /&gt;{&lt;br /&gt;      HDEVINFO hDevInfo = NULL;&lt;br /&gt;      SP_DEVINFO_DATA DeviceInterfaceData;&lt;br /&gt;      int i = 0;&lt;br /&gt;      DWORD dataType, actualSize = 0;&lt;br /&gt;      unsigned char dataBuf[MAX_PATH + 1];&lt;br /&gt; &lt;br /&gt;      // Reset Port List&lt;br /&gt;      m_PortCount = 0;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;      // Search device set&lt;br /&gt;      hDevInfo = SetupDiGetClassDevs((struct _GUID *)&amp;GUID_PORTSDEVS,0,0,DIGCF_PRESENT);&lt;br /&gt;      if ( hDevInfo )&lt;br /&gt;      {&lt;br /&gt;             while (TRUE)&lt;br /&gt;             {&lt;br /&gt;                     ZeroMemory(&amp;DeviceInterfaceData, sizeof(DeviceInterfaceData));&lt;br /&gt;                     DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);&lt;br /&gt;                     if (!SetupDiEnumDeviceInfo(hDevInfo, i, &amp;DeviceInterfaceData))&lt;br /&gt;                     {&lt;br /&gt;                            // SetupDiEnumDeviceInfo failed&lt;br /&gt;                            break;&lt;br /&gt;                     }&lt;br /&gt;                     &lt;br /&gt;                     if (SetupDiGetDeviceRegistryProperty(hDevInfo,&lt;br /&gt;                            &amp;DeviceInterfaceData,&lt;br /&gt;                            SPDRP_FRIENDLYNAME,&lt;br /&gt;                            &amp;dataType,&lt;br /&gt;                            dataBuf,&lt;br /&gt;                            sizeof(dataBuf),&lt;br /&gt;                            &amp;actualSize))&lt;br /&gt;                     {                           &lt;br /&gt;                            // IF IT'S A KEYSPAN DEVICE&lt;br /&gt;                            if (strstr((char *)dataBuf, "Keyspan"))&lt;br /&gt;                            {&lt;br /&gt; &lt;br /&gt;                                   char *begin, *end;&lt;br /&gt;                                   m_PortArray[m_PortCount][0] = 0;&lt;br /&gt;                                   if (begin = strstr((char *)dataBuf, "COM"))&lt;br /&gt;                                   {&lt;br /&gt;                                          if (end = strstr(begin, ")"))&lt;br /&gt;                                          {&lt;br /&gt;                                                 *end = 0;&lt;br /&gt;                                                 strcpy(m_PortArray[m_PortCount], begin);&lt;br /&gt;                                          }&lt;br /&gt;                                          &lt;br /&gt;                                   }&lt;br /&gt;                                   // Even if PortName parse fails increment port count&lt;br /&gt;                                   if (m_PortCount++ &gt; MAX_PORTS) break;&lt;br /&gt;                            }&lt;br /&gt; &lt;br /&gt;                     }&lt;br /&gt; &lt;br /&gt;                    i++;&lt;br /&gt;                     &lt;br /&gt;             }&lt;br /&gt;      }&lt;br /&gt;      SetupDiDestroyDeviceInfoList(hDevInfo);&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Instead of extracting the "COM" name from the FriendlyName, applications can call SetupDiOpenDevRegKey() and then read the "PortName" field using  RegQueryValueEx().&lt;br /&gt; &lt;br /&gt;Hot-Pluggable Serial Ports:&lt;br /&gt;Since Keyspan USB Serial adapters are hot-pluggable (user may remove and attach the adapter during normal system operation), application developers should expect the serial port to be removed mid-communication. Upon detecting that the device has been removed, the application should close its connection and re-attempt opening the port at some specified interval in case the adapter is re-attached. If the application maintains its connection to a serial port that has been removed, the operating system is unable to clean-up the device object associated with that connection such that when the device is re-attached, a new device instance must be created. The application will no longer have a valid connection to the device even though it has been re-attached. If the application closes its connection and then periodically re-opens a connection to the same device name (COMxx) it can correctly link the appropriate device instance once the adapter has been plugged in. Because some systems power down the USB bus during sleep (resulting in the adapter being removed), this will also allow applications to continue communication with a Keyspan Serial port after sleep-resume.&lt;br /&gt; &lt;br /&gt;Applications can use the RegisterDeviceNotification() function if running on Windows 2000/XP. This allows user-mode code to detect the removal of a device(s) based on device class (use class=Ports) or a file handle (use the handle returned from CreateFile()). &lt;br /&gt; &lt;br /&gt;An application could also assume a WriteFile() failure to indicate that the device has been removed. Generally, there is no reason why a WriteFile() call to a Keyspan Serial port should fail. In this context, failure is described either as a return of false from WriteFile() or that the number of bytes written is less than the number of bytes requested and the port is not in a handshaking hold state.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-8254008382320435663?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/8254008382320435663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=8254008382320435663' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8254008382320435663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/8254008382320435663'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/keyspan-developer-documentation-usb-to.html' title='Keyspan Developer Documentation USB to Serial Programming'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-7368812707216428383</id><published>2008-07-18T03:25:00.000-07:00</published><updated>2008-07-18T03:26:27.147-07:00</updated><title type='text'>BitKeeper diffs</title><content type='html'>#### ChangeSet ####&lt;br /&gt;2006-10-05 10:20:42+00:00, burnicki at pogo.udel.edu &lt;br /&gt;  [Bug 708] Set the affinity to a specific CPU for the clock interpolation thread only, not for the whole process.&lt;br /&gt;&lt;br /&gt;==== ports/winnt/ntpd/nt_clockstuff.c ====&lt;br /&gt;2006-10-05 10:20:40+00:00, burnicki at pogo.udel.edu +250 -575&lt;br /&gt;  Set the affinity to a specific CPU for the clock interpolation thread only, not for the whole process.&lt;br /&gt;&lt;br /&gt;--- 1.21/ports/winnt/ntpd/nt_clockstuff.c 2006-10-08 03:33:09 -04:00&lt;br /&gt;+++ 1.22/ports/winnt/ntpd/nt_clockstuff.c 2006-10-08 03:33:09 -04:00&lt;br /&gt;@@ -1,622 +1,297 @@&lt;br /&gt;-/* Windows NT Clock Routines&lt;br /&gt;- *&lt;br /&gt;- *&lt;br /&gt;- * Revision History:&lt;br /&gt;- * $Log$&lt;br /&gt;- * Revision 1.9  2000/11/19 09:02:12  dietrich&lt;br /&gt;- * From: Ron Thornton [rthornto at pictel.com]&lt;br /&gt;- * Sent: Thu 11/16/00 8:51 AM&lt;br /&gt;- * On Windows 2000 it requires a privilege on the current process token&lt;br /&gt;- * that is disabled by default on Windows 2000.&lt;br /&gt;- *&lt;br /&gt;- * I set the token by adding the following code at the beginning of the&lt;br /&gt;- * init_winnt_time() function in nt_clockstuff.c.&lt;br /&gt;- *&lt;br /&gt;- * Revision 1.8  2000/11/19 08:03:20  dietrich&lt;br /&gt;- * From: "Colin Dancer" &lt;colin.dancer at pyrochrome.net&gt;&lt;br /&gt;- * To: &lt;bugs at ntp.org&gt;&lt;br /&gt;- * Sent: 10 November 2000 12:59&lt;br /&gt;- * Subject: NT bug in NTP 4.0.99j&lt;br /&gt;- *&lt;br /&gt;- * I've found a bug in (and produced a fix for) the NT clock interpolation&lt;br /&gt;- * code in NTP 4.0.99j.&lt;br /&gt;- *&lt;br /&gt;- * The symptoms of the problem are that gettimeofday() function on NT&lt;br /&gt;- * can be wrong by hundreds of seconds if, while a gettimeofday() call&lt;br /&gt;- * is being processed, an APC completes after the query of the performance&lt;br /&gt;- * counter but before the lock is grabbed.  The most obvious fix is to move&lt;br /&gt;- * the lock to include the querying of the performance counter, but this&lt;br /&gt;- * could affect the predictability of the timestamp so I have instead&lt;br /&gt;- * tweaked the code to detect and sidestep the duff calculation.&lt;br /&gt;- *&lt;br /&gt;- * I've also found that on a loaded system the execution of the APC can be&lt;br /&gt;- * delayed, leading to errors of upto 10ms.  There is no easy fix to this,&lt;br /&gt;- * but I do have code for an alternative interpolation scheme which avoids&lt;br /&gt;- * the problem on single processor systems. I'm currently integrating this&lt;br /&gt;- * along with code for deciding which algorithm to use based on whether&lt;br /&gt;- * the system is SP or MP.&lt;br /&gt;- *&lt;br /&gt;- * Created by Sven Dietrich  sven at inter-yacht.com&lt;br /&gt;- *&lt;br /&gt;- */&lt;br /&gt;-&lt;br /&gt;+/* This file implementes system calls that are not compatible with UNIX */&lt;br /&gt; &lt;br /&gt; #ifdef HAVE_CONFIG_H&lt;br /&gt;-#include "config.h"&lt;br /&gt;+# include &lt;config.h&gt;&lt;br /&gt; #endif&lt;br /&gt; &lt;br /&gt;-#include "ntp_stdlib.h"&lt;br /&gt;-#include "clockstuff.h"&lt;br /&gt;-#include "ntservice.h"&lt;br /&gt;-#include "ntp_timer.h"&lt;br /&gt;-#include "ntpd.h"&lt;br /&gt;-&lt;br /&gt;-/*&lt;br /&gt;- * Include code to possibly modify the MM timer while the service is active. &lt;br /&gt;- */&lt;br /&gt;-&lt;br /&gt;-  /*&lt;br /&gt;-   * Whether or not MM timer modifications takes place is still controlled &lt;br /&gt;-   * by the variable below which is initialized by a default value but &lt;br /&gt;-   * might be changed depending on a command line switch.&lt;br /&gt;-   */&lt;br /&gt;-  int modify_mm_timer = MM_TIMER_LORES;&lt;br /&gt;-&lt;br /&gt;-  #define MM_TIMER_INTV   1  /* the interval we'd want to set the MM timer to [ms] */&lt;br /&gt;-&lt;br /&gt;-  static UINT wTimerRes;&lt;br /&gt;-  static TIMECAPS tc;&lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-extern double sys_residual; /* residual from previous adjustment */&lt;br /&gt;-&lt;br /&gt;-char szMsgPath[255];&lt;br /&gt;-BOOL init_randfile();&lt;br /&gt;-&lt;br /&gt;-static long last_Adj = 0;&lt;br /&gt;-&lt;br /&gt;-#define LS_CORR_INTV_SECS  2   /* seconds to apply leap second correction */&lt;br /&gt;-#define LS_CORR_INTV   ( (LONGLONG) HECTONANOSECONDS * LS_CORR_INTV_SECS )  &lt;br /&gt;-#define LS_CORR_LIMIT  ( (LONGLONG) HECTONANOSECONDS / 2 )  // half a second&lt;br /&gt;-&lt;br /&gt;-typedef union&lt;br /&gt;-{&lt;br /&gt;- FILETIME ft;&lt;br /&gt;- ULONGLONG ull;&lt;br /&gt;-} FT_ULL;&lt;br /&gt;-&lt;br /&gt;-static FT_ULL ls_ft;&lt;br /&gt;-static DWORD ls_time_adjustment;&lt;br /&gt;-static LARGE_INTEGER ls_ref_perf_cnt;&lt;br /&gt;-static LONGLONG ls_elapsed;&lt;br /&gt;-&lt;br /&gt;-static void StartClockThread(void);&lt;br /&gt;-static void StopClockThread(void);&lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-static CRITICAL_SECTION TimerCritialSection; /* lock for LastTimerCount &amp; LastTimerTime */&lt;br /&gt;-&lt;br /&gt;-static ULONGLONG RollOverCount = 0;&lt;br /&gt;-static ULONGLONG LastTimerCount = 0;&lt;br /&gt;-static ULONGLONG LastTimerTime = 0;&lt;br /&gt; &lt;br /&gt;-static HANDLE ClockThreadHandle = NULL;&lt;br /&gt;-static HANDLE TimerThreadExitRequest = NULL;&lt;br /&gt;-&lt;br /&gt;-static DWORD every = 0;&lt;br /&gt;-static DWORD initial_units_per_tick = 0;&lt;br /&gt;-static DWORD lastLowTimer = 0;&lt;br /&gt;+#include &lt;stdio.h&gt;&lt;br /&gt;+#include "ntp_machine.h"&lt;br /&gt;+#include "ntp_stdlib.h"&lt;br /&gt;+#include "ntp_syslog.h"&lt;br /&gt;+#include "ntp_fp.h"&lt;br /&gt;+#include "ntp.h"&lt;br /&gt;+#include "ntp_refclock.h"&lt;br /&gt;+#include "win32_io.h"&lt;br /&gt; &lt;br /&gt;-ULONGLONG PerfFrequency = 0;&lt;br /&gt;-static DWORD units_per_tick = 0;&lt;br /&gt;-static DOUBLE ppm_per_adjust_unit = 0.0;&lt;br /&gt; &lt;br /&gt;-/*&lt;br /&gt;- * Request Multimedia Timer&lt;br /&gt;- */&lt;br /&gt;-void&lt;br /&gt;-set_mm_timer(int timerres)&lt;br /&gt;+int NT_set_process_priority(void)&lt;br /&gt; {&lt;br /&gt;- modify_mm_timer = timerres;&lt;br /&gt;+ if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)) &lt;br /&gt;+  {&lt;br /&gt;+  msyslog(LOG_ERR, "SetPriorityClass: %m"); &lt;br /&gt;+  return 0;&lt;br /&gt;+  }&lt;br /&gt;+ else &lt;br /&gt;+  return 1;&lt;br /&gt; }&lt;br /&gt;+&lt;br /&gt; /*&lt;br /&gt;- * adj_systime - called once every second to make system time adjustments.&lt;br /&gt;- * Returns 1 if okay, 0 if trouble.&lt;br /&gt;+ * refclock_open - open serial port for reference clock&lt;br /&gt;+ *&lt;br /&gt;+ * This routine opens a serial port for I/O and sets default options. It&lt;br /&gt;+ * returns the file descriptor if success and zero if failure.&lt;br /&gt;  */&lt;br /&gt; int&lt;br /&gt;-adj_systime(&lt;br /&gt;- double now&lt;br /&gt;+refclock_open(&lt;br /&gt;+ char *dev,  /* device name pointer */&lt;br /&gt;+ u_int speed,  /* serial port speed (code) */&lt;br /&gt;+ u_int flags  /* line discipline flags */&lt;br /&gt;  )&lt;br /&gt; {&lt;br /&gt;- double dtemp;&lt;br /&gt;- u_char isneg = 0;&lt;br /&gt;- int rc;&lt;br /&gt;- long dwTimeAdjustment;&lt;br /&gt;-&lt;br /&gt;- /*&lt;br /&gt;-  * Add the residual from the previous adjustment to the new&lt;br /&gt;-  * adjustment, bound and round.&lt;br /&gt;-  */&lt;br /&gt;- dtemp = sys_residual + now;&lt;br /&gt;- sys_residual = 0;&lt;br /&gt;- if (dtemp &lt; 0)&lt;br /&gt;- {&lt;br /&gt;-  isneg = 1;&lt;br /&gt;-  dtemp = -dtemp;&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- if (dtemp &gt; NTP_MAXFREQ)&lt;br /&gt;-  dtemp = NTP_MAXFREQ;&lt;br /&gt;-&lt;br /&gt;- dtemp = dtemp * 1e6;&lt;br /&gt;-&lt;br /&gt;- if (isneg)&lt;br /&gt;-  dtemp = -dtemp;&lt;br /&gt;-&lt;br /&gt;- /* dtemp is in micro seconds. NT uses 100 ns units,&lt;br /&gt;-  * so a unit change in dwTimeAdjustment corresponds&lt;br /&gt;-  * to slewing 10 ppm on a 100 Hz system.&lt;br /&gt;-  * Calculate the number of 100ns units to add,&lt;br /&gt;-  * using OS tick frequency as per suggestion from Harry Pyle,&lt;br /&gt;-  * and leave the remainder in dtemp */&lt;br /&gt;- dwTimeAdjustment = (DWORD)( dtemp / ppm_per_adjust_unit + (isneg ? -0.5 : 0.5)) ;&lt;br /&gt;- dtemp += (double) -dwTimeAdjustment * ppm_per_adjust_unit; &lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-  /* If a leap second is pending then determine the UTC time stamp &lt;br /&gt;-  * of when the insertion must take place */&lt;br /&gt;- if (leap_next &amp; LEAP_ADDSECOND)  &lt;br /&gt;- {&lt;br /&gt;-  if ( ls_ft.ull == 0 )  /* time stamp has not yet been computed */&lt;br /&gt;-  {&lt;br /&gt;-   FT_ULL ft;&lt;br /&gt;-   SYSTEMTIME st;&lt;br /&gt;-   int itmp;&lt;br /&gt;-&lt;br /&gt;-   GetSystemTimeAsFileTime(&amp;ft.ft);   &lt;br /&gt;-   FileTimeToSystemTime(&amp;ft.ft, &amp;st);&lt;br /&gt;-&lt;br /&gt;-    /* Accept leap announcement only 1 month in advance,&lt;br /&gt;-    * for end of March, June, September, or December.&lt;br /&gt;-    */&lt;br /&gt;-   if ( ( st.wMonth % 3 ) == 0 )&lt;br /&gt;-   {&lt;br /&gt;-    /* The comarison time stamp is computed according &lt;br /&gt;-     * to 0:00h UTC of the following day */   &lt;br /&gt;-    if ( ++st.wMonth &gt; 12 )&lt;br /&gt;-    {&lt;br /&gt;-     st.wMonth -= 12;&lt;br /&gt;-     st.wYear++;&lt;br /&gt;-    }&lt;br /&gt;-    &lt;br /&gt;-    st.wDay = 1;&lt;br /&gt;-    st.wHour = 0;&lt;br /&gt;-    st.wMinute = 0;&lt;br /&gt;-    st.wSecond = 0;&lt;br /&gt;-    st.wMilliseconds = 0;&lt;br /&gt;-&lt;br /&gt;-    SystemTimeToFileTime(&amp;st, &amp;ls_ft.ft);&lt;br /&gt;-    msyslog(LOG_INFO, "Detected positive leap second announcement "&lt;br /&gt;-                      "for %04d-%02d-%02d %02d:%02d:%02d UTC",&lt;br /&gt;-             st.wYear, st.wMonth, st.wDay,&lt;br /&gt;-                      st.wHour, st.wMinute, st.wSecond);&lt;br /&gt;-   }&lt;br /&gt;-  }&lt;br /&gt;-  }&lt;br /&gt;-&lt;br /&gt;- &lt;br /&gt;-  /* If the time stamp for the next leap second has been set&lt;br /&gt;-  * then check if the leap second must be handled */&lt;br /&gt;- if ( ls_ft.ull )&lt;br /&gt;- {&lt;br /&gt;-  LARGE_INTEGER this_perf_count;&lt;br /&gt;-&lt;br /&gt;-  QueryPerformanceCounter( &amp;this_perf_count );&lt;br /&gt;-&lt;br /&gt;-  if ( ls_time_adjustment == 0 ) /* has not yet been scheduled */&lt;br /&gt;-  {&lt;br /&gt;-   FT_ULL curr_ft;&lt;br /&gt;-&lt;br /&gt;-    GetSystemTimeAsFileTime(&amp;curr_ft.ft);   &lt;br /&gt;-   if ( curr_ft.ull &gt;= ls_ft.ull )&lt;br /&gt;-   {&lt;br /&gt;-    ls_time_adjustment = every / LS_CORR_INTV_SECS;&lt;br /&gt;-    ls_ref_perf_cnt = this_perf_count;&lt;br /&gt;-    ls_elapsed = 0;&lt;br /&gt;-    msyslog(LOG_INFO, "Inserting positive leap second.");&lt;br /&gt;-   }&lt;br /&gt;-  }&lt;br /&gt;-  else  /* leap sec adjustment has been scheduled previously */&lt;br /&gt;-  {&lt;br /&gt;-   ls_elapsed = ( this_perf_count.QuadPart - ls_ref_perf_cnt.QuadPart ) &lt;br /&gt;-                  * HECTONANOSECONDS / PerfFrequency;&lt;br /&gt;-  }&lt;br /&gt;-&lt;br /&gt;-  if ( ls_time_adjustment )  /* leap second adjustment is currently active */&lt;br /&gt;-  {&lt;br /&gt;-   if ( ls_elapsed &gt; ( LS_CORR_INTV - LS_CORR_LIMIT ) )&lt;br /&gt;-   {&lt;br /&gt;-    ls_time_adjustment = 0;  /* leap second adjustment done */&lt;br /&gt;-    ls_ft.ull = 0;&lt;br /&gt;-   }&lt;br /&gt;-&lt;br /&gt;-  /* NOTE: While the system time is slewed during the leap second &lt;br /&gt;-   * the interpolation function which is based on the performance &lt;br /&gt;-   * counter does not account for the slew.&lt;br /&gt;-   */&lt;br /&gt;-  dwTimeAdjustment -= ls_time_adjustment;&lt;br /&gt;-  }&lt;br /&gt;+ HANDLE Handle = INVALID_HANDLE_VALUE;&lt;br /&gt;+ COMMTIMEOUTS timeouts;&lt;br /&gt;+ DCB dcb = {0};&lt;br /&gt;+&lt;br /&gt;+ //&lt;br /&gt;+ // open communication port handle&lt;br /&gt;+ //&lt;br /&gt;+ Handle = CreateFile(dev,&lt;br /&gt;+  GENERIC_READ | GENERIC_WRITE,&lt;br /&gt;+  0, // no sharing&lt;br /&gt;+  NULL, // no security&lt;br /&gt;+  OPEN_EXISTING,&lt;br /&gt;+  FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,&lt;br /&gt;+  NULL); // not template&lt;br /&gt;+ if (Handle == INVALID_HANDLE_VALUE) {  &lt;br /&gt;+   &lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: CreateFile error: %m", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;-&lt;br /&gt;- /* only adjust the clock if adjustment changes */&lt;br /&gt;- if (last_Adj != dwTimeAdjustment) {  &lt;br /&gt;-   last_Adj = dwTimeAdjustment;&lt;br /&gt;-# ifdef DEBUG&lt;br /&gt;-  if (debug &gt; 1)&lt;br /&gt;-   printf("SetSystemTimeAdjustment( %ld) + (%ld)\n", dwTimeAdjustment, units_per_tick);   &lt;br /&gt;-# endif&lt;br /&gt;-   dwTimeAdjustment += units_per_tick;&lt;br /&gt;-   rc = !SetSystemTimeAdjustment(dwTimeAdjustment, FALSE);&lt;br /&gt;- }&lt;br /&gt;- else rc = 0;&lt;br /&gt;- if (rc)&lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "Can't adjust time: %m");&lt;br /&gt;-  return 0;&lt;br /&gt;- }&lt;br /&gt;- else {&lt;br /&gt;-  sys_residual = dtemp / 1000000.0;&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;- if (debug &gt; 6)&lt;br /&gt;-  printf("adj_systime: adj %.9f -&gt; remaining residual %.9f\n", now, sys_residual);&lt;br /&gt;-#endif&lt;br /&gt;- return 1;&lt;br /&gt;-}&lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-void init_winnt_time(void)&lt;br /&gt;-{&lt;br /&gt;- BOOL noslew;&lt;br /&gt;- HANDLE hToken = INVALID_HANDLE_VALUE;&lt;br /&gt;- TOKEN_PRIVILEGES tkp;&lt;br /&gt;-&lt;br /&gt;- /*&lt;br /&gt;-  * Make sure the service is initialized&lt;br /&gt;-  * before we do anything else&lt;br /&gt;-  */&lt;br /&gt;- ntservice_init();&lt;br /&gt;-&lt;br /&gt;- /* Set the Event-ID message-file name. */&lt;br /&gt;- if (!GetModuleFileName(NULL, szMsgPath, sizeof(szMsgPath))) &lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "GetModuleFileName(PGM_EXE_FILE) failed: %m\n");&lt;br /&gt;-  exit(1);&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- /* Initialize random file before OpenSSL checks */&lt;br /&gt;- if(!init_randfile())&lt;br /&gt;-  msyslog(LOG_ERR, "Unable to initialize .rnd file\n");&lt;br /&gt;-&lt;br /&gt;- /*&lt;br /&gt;-  * Get privileges needed for fiddling with the clock&lt;br /&gt;-  */&lt;br /&gt;-&lt;br /&gt;-   /* get the current process token handle */&lt;br /&gt;- if (!OpenProcessToken(GetCurrentProcess(),&lt;br /&gt;-      TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken)) &lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "OpenProcessToken failed: %m");&lt;br /&gt;-  exit(-1);&lt;br /&gt;- }&lt;br /&gt;-   /* get the LUID for system-time privilege. */&lt;br /&gt;- LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &amp;tkp.Privileges[0].Luid);&lt;br /&gt;- tkp.PrivilegeCount = 1;  /* one privilege to set */&lt;br /&gt;- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;&lt;br /&gt;-&lt;br /&gt;- /* get set-time privilege for this process. */&lt;br /&gt;- AdjustTokenPrivileges(hToken, FALSE, &amp;tkp, 0,&lt;br /&gt;-   (PTOKEN_PRIVILEGES) NULL, 0);&lt;br /&gt;-&lt;br /&gt;- /* cannot use return value of AdjustTokenPrivileges. */&lt;br /&gt;- /* (success does not indicate all privileges were set) */&lt;br /&gt;- if (GetLastError() != ERROR_SUCCESS) &lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");&lt;br /&gt;-   /* later set time call will probably fail */&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- /* Reset the Clock to a reasonable increment */&lt;br /&gt;- if (!GetSystemTimeAdjustment(&amp;initial_units_per_tick, &amp;every,&amp;noslew))&lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "GetSystemTimeAdjustment failed: %m\n");&lt;br /&gt;-  exit(-1);&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- units_per_tick = initial_units_per_tick;&lt;br /&gt;-&lt;br /&gt;- /* Calculate the time adjustment resulting from incrementing&lt;br /&gt;-  * units per tick by 1 unit for 1 second */&lt;br /&gt;- ppm_per_adjust_unit = 1000000.0 / (double) every;&lt;br /&gt;-&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;- msyslog(LOG_INFO, "Initial Clock increment %7.1f us",&lt;br /&gt;-   (float) (units_per_tick / 10));&lt;br /&gt;- msyslog(LOG_INFO, "Adjustment rate %5.3f ppm/s", ppm_per_adjust_unit);&lt;br /&gt;-#endif&lt;br /&gt;-&lt;br /&gt;- /*++++ Gerhard Junker&lt;br /&gt;- * see Platform SDK for QueryPerformanceCounter&lt;br /&gt;- * On a multiprocessor machine, it should not matter which processor is called. &lt;br /&gt;- * However, you can get different results on different processors due to bugs in the BIOS or the HAL. &lt;br /&gt;- * To specify processor affinity for a thread, use the SetThreadAffinityMask function. &lt;br /&gt;- * ... we will hope, the apc routine will run on the same processor&lt;br /&gt;+ /*  Change the input/output buffers to be large.&lt;br /&gt;  */&lt;br /&gt;-&lt;br /&gt;- SetThreadAffinityMask(GetCurrentThread(), 1L);&lt;br /&gt;-&lt;br /&gt;- /*---- Gerhard Junker */&lt;br /&gt;-&lt;br /&gt;- StartClockThread();&lt;br /&gt;-&lt;br /&gt;- /* Set up the Console Handler */&lt;br /&gt;- if (!SetConsoleCtrlHandler(OnConsoleEvent, TRUE))&lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "Can't set console control handler: %m");&lt;br /&gt;+ if (!SetupComm( Handle, 1024, 1024)) {&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: SetupComm error: %m", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ dcb.DCBlength = sizeof(dcb);&lt;br /&gt;+ if (!GetCommState(Handle, &amp;dcb)) {&lt;br /&gt;+  // Error getting current DCB settings&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: GetCommState error: %m", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ switch (speed) {&lt;br /&gt;+   case B300 :   dcb.BaudRate = 300; break;&lt;br /&gt;+   case B1200 :  dcb.BaudRate = 1200; break;&lt;br /&gt;+   case B2400 :  dcb.BaudRate = 2400; break;&lt;br /&gt;+   case B4800 :  dcb.BaudRate = 4800; break;&lt;br /&gt;+   case B9600 :  dcb.BaudRate = 9600; break;&lt;br /&gt;+   case B19200 : dcb.BaudRate = 19200; break;&lt;br /&gt;+   case B38400 : dcb.BaudRate = 38400; break;&lt;br /&gt;+   default :&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: unsupported baud rate", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+&lt;br /&gt;+ dcb.ByteSize = 8;&lt;br /&gt;+ dcb.fBinary = TRUE;&lt;br /&gt;+ dcb.fParity = TRUE;&lt;br /&gt;+ dcb.fOutxCtsFlow = 0;&lt;br /&gt;+ dcb.fOutxDsrFlow = 0;&lt;br /&gt;+ dcb.fDtrControl = DTR_CONTROL_DISABLE;&lt;br /&gt;+ dcb.fDsrSensitivity = 0;&lt;br /&gt;+ dcb.fTXContinueOnXoff = FALSE;&lt;br /&gt;+ dcb.fOutX = 0; &lt;br /&gt;+ dcb.fInX = 0;&lt;br /&gt;+ dcb.fErrorChar = 0;&lt;br /&gt;+ dcb.fNull = 0;&lt;br /&gt;+ dcb.fRtsControl = RTS_CONTROL_DISABLE; // RTS_CONTROL_DISABLE;&lt;br /&gt;+ dcb.fAbortOnError = 0;&lt;br /&gt;+ dcb.ByteSize = 8;&lt;br /&gt;+ dcb.StopBits = ONESTOPBIT;&lt;br /&gt;+ dcb.Parity = NOPARITY;&lt;br /&gt;+ dcb.ErrorChar = 0;&lt;br /&gt;+ dcb.EvtChar = 0;&lt;br /&gt;+ dcb.EofChar = 0;&lt;br /&gt;+&lt;br /&gt;+ if (!SetCommState(Handle, &amp;dcb)) {&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: SetCommState error: %m", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ timeouts.ReadIntervalTimeout = 20; &lt;br /&gt;+ timeouts.ReadTotalTimeoutMultiplier = 0;&lt;br /&gt;+ timeouts.ReadTotalTimeoutConstant = 5000;&lt;br /&gt;+ timeouts.WriteTotalTimeoutMultiplier = 0;&lt;br /&gt;+ timeouts.WriteTotalTimeoutConstant = 5000;&lt;br /&gt;+&lt;br /&gt;+    // Error setting time-outs.&lt;br /&gt;+ if (!SetCommTimeouts(Handle, &amp;timeouts)) {&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: Device %s: SetCommTimeouts error: %m", dev);&lt;br /&gt;+  return -1;&lt;br /&gt;  }&lt;br /&gt;-}&lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-void reset_winnt_time(void)&lt;br /&gt;-{&lt;br /&gt;- /* restore the clock frequency back to its original value */&lt;br /&gt;- if (!SetSystemTimeAdjustment(0, TRUE)) &lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "Failed to reset clock state, SetSystemTimeAdjustment(): %m");&lt;br /&gt;- }&lt;br /&gt;-   /* read the current system time, and write it back to&lt;br /&gt;-           force CMOS update: */&lt;br /&gt;-      /************ Added back in 2003-01-26 *****************/&lt;br /&gt;- {&lt;br /&gt;-  SYSTEMTIME st;&lt;br /&gt;-  GetSystemTime(&amp;st);&lt;br /&gt;-  SetSystemTime(&amp;st);&lt;br /&gt;- }&lt;br /&gt;-}&lt;br /&gt; &lt;br /&gt;-&lt;br /&gt;-&lt;br /&gt;-int&lt;br /&gt;-gettimeofday(&lt;br /&gt;- struct timeval *tv&lt;br /&gt;- )&lt;br /&gt;-{&lt;br /&gt;- /*  Use the system time (roughly synchronised to the tick, and&lt;br /&gt;-  *  extrapolated using the system performance counter.&lt;br /&gt;-  */&lt;br /&gt;-&lt;br /&gt;- ULONGLONG Count;&lt;br /&gt;- LARGE_INTEGER LargeIntNowCount;&lt;br /&gt;- ULONGLONG Time;&lt;br /&gt;- ULONGLONG NowCount;&lt;br /&gt;- ULONGLONG PreCount;                                                  /*FIX*/&lt;br /&gt;- LONGLONG TicksElapsed;&lt;br /&gt;- LONG time_adjustment;&lt;br /&gt;-&lt;br /&gt;- /*  Mark a mark ASAP. The latency to here should&lt;br /&gt;-  *  be reasonably deterministic&lt;br /&gt;-  */&lt;br /&gt;-&lt;br /&gt;- PreCount = LastTimerCount;                                           /*FIX*/&lt;br /&gt;-&lt;br /&gt;- if (!QueryPerformanceCounter(&amp;LargeIntNowCount)) {&lt;br /&gt;-  msyslog(LOG_ERR, "QueryPeformanceCounter failed: %m");&lt;br /&gt;-  exit(1);&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- NowCount = LargeIntNowCount.QuadPart;&lt;br /&gt;-&lt;br /&gt;- /*  Get base time we are going to extrapolate from&lt;br /&gt;-  */ &lt;br /&gt;- EnterCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;- Count = LastTimerCount;&lt;br /&gt;- Time = LastTimerTime;&lt;br /&gt;- LeaveCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;-&lt;br /&gt;- /*  Calculate when now is.&lt;br /&gt;-  *&lt;br /&gt;-  *  Result = LastTimerTime +  (NowCount - LastTimerCount) / PerfFrequency&lt;br /&gt;-  */&lt;br /&gt;-&lt;br /&gt;- if (NowCount &gt;= Count)&lt;br /&gt;- {&lt;br /&gt;-  TicksElapsed = NowCount - Count; /* linear progression of ticks */&lt;br /&gt;- }&lt;br /&gt;- else&lt;br /&gt;- {&lt;br /&gt;- /************************************************************************/&lt;br /&gt;- /* Differentiate between real rollover and the case of taking a         */&lt;br /&gt;- /* perfcount then the APC coming in.                                    */&lt;br /&gt;- /************************************************************************/&lt;br /&gt;-  if (Count &gt; PreCount)                                           /*FIX*/&lt;br /&gt;-  {        /*FIX*/&lt;br /&gt;-   TicksElapsed = 0;                                       /*FIX*/&lt;br /&gt;-  }                                                               /*FIX*/&lt;br /&gt;-  else                                                            /*FIX*/&lt;br /&gt;-  {                                                               /*FIX*/&lt;br /&gt;-   TicksElapsed = NowCount + (RollOverCount - Count); /*FIX*/&lt;br /&gt;-  }                                                               /*FIX*/&lt;br /&gt;- }&lt;br /&gt;-&lt;br /&gt;- /*  Calculate the new time (in 100's of nano-seconds)&lt;br /&gt;-  */&lt;br /&gt;- time_adjustment = (long) ((TicksElapsed * HECTONANOSECONDS) / PerfFrequency);&lt;br /&gt;- Time += time_adjustment;&lt;br /&gt;-&lt;br /&gt;- /* Convert the hecto-nano second time to tv format&lt;br /&gt;-  */&lt;br /&gt;- Time -= FILETIME_1970;&lt;br /&gt;- tv-&gt;tv_sec = (LONG) ( Time / 10000000ui64);&lt;br /&gt;- tv-&gt;tv_usec = (LONG) (( Time % 10000000ui64) / 10);&lt;br /&gt;-&lt;br /&gt;- return 0;&lt;br /&gt;+ return (int) Handle;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;-static void CALLBACK&lt;br /&gt;-TimerApcFunction(&lt;br /&gt;- LPVOID lpArgToCompletionRoutine,&lt;br /&gt;- DWORD dwTimerLowValue,&lt;br /&gt;- DWORD dwTimerHighValue&lt;br /&gt;- )&lt;br /&gt;-{&lt;br /&gt;- LARGE_INTEGER LargeIntNowCount;&lt;br /&gt;- (void) lpArgToCompletionRoutine; /* not used */&lt;br /&gt;-&lt;br /&gt;- if (dwTimerLowValue == lastLowTimer) return;&lt;br /&gt;- &lt;br /&gt;- /* Grab the counter first of all */&lt;br /&gt;- QueryPerformanceCounter(&amp;LargeIntNowCount);&lt;br /&gt;-&lt;br /&gt;- /* Save this for next time */&lt;br /&gt;- lastLowTimer = dwTimerLowValue;&lt;br /&gt; &lt;br /&gt;- /* Check to see if the counter has rolled. This happens&lt;br /&gt;-    more often on Multi-CPU systems */&lt;br /&gt;-&lt;br /&gt;- if ((ULONGLONG) LargeIntNowCount.QuadPart &lt; LastTimerCount) {&lt;br /&gt;-  /* Counter Rolled - try and estimate the rollover point using&lt;br /&gt;-    the nominal counter frequency divided by an estimate of the&lt;br /&gt;-    OS frequency */&lt;br /&gt;-  RollOverCount = LastTimerCount + PerfFrequency * every /  HECTONANOSECONDS -&lt;br /&gt;-   (ULONGLONG) LargeIntNowCount.QuadPart;&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;-  msyslog(LOG_INFO,&lt;br /&gt;-   "Performance Counter Rollover %I64u:\rLast Timer Count %I64u\rCurrent Count %I64u",&lt;br /&gt;-    RollOverCount, LastTimerCount, LargeIntNowCount.QuadPart);&lt;br /&gt;-#endif&lt;br /&gt;+int &lt;br /&gt;+ioctl(int fd,&lt;br /&gt;+   int cmd,&lt;br /&gt;+   int *x) {&lt;br /&gt;+&lt;br /&gt;+ if ((cmd == TIOCMSET) &amp;&amp; (*x &amp; TIOCM_RTS)) {&lt;br /&gt;+  if (!EscapeCommFunction((HANDLE) fd, SETRTS)) &lt;br /&gt;+   return -1;&lt;br /&gt;+ }&lt;br /&gt;+ else if ((cmd == TIOCMSET) &amp;&amp; !(*x &amp; TIOCM_RTS)){&lt;br /&gt;+  if (!EscapeCommFunction((HANDLE) fd, CLRRTS)) &lt;br /&gt;+   return -1;&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;- /* Now we can hang out and wait for the critical section to free up;&lt;br /&gt;-    we will get the CPU this timeslice. Meanwhile other tasks can use&lt;br /&gt;-    the last value of LastTimerCount */&lt;br /&gt;-  &lt;br /&gt;- EnterCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;- LastTimerCount = (ULONGLONG) LargeIntNowCount.QuadPart;&lt;br /&gt;- LastTimerTime = ((ULONGLONG) dwTimerHighValue &lt;&lt; 32) +&lt;br /&gt;-    (ULONGLONG) dwTimerLowValue;&lt;br /&gt;- LeaveCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;+ return 0;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;-&lt;br /&gt;-DWORD WINAPI ClockThread(void *arg)&lt;br /&gt;+int &lt;br /&gt;+tcsetattr(&lt;br /&gt;+ int fd, &lt;br /&gt;+ int optional_actions, &lt;br /&gt;+ const struct termios * s)&lt;br /&gt; {&lt;br /&gt;+ DCB dcb = { 0 };&lt;br /&gt;+ HANDLE Handle = (HANDLE) fd;&lt;br /&gt;+ dcb.DCBlength = sizeof(dcb);&lt;br /&gt;+ if (!GetCommState(Handle, &amp;dcb)) {&lt;br /&gt;+  // Error getting current DCB settings&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: GetCommState error: %m");&lt;br /&gt;+  return FALSE;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ switch (max(s-&gt;c_ospeed, s-&gt;c_ispeed)) {&lt;br /&gt;+  case B300 :   dcb.BaudRate = 300; break;&lt;br /&gt;+  case B1200 :  dcb.BaudRate = 1200; break;&lt;br /&gt;+  case B2400 :  dcb.BaudRate = 2400; break;&lt;br /&gt;+  case B4800 :  dcb.BaudRate = 4800; break;&lt;br /&gt;+  case B9600 :  dcb.BaudRate = 9600; break;&lt;br /&gt;+  case B19200 : dcb.BaudRate = 19200; break;&lt;br /&gt;+  case B38400 : dcb.BaudRate = 38400; break;&lt;br /&gt;+  default :&lt;br /&gt;+   msyslog(LOG_ERR, "NT_COM: unsupported baud rate");&lt;br /&gt;+   return FALSE;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ switch (s-&gt;c_cflag &amp; CSIZE) {&lt;br /&gt;+  case CS5 : dcb.ByteSize = 5; break;&lt;br /&gt;+  case CS6 : dcb.ByteSize = 6; break;&lt;br /&gt;+  case CS7 : dcb.ByteSize = 7; break;&lt;br /&gt;+  case CS8 : dcb.ByteSize = 8; break;&lt;br /&gt;+  default :&lt;br /&gt;+   msyslog(LOG_ERR, "NT_COM: unsupported word size");&lt;br /&gt;+   return FALSE;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ if (s-&gt;c_cflag &amp; PARENB) {&lt;br /&gt;+  dcb.fParity = TRUE;&lt;br /&gt;+  if (s-&gt;c_cflag &amp; PARODD) {&lt;br /&gt;+   dcb.Parity = ODDPARITY;&lt;br /&gt;+  }&lt;br /&gt;+  else {&lt;br /&gt;+   dcb.Parity = EVENPARITY;&lt;br /&gt;+  }&lt;br /&gt;+ }&lt;br /&gt;+ else {&lt;br /&gt;+  dcb.fParity = FALSE;&lt;br /&gt;+  dcb.Parity = NOPARITY;&lt;br /&gt;+ }&lt;br /&gt; &lt;br /&gt;- LARGE_INTEGER DueTime;&lt;br /&gt;- HANDLE WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL);&lt;br /&gt;-&lt;br /&gt;- (void) arg; /* not used */&lt;br /&gt; &lt;br /&gt;- if (WaitableTimerHandle != NULL) {&lt;br /&gt;-  DueTime.QuadPart = 0i64;&lt;br /&gt;-  if (SetWaitableTimer(WaitableTimerHandle, &amp;DueTime, 1L /* ms */, TimerApcFunction, &amp;WaitableTimerHandle, FALSE) != NO_ERROR) {&lt;br /&gt;-   for(;;) {&lt;br /&gt;-    if (WaitForSingleObjectEx(TimerThreadExitRequest, INFINITE, TRUE) == WAIT_OBJECT_0) {&lt;br /&gt;-     break; /* we've been asked to exit */&lt;br /&gt;-    }&lt;br /&gt;-   }&lt;br /&gt;-  }&lt;br /&gt;-  CloseHandle(WaitableTimerHandle);&lt;br /&gt;-  WaitableTimerHandle = NULL;&lt;br /&gt;+ dcb.fOutxCtsFlow = 0;&lt;br /&gt;+ dcb.fOutxDsrFlow = 0;&lt;br /&gt;+ dcb.fDtrControl = DTR_CONTROL_DISABLE;&lt;br /&gt;+ dcb.fDsrSensitivity = 0;&lt;br /&gt;+ dcb.fOutX = 0; &lt;br /&gt;+ dcb.fInX = 0;&lt;br /&gt;+ dcb.fErrorChar = 0;&lt;br /&gt;+ dcb.fNull = 0;&lt;br /&gt;+ dcb.fRtsControl = RTS_CONTROL_DISABLE;&lt;br /&gt;+ dcb.fAbortOnError = 0;&lt;br /&gt;+ dcb.ErrorChar = 0;&lt;br /&gt;+ dcb.EvtChar = 0;&lt;br /&gt;+ dcb.EofChar = 0;&lt;br /&gt;+&lt;br /&gt;+ if (!SetCommState(Handle, &amp;dcb)) {&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: SetCommState error: %m");&lt;br /&gt;+  return FALSE;&lt;br /&gt;  }&lt;br /&gt;- return 0;&lt;br /&gt;+ return TRUE;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;-&lt;br /&gt;-static void StartClockThread(void)&lt;br /&gt;+extern int &lt;br /&gt;+tcgetattr(&lt;br /&gt;+ int fd, struct termios *s)&lt;br /&gt; {&lt;br /&gt;- DWORD tid;&lt;br /&gt;- FILETIME StartTime;&lt;br /&gt;- LARGE_INTEGER Freq = { 0, 0 };&lt;br /&gt;- &lt;br /&gt;- /* get the performance counter freq */&lt;br /&gt;- if (!QueryPerformanceFrequency(&amp;Freq))&lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "QueryPerformanceFrequency failed: %m\n");&lt;br /&gt;-  exit (-1);&lt;br /&gt;+ DCB dcb = { 0 };&lt;br /&gt;+ HANDLE Handle = (HANDLE) fd;&lt;br /&gt;+ dcb.DCBlength = sizeof(dcb);&lt;br /&gt;+ if (!GetCommState(Handle, &amp;dcb)) {&lt;br /&gt;+  // Error getting current DCB settings&lt;br /&gt;+  msyslog(LOG_ERR, "NT_COM: GetCommState error: %m");&lt;br /&gt;+  return FALSE;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ /*  Set c_ispeed &amp; c_ospeed&lt;br /&gt;+  */&lt;br /&gt;+ switch (dcb.BaudRate) {&lt;br /&gt;+  case 300 : s-&gt;c_ispeed = s-&gt;c_ospeed = B300; break;&lt;br /&gt;+  case 1200 : s-&gt;c_ispeed = s-&gt;c_ospeed = B1200; break;&lt;br /&gt;+  case 2400 : s-&gt;c_ispeed = s-&gt;c_ospeed = B2400; break;&lt;br /&gt;+  case 4800 : s-&gt;c_ispeed = s-&gt;c_ospeed = B4800; break;&lt;br /&gt;+  case 9600 : s-&gt;c_ispeed = s-&gt;c_ospeed = B9600; break;&lt;br /&gt;+  case 19200 : s-&gt;c_ispeed = s-&gt;c_ospeed = B19200; break;&lt;br /&gt;+  case 38400 : s-&gt;c_ispeed = s-&gt;c_ospeed = B38400; break;&lt;br /&gt;+  default : s-&gt;c_ispeed = s-&gt;c_ospeed = B9600;&lt;br /&gt;  }&lt;br /&gt;+ &lt;br /&gt; &lt;br /&gt;- PerfFrequency = Freq.QuadPart;&lt;br /&gt;+ s-&gt;c_cflag = 0;&lt;br /&gt;+ switch (dcb.ByteSize) {&lt;br /&gt;+  case 5 : s-&gt;c_cflag |= CS5; break;&lt;br /&gt;+  case 6 : s-&gt;c_cflag |= CS6; break;&lt;br /&gt;+  case 7 : s-&gt;c_cflag |= CS7; break;&lt;br /&gt;+  case 8 : s-&gt;c_cflag |= CS8; break;&lt;br /&gt;+ }&lt;br /&gt;+ if (dcb.fParity) {&lt;br /&gt;+    s-&gt;c_cflag |= PARENB;&lt;br /&gt;+ }&lt;br /&gt;+ switch (dcb.Parity) {&lt;br /&gt;+  case EVENPARITY : break;&lt;br /&gt;+  case MARKPARITY : break;&lt;br /&gt;+  case NOPARITY : break;&lt;br /&gt;+  case ODDPARITY : s-&gt;c_cflag |= PARODD; break;&lt;br /&gt;+  case SPACEPARITY : break;&lt;br /&gt;+ }&lt;br /&gt;+&lt;br /&gt;+ s-&gt;c_iflag = 0;&lt;br /&gt;+ s-&gt;c_lflag = 0;&lt;br /&gt;+ s-&gt;c_line = 0;&lt;br /&gt;+ s-&gt;c_oflag = 0;&lt;br /&gt; &lt;br /&gt;+ return TRUE; /* ok */&lt;br /&gt;+}&lt;br /&gt; &lt;br /&gt;- if ( modify_mm_timer != 0)&lt;br /&gt;- {&lt;br /&gt;-  if (timeGetDevCaps( &amp;tc, sizeof( tc ) ) == TIMERR_NOERROR ) &lt;br /&gt;-  {&lt;br /&gt;-   wTimerRes = min( max( tc.wPeriodMin, MM_TIMER_INTV ), tc.wPeriodMax );&lt;br /&gt; &lt;br /&gt;-   timeBeginPeriod( wTimerRes );&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;-   msyslog( LOG_INFO, "MM timer resolution: %u..%u ms, set to %u ms\n",&lt;br /&gt;-            tc.wPeriodMin, tc.wPeriodMax, wTimerRes );&lt;br /&gt;-#endif&lt;br /&gt;-  }&lt;br /&gt;-  else&lt;br /&gt;-   msyslog( LOG_ERR, "Failed to get MM timer caps\n" );&lt;br /&gt;- }&lt;br /&gt;+extern int tcflush(int fd, int mode) {&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;- /* init variables with the time now */&lt;br /&gt;- GetSystemTimeAsFileTime(&amp;StartTime);&lt;br /&gt;- LastTimerTime = (((ULONGLONG) StartTime.dwHighDateTime) &lt;&lt; 32) +&lt;br /&gt;-     (ULONGLONG) StartTime.dwLowDateTime;&lt;br /&gt; &lt;br /&gt;- /* init sync objects */&lt;br /&gt;- InitializeCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;- TimerThreadExitRequest = CreateEvent(NULL, FALSE, FALSE, "TimerThreadExitRequest");&lt;br /&gt; &lt;br /&gt;- ClockThreadHandle = CreateThread(NULL, 0, ClockThread, NULL, 0, &amp;tid);&lt;br /&gt;- if (ClockThreadHandle != NULL)&lt;br /&gt;- {&lt;br /&gt;-  /* remember the thread priority is only within the process class */&lt;br /&gt;-  if (!SetThreadPriority(ClockThreadHandle, THREAD_PRIORITY_TIME_CRITICAL)) &lt;br /&gt;-  {&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;-   printf("Error setting thread priority\n");&lt;br /&gt;-#endif&lt;br /&gt;-    }&lt;br /&gt;- }&lt;br /&gt;+return 0;&lt;br /&gt; &lt;br /&gt;- atexit( StopClockThread );&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;-static void StopClockThread(void)&lt;br /&gt;-{ &lt;br /&gt;- if ( wTimerRes )  /* if not 0 then the MM timer has been modified at startup */&lt;br /&gt;- {&lt;br /&gt;-  timeEndPeriod( wTimerRes ); &lt;br /&gt;-  wTimerRes = 0;&lt;br /&gt;-#ifdef DEBUG&lt;br /&gt;-  msyslog( LOG_INFO, "MM timer set to default\n" );&lt;br /&gt;-#endif&lt;br /&gt;- }&lt;br /&gt;+extern int cfsetispeed(struct termios *tio, int speed) {&lt;br /&gt;+  &lt;br /&gt;+return 0;  &lt;br /&gt;+}; &lt;br /&gt;+&lt;br /&gt;+&lt;br /&gt;+extern int cfsetospeed(struct termios *tio, int speed) {&lt;br /&gt;+  &lt;br /&gt;+return 0;  &lt;br /&gt;+}; &lt;br /&gt; &lt;br /&gt;- if (SetEvent(TimerThreadExitRequest) &amp;&amp;&lt;br /&gt;-     WaitForSingleObject(ClockThreadHandle, 10000L) == 0)&lt;br /&gt;- {&lt;br /&gt;-  CloseHandle(TimerThreadExitRequest);&lt;br /&gt;-  TimerThreadExitRequest = NULL;&lt;br /&gt;-&lt;br /&gt;-  CloseHandle(ClockThreadHandle);&lt;br /&gt;-  ClockThreadHandle = NULL;&lt;br /&gt;-&lt;br /&gt;-  DeleteCriticalSection(&amp;TimerCritialSection);&lt;br /&gt;- }&lt;br /&gt;- else&lt;br /&gt;- {&lt;br /&gt;-  msyslog(LOG_ERR, "Failed to stop clock thread.");&lt;br /&gt;-  Sleep( 100 );&lt;br /&gt;- }&lt;br /&gt;-}&lt;br /&gt;&lt;br /&gt;==== ports/winnt/ntpd/win32_io.c ====&lt;br /&gt;2006-10-05 10:20:40+00:00, burnicki at pogo.udel.edu +0 -22&lt;br /&gt;  Set the affinity to a specific CPU for the clock interpolation thread only, not for the whole process.&lt;br /&gt;&lt;br /&gt;--- 1.11/ports/winnt/ntpd/win32_io.c 2006-10-08 03:33:09 -04:00&lt;br /&gt;+++ 1.12/ports/winnt/ntpd/win32_io.c 2006-10-08 03:33:09 -04:00&lt;br /&gt;@@ -17,28 +17,6 @@&lt;br /&gt; &lt;br /&gt; int NT_set_process_priority(void)&lt;br /&gt; {&lt;br /&gt;- DWORD  SingleCPUMask = 0;&lt;br /&gt;- DWORD ProcessAffinityMask, SystemAffinityMask;&lt;br /&gt;- if (!GetProcessAffinityMask(GetCurrentProcess(), &amp;ProcessAffinityMask, &amp;&lt;br /&gt;-   SystemAffinityMask))&lt;br /&gt;-  msyslog(LOG_ERR, "GetProcessAffinityMask: %m");&lt;br /&gt;- else {&lt;br /&gt;-  SingleCPUMask = 1; &lt;br /&gt;-# ifdef DEBUG &lt;br /&gt;- msyslog(LOG_INFO, "System AffinityMask = %x", SystemAffinityMask); &lt;br /&gt;-# endif &lt;br /&gt;-  }&lt;br /&gt;-&lt;br /&gt;- while (SingleCPUMask &amp;&amp; !(SingleCPUMask &amp; SystemAffinityMask)) &lt;br /&gt;-  SingleCPUMask = SingleCPUMask &lt;&lt; 1; &lt;br /&gt;-  &lt;br /&gt;- if (!SingleCPUMask) &lt;br /&gt;-  msyslog(LOG_ERR, "Can't set Processor Affinity Mask"); &lt;br /&gt;- else if (!SetProcessAffinityMask(GetCurrentProcess(), SingleCPUMask)) &lt;br /&gt;-  msyslog(LOG_ERR, "SetProcessAffinityMask: %m"); &lt;br /&gt;-# ifdef DEBUG &lt;br /&gt;- else msyslog(LOG_INFO,"ProcessorAffinity Mask: %x", SingleCPUMask ); &lt;br /&gt;-# endif &lt;br /&gt;  if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)) &lt;br /&gt;   {&lt;br /&gt;   msyslog(LOG_ERR, "SetPriorityClass: %m");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-7368812707216428383?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/7368812707216428383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=7368812707216428383' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7368812707216428383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/7368812707216428383'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/bitkeeper-diffs.html' title='BitKeeper diffs'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-5667013364295876820</id><published>2008-07-18T03:22:00.000-07:00</published><updated>2008-07-18T03:25:17.345-07:00</updated><title type='text'>Sending Hex commands in VC++</title><content type='html'>hi&lt;br /&gt;actually i am working with vb environment and have some basic experience in c++, now our company like to write a dll for handling a mifare reader through serial port in vc++. as for as vb is concerened i am pretty much able to do all the available command sets given by the manufacturer using mscomm control. but i am pretty strucked in vc++ 6.0 i wrote a simple serial communiation program to send a command which basically reads the firmware of the reader and returns it. the manufacturer says the command is FF 00 01 81 82 (hex) i tried this directly by sending it to a wchar variable but it returns some thing which i dont know what is it. for the reference i am giving here the part of the code which handles this condition.    &lt;br /&gt;   &lt;br /&gt;   &lt;span style="color: rgb(128, 0, 128);"&gt; WCHAR str[]={0xFF,0X0,0X1,0X81,0X82};&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;          &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    printf("%x\n",str);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    fSuccess=WriteFile (hcomm,str,sizeof(str),&amp;amp;dwWrittenBytes,&amp;amp;ovWrite);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    if (fSuccess=false)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        printf("failed to Write to comm port");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    printf("written to comm port\n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;    fSuccess=GetOverlappedResult(hcomm,&amp;amp;ovRead,&amp;amp;dwReadBytes,TRUE);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        if (fSuccess=true)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;            lpReadbuff[dwReadBytes]=0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;            printf("read result \n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;            printf("%X\n",lpReadbuff);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;            printf("/n failed");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;        }&lt;/span&gt;&lt;br /&gt;       &lt;br /&gt;the output is&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Handle created&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;set comm state success&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;12fb0c&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;//this is what i get when i tried to print the str which contains the hex command&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;written to comm port&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;read result&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;12FB7C&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;//this is the result returned by the reader&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Press any key to continue&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;hello sir&lt;br /&gt;yes you are correct ,i have to modify it like (fsuccess==FALSE); but now i found the real problem, SetCommState() function failed with last error code as 87. which turned out to be invalid parameter. how to clear this error, i am using buildcommdcb to set the comm settings. i am pasting my full code here. hope will that help to find the pain area in my program.my device settings are b=9600, p=n,data=8,stop=1,flowctrl=hardware.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;  &lt;div class="codesniptitle"&gt;&lt;span style="width: 100%;"&gt;Code Snippet&lt;/span&gt;&lt;/div&gt;  #&lt;span style="font-size:85%;"&gt;include "windows.h"&lt;br /&gt;#include "iostream.h"&lt;br /&gt;#include "stdio.h"&lt;br /&gt;&lt;br /&gt;int main(int argc, char* argv[])&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    HANDLE hcomm;&lt;br /&gt;   &lt;br /&gt;    unsigned char lpReadbuff[1024];&lt;br /&gt;    OVERLAPPED ovRead,ovWrite;&lt;br /&gt;    DCB dcb;&lt;br /&gt;    DWORD dwReadBytes,dwWrittenBytes;&lt;br /&gt;    BOOL fSuccess;&lt;br /&gt;    COMMTIMEOUTS cto;&lt;br /&gt;&lt;br /&gt;    ovRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);&lt;br /&gt;    ovWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;    hcomm=CreateFile("\\\\.\\COM2",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);&lt;br /&gt;&lt;br /&gt;    if (hcomm==INVALID_HANDLE_VALUE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to open handle\n");&lt;br /&gt;        return -1;&lt;br /&gt;    }&lt;br /&gt;    printf("Handle created\n");&lt;br /&gt;&lt;br /&gt;    memset(&amp;amp;ovRead,0,sizeof(ovRead));&lt;br /&gt;    memset(&amp;amp;ovWrite,0,sizeof(ovWrite));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    fSuccess=(SetupComm(hcomm,1024,1024));&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;    if (fSuccess==FALSE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to set comm state \n");&lt;br /&gt;        return -1;&lt;br /&gt;    }&lt;br /&gt;    printf("SetupComm success\n");&lt;br /&gt;&lt;br /&gt;    char initstr[20];&lt;br /&gt;    sprintf(initstr,"9600,N,8,1");&lt;br /&gt;    fSuccess=BuildCommDCB(initstr,&amp;amp;dcb);&lt;br /&gt;&lt;br /&gt;    if (fSuccess==FALSE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to build comm state");&lt;br /&gt;        return -1;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    printf("BuildCommDCB success\n");&lt;br /&gt;&lt;br /&gt;    cto.ReadIntervalTimeout =1000;&lt;br /&gt;    cto.ReadTotalTimeoutConstant =1000;&lt;br /&gt;    cto.ReadTotalTimeoutMultiplier=1000;&lt;br /&gt;    cto.WriteTotalTimeoutConstant=1000;&lt;br /&gt;    cto.WriteTotalTimeoutMultiplier=1000;&lt;br /&gt;   &lt;br /&gt;    fSuccess=SetCommTimeouts(hcomm,&amp;amp;cto);&lt;br /&gt;&lt;br /&gt;    if (fSuccess==FALSE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to set comm timeouts");&lt;br /&gt;        return -1;&lt;br /&gt;    }&lt;br /&gt;    printf("CommTimeout success\n");&lt;br /&gt;    fSuccess=SetCommState(hcomm,&amp;amp;dcb);&lt;br /&gt;    if (fSuccess==FALSE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to set comm state %d \n",GetLastError());&lt;br /&gt;        return -1;&lt;br /&gt;    }&lt;br /&gt;    printf("set comm state success\n");&lt;br /&gt;    unsigned char str[]={0xFF,0X0,0X1,0X83,0X84};&lt;br /&gt;    fSuccess=WriteFile (hcomm,str,sizeof(str),&amp;amp;dwWrittenBytes,&amp;amp;ovWrite);&lt;br /&gt;&lt;br /&gt;    if (fSuccess==FALSE)&lt;br /&gt;    {&lt;br /&gt;        printf("failed to Write to comm port");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    printf("written to comm port\n");&lt;br /&gt;   &lt;br /&gt;    for (int i = 0; i &lt; sizeof(str); i++)&lt;br /&gt;        {&lt;br /&gt;            printf("%02x\n", str[i]);&lt;br /&gt;        }&lt;br /&gt;   &lt;br /&gt;    fSuccess =ReadFile(hcomm,lpReadbuff,sizeof(lpReadbuff),&amp;amp;dwReadBytes ,&amp;amp;ovRead);&lt;br /&gt;   &lt;br /&gt;    if (fSuccess==TRUE)&lt;br /&gt;    {&lt;br /&gt;        printf("read to comm port\n");&lt;br /&gt;        lpReadbuff[dwReadBytes]='\0';&lt;br /&gt;                for (int j=0;j&lt;sizeof(lpReadbuff);j++)&lt;br /&gt;            {&lt;br /&gt;                printf("%02X\t",(unsigned char)lpReadbuff[j]);}&lt;br /&gt;   &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    fSuccess=GetOverlappedResult(hcomm,&amp;amp;ovRead,&amp;amp;dwReadBytes,TRUE);&lt;br /&gt;       &lt;br /&gt;        if (fSuccess==TRUE)&lt;br /&gt;        {&lt;br /&gt;            lpReadbuff[dwReadBytes]=0;&lt;br /&gt;            printf("read result \n");&lt;br /&gt;   &lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            printf("/n failed");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    CloseHandle(hcomm);&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3035002048794942023-5667013364295876820?l=serial-programming-in-win32-os.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://serial-programming-in-win32-os.blogspot.com/feeds/5667013364295876820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3035002048794942023&amp;postID=5667013364295876820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/5667013364295876820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3035002048794942023/posts/default/5667013364295876820'/><link rel='alternate' type='text/html' href='http://serial-programming-in-win32-os.blogspot.com/2008/07/sending-hex-commands-in-vc.html' title='Sending Hex commands in VC++'/><author><name>Manoj Maurya</name><uri>http://www.blogger.com/profile/07820797331061290982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_Xl0qZcuOw_Q/SW48LGzVHzI/AAAAAAAAABY/9jHP4vI9-OI/S220/Image087.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3035002048794942023.post-2367207374043431591</id><published>2008-07-18T03:21:00.000-07:00</published><updated>2008-07-18T03:22:37.876-07:00</updated><title type='text'>Basic Serial Communication</title><content type='html'>&lt;div class="title" msxsl="urn:schemas-microsoft-com:xslt"&gt;Basic Serial Communication&lt;/div&gt;&lt;!--Content type: PSDK_15. Transform: msdneditorial2mtps.xslt.--&gt; &lt;input id="userDataCache" class="userDataStyle" name="userDataCache" type="hidden"&gt;       &lt;p&gt;The interface for a serial device is a combination of generic driver I/O calls and specific communication-related functions. The serial device is treated as a generic, installable stream device for opening, closing, reading from, and writing to the serial port. For configuring the port, the Win32 API supports a set of Comm functions. Windows CE supports most of the Comm functions supported on the desktop.&lt;/p&gt; &lt;p&gt;A word of warning: programming a serial port under Windows CE isn’t like programming one under MS-DOS. You can’t simply find the base address of the serial port and program the registers directly. While there are ways for a program to gain access to the physical memory space, every Windows CE device has a different physical memory map. Even if you solved the access problem by knowing exactly where the serial hardware resided in the memory map, there’s no guarantee the serial hardware is going to be compatible with the 16550-compatible serial interface we’ve all come to know and love in the PC world. In fact, the implementation of the serial port on some Windows CE devices looks nothing like a 16550.&lt;/p&gt; &lt;p&gt;But even if you know where to go in the memory map and the implementation of the serial hardware, you still don’t need to “hack down to the hardware.” The serial port drivers in Windows CE are interrupt-driven designs and are written to support its specific serial hardware. If you have any special needs not provided by the base serial driver, you can purchase the Microsoft Windows CE Platform Builder and write a serial driver yourself. Aside from that extreme case, there’s just no reason not to use the published Win32 serial interface under Windows CE.&lt;/p&gt; &lt;h2&gt;Opening and Closing a Serial Port&lt;/h2&gt; &lt;p&gt;As with all stream device drivers, a serial port device is opened using &lt;i&gt;CreateFile&lt;/i&gt;. The name used needs to follow a specific format: the three letters COM followed by the number of the COM port to open and then a colon. The colon is required under Windows CE and is a departure from the naming convention used for device driver names used on the desktop versions of Windows.&lt;/p&gt; &lt;p&gt;The traditional driver naming convention allowed only 10 instances of a COM port. Windows CE also supports an extended naming convention that allows instance values other than 0 to 9. This convention prefixes the string “\$device\” in front of the driver name and omits the trailing colon. A driver name in this format would look like “\$device\COM1” or “\$device\COM24”.&lt;/p&gt; &lt;p&gt;The following line opens COM port 1 for reading and writing:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl01_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl01');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl01" space="preserve"&gt;hSer = CreateFile (TEXT (“COM1:”), GENERIC_READ | GENERIC_WRITE,&lt;br /&gt;                         0, NULL, OPEN_EXISTING, 0, NULL);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;You must pass a 0 in the sharing parameter as well as in the security attributes and the template file parameters of &lt;i&gt;CreateFile&lt;/i&gt;. Windows CE doesn’t support overlapped I/O for devices, so you can’t pass the &lt;i&gt;FILE_FLAG_OVERLAPPED&lt;/i&gt; flag in the &lt;i&gt;dwFlagsAndAttributes&lt;/i&gt; parameter. The handle returned is either the handle to the opened serial port or &lt;i&gt;INVALID_HANDLE_ VALUE&lt;/i&gt;. Remember that unlike many of the Windows functions, &lt;i&gt;CreateFile&lt;/i&gt; doesn’t return a 0 for a failed open.&lt;/p&gt; &lt;p&gt;You close a serial port by calling &lt;i&gt;CloseHandle&lt;/i&gt;, as in the following:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl02_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl02');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl02" space="preserve"&gt;CloseHandle (hSer);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;You don’t do anything differently when using &lt;i&gt;CloseHandle&lt;/i&gt; to close a serial device than when you use it to close a file handle.&lt;/p&gt; &lt;h2&gt;Reading from and Writing to a Serial Port&lt;/h2&gt; &lt;p&gt;Just as you use the &lt;i&gt;CreateFile&lt;/i&gt; function to open a serial port, you use the functions &lt;i&gt;ReadFile&lt;/i&gt; and &lt;i&gt;WriteFile&lt;/i&gt; to read and write to that serial port. Reading data from a serial port is as simple as making this call to &lt;i&gt;ReadFile&lt;/i&gt;:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl03_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl03');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl03" space="preserve"&gt;INT rc;&lt;br /&gt;DWORD cBytes;&lt;br /&gt;BYTE ch;&lt;br /&gt;rc = ReadFile(hSer, &amp;amp;ch, 1, &amp;amp;cBytes, NULL);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;This call assumes the serial port has been successfully opened with a call to &lt;i&gt;CreateFile&lt;/i&gt;. If the call is successful, one byte is read into the variable &lt;i&gt;ch&lt;/i&gt;, and &lt;i&gt;cBytes&lt;/i&gt; is set to the number of bytes read.&lt;/p&gt; &lt;p&gt;Writing to a serial port is just as simple. The call would look something like the following:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl04_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl04');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl04" space="preserve"&gt;INT rc;&lt;br /&gt;DWORD cBytes;&lt;br /&gt;BYTE ch;&lt;br /&gt;ch = TEXT (‘a’);&lt;br /&gt;rc = WriteFile(hSer, &amp;amp;ch, 1, &amp;amp;cBytes, NULL);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;This code writes the character &lt;i&gt;a&lt;/i&gt; to the serial port previously opened. As you may remember from Chapter 9, both &lt;i&gt;ReadFile&lt;/i&gt; and &lt;i&gt;WriteFile&lt;/i&gt; return &lt;i&gt;TRUE&lt;/i&gt; if successful.&lt;/p&gt; &lt;p&gt;Because overlapped I/O isn’t supported under Windows CE, you should be careful not to attempt to read or write a large amount of serial data from your primary thread or from any thread that has created a window. Because those threads are also responsible for handling the message queues for their windows, they can’t be blocked waiting on a relatively slow serial read or write. Instead, you should use separate threads for reading from and writing to the serial port.&lt;/p&gt; &lt;p&gt;You can also transmit a single character using this function:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl05_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl05');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl05" space="preserve"&gt;BOOL TransmitCommChar (HANDLE hFile, char cChar);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;The difference between the &lt;i&gt;TransmitCommChar&lt;/i&gt; and &lt;i&gt;WriteFile &lt;/i&gt;functions is that &lt;i&gt;TransmitCommChar&lt;/i&gt; puts the character to be transmitted at the front of the transmit queue. When you call &lt;i&gt;WriteFile&lt;/i&gt;, the characters are queued up after any characters that haven’t yet been transmitted by the serial driver. &lt;i&gt;TransmitCommChar&lt;/i&gt; allows you to insert control characters quickly in the stream without having to wait for the queue to empty.&lt;/p&gt; &lt;h2&gt;Asynchronous Serial I/O&lt;/h2&gt; &lt;p&gt;While Windows CE doesn’t support overlapped I/O, there’s no reason why you can’t use multiple threads to implement the same type of overlapped operation. All that’s required is that you launch separate threads to handle the synchronous I/O operations while your primary thread goes about its business. In addition to using separate threads for reading and writing, Windows CE supports the Win32 &lt;i&gt;WaitCommEvent&lt;/i&gt; function that blocks a thread until one of a group of preselected serial events occurs. I’ll demonstrate how to use separate threads for reading and writing a serial port in the CeChat example program later in this chapter.&lt;/p&gt; &lt;p&gt;You can make a thread wait on serial driver events by means of the following three functions:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl06_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl06');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl06" space="preserve"&gt;BOOL SetCommMask (HANDLE hFile, DWORD dwEvtMask);&lt;br /&gt;BOOL GetCommMask (HANDLE hFile, LPDWORD lpEvtMask);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;and&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl07_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl07');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl07" space="preserve"&gt;BOOL WaitCommEvent (HANDLE hFile, LPDWORD lpEvtMask,&lt;br /&gt;                          LPOVERLAPPED lpOverlapped);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;To wait on an event, you first set the event mask using &lt;i&gt;SetCommMask&lt;/i&gt;. The parameters for this function are the handle to the serial device and a combination of the following event flags:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;EV_BREAK&lt;/b&gt; A break was detected.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_CTS&lt;/b&gt; The Clear to Send (CTS) signal changed state.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_DSR&lt;/b&gt; The Data Set Ready (DSR) signal changed state.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_ERR&lt;/b&gt; An error was detected by the serial driver.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_RLSD&lt;/b&gt; The Receive Line Signal Detect (RLSD) line changed state.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_RXCHAR&lt;/b&gt; A character was received.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_RXFLAG&lt;/b&gt; An event character was received.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;EV_TXEMPTY&lt;/b&gt; The transmit buffer is empty.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;You can set any or all of the flags in this list at the same time using &lt;i&gt;SetCommMask&lt;/i&gt;. You can query the current event mask using &lt;i&gt;GetCommMask&lt;/i&gt;.&lt;/p&gt; &lt;p&gt;To wait on the events specified by &lt;i&gt;SetCommMask&lt;/i&gt;, you call &lt;i&gt;WaitCommEvent&lt;/i&gt;. The parameters for this call are the handle to the device; a pointer to a &lt;i&gt;DWORD&lt;/i&gt; that will receive the reason the call returned; and &lt;i&gt;lpOverlapped&lt;/i&gt;, which under Windows CE must be set to &lt;i&gt;NULL&lt;/i&gt;. The code fragment that follows waits on a character being received or an error. The code assumes that the serial port has already been opened and that the handle is contained in &lt;i&gt;hComPort&lt;/i&gt;.&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl08_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl08');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl08" space="preserve"&gt;DWORD dwMask;&lt;br /&gt;// Set mask and wait.&lt;br /&gt;SetCommMask (hComPort, EV_RXCHAR | EV_ERR);&lt;br /&gt;if (WaitCommEvent (hComPort, &amp;amp;dwMask, 0) {&lt;br /&gt;// Use the flags returned in dwMask to determine the reason&lt;br /&gt;// for returning.&lt;br /&gt;Switch (dwMask) {&lt;br /&gt;case EV_RXCHAR:&lt;br /&gt;//Read character.&lt;br /&gt;break;&lt;br /&gt; case EV_ERR:&lt;br /&gt;// Process error.&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt; &lt;h2&gt;Configuring the Serial Port&lt;/h2&gt; &lt;p&gt;Reading from and writing to a serial port is fairly straightforward, but you also must configure the port for the proper baud rate, character size, and so forth. The masochist could con-figure the serial driver through device I/O control (IOCTL) calls, but the &lt;i&gt;IoCtl &lt;/i&gt;codes necessary for this are exposed only in the Platform Builder, not the Software Development Kit. Besides, there’s a simpler method.&lt;/p&gt; &lt;p&gt;You can go a long way in configuring the serial port using two functions, &lt;i&gt;GetCommState&lt;/i&gt; and &lt;i&gt;SetCommState&lt;/i&gt;, prototyped here:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl09_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl09');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl09" space="preserve"&gt;BOOL SetCommState (HANDLE hFile, LPDCB lpDCB);&lt;br /&gt;BOOL GetCommState (HANDLE hFile, LPDCB lpDCB);&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;Both these functions take two parameters: the handle to the opened serial port and a pointer to a &lt;i&gt;DCB&lt;/i&gt; structure. The extensive &lt;i&gt;DCB&lt;/i&gt; structure is defined as follows:&lt;/p&gt;&lt;div class="" id="ctl00_rs1_mainContentContainer_ctl10_"&gt;&lt;div class="CodeSnippetTitleBar"&gt;&lt;div class="CopyCodeButton"&gt;&lt;a class="copyCode" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl10');"&gt;&lt;img src="http://i.msdn.microsoft.com/Platform/Controls/CodeSnippet/resources/copy_off.gif" align="middle" border="0" height="9" /&gt; Copy Code&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl10" space="preserve"&gt;typedef struct _DCB {&lt;br /&gt;DWORD DCBlength;&lt;br /&gt;DWORD BaudRate;&lt;br /&gt;DWORD fBinary: 1;&lt;br /&gt;DWORD fParity: 1;&lt;br /&gt;DWORD fOutxCtsFlow:1;&lt;br /&gt;DWORD fOutxDsrFlow:1;&lt;br /&gt;DWORD fDtrControl:2;&lt;br /&gt;DWORD fDsrSensitivity:1;&lt;br /&gt;DWORD fTXContinueOnXoff:1;&lt;br /&gt;DWORD fOutX: 1;&lt;br /&gt;DWORD fInX: 1;&lt;br /&gt;DWORD fErrorChar: 1;&lt;br /&gt;DWORD fNull: 1;&lt;br /&gt;DWORD fRtsControl:2;&lt;br /&gt;DWORD fAbortOnError:1;&lt;br /&gt;DWORD fD
