<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>方式 &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/%E6%96%B9%E5%BC%8F/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Sun, 03 May 2020 13:26:24 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>不要指望用同步方式同时收、发串口数据</title>
		<link>https://www.codelast.com/%e4%b8%8d%e8%a6%81%e6%8c%87%e6%9c%9b%e7%94%a8%e5%90%8c%e6%ad%a5%e6%96%b9%e5%bc%8f%e5%90%8c%e6%97%b6%e6%94%b6%e3%80%81%e5%8f%91%e4%b8%b2%e5%8f%a3%e6%95%b0%e6%8d%ae/</link>
					<comments>https://www.codelast.com/%e4%b8%8d%e8%a6%81%e6%8c%87%e6%9c%9b%e7%94%a8%e5%90%8c%e6%ad%a5%e6%96%b9%e5%bc%8f%e5%90%8c%e6%97%b6%e6%94%b6%e3%80%81%e5%8f%91%e4%b8%b2%e5%8f%a3%e6%95%b0%e6%8d%ae/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 14 Sep 2010 02:40:50 +0000</pubDate>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[串口]]></category>
		<category><![CDATA[同时]]></category>
		<category><![CDATA[同步]]></category>
		<category><![CDATA[收发]]></category>
		<category><![CDATA[数据]]></category>
		<category><![CDATA[方式]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=73</guid>

					<description><![CDATA[<p>
	&#160;</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	很久以前记下的一条血的教训，当时折腾了很长时间，才从书上看到这个结论。串口通信时，如果你希望数据到达能监听到，那你可能会为了简单，而使用同步方式来实现数据的收发，用SetCommEvent来设置数据到达事件提醒，在监听线程中使用WaitCommEvent来等待数据的到达，数据一直没来，这时你又想要发送数据，于是用WriteFile来写，但此时你会发现，程序会锁死，为什么？如何解决？</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
<span id="more-73"></span></p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	据书上说，可能的原因是：同步方式下，一个API函数还没有执行完的时候，是会一直阻塞在一处的，这就导致了在数据一直没有到达的时候，监听线程中的WaitCommEvent函数永远阻塞，所以当你想要再WriteFile，就进行不下去了，程序就会锁死。</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	据书上说，解决方案就是将同步改成异步。想要在同步方式下实现，书上说还没发现有什么办法可以解决。就我的惨痛经历来说，我试了N种方法，也没有发现解决办法，最后只能改成异步模式，就把问题解决了。用同步模式是为了图简单，结果反而造成了巨大的麻烦，还是要用回异步模式，血的教训。</p>
<p>	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#160;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" />&#8230; <a href="https://www.codelast.com/%e4%b8%8d%e8%a6%81%e6%8c%87%e6%9c%9b%e7%94%a8%e5%90%8c%e6%ad%a5%e6%96%b9%e5%bc%8f%e5%90%8c%e6%97%b6%e6%94%b6%e3%80%81%e5%8f%91%e4%b8%b2%e5%8f%a3%e6%95%b0%e6%8d%ae/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
	&nbsp;</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	很久以前记下的一条血的教训，当时折腾了很长时间，才从书上看到这个结论。串口通信时，如果你希望数据到达能监听到，那你可能会为了简单，而使用同步方式来实现数据的收发，用SetCommEvent来设置数据到达事件提醒，在监听线程中使用WaitCommEvent来等待数据的到达，数据一直没来，这时你又想要发送数据，于是用WriteFile来写，但此时你会发现，程序会锁死，为什么？如何解决？</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
<span id="more-73"></span></p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	据书上说，可能的原因是：同步方式下，一个API函数还没有执行完的时候，是会一直阻塞在一处的，这就导致了在数据一直没有到达的时候，监听线程中的WaitCommEvent函数永远阻塞，所以当你想要再WriteFile，就进行不下去了，程序就会锁死。</p>
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 9px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(77, 77, 77); ">
	据书上说，解决方案就是将同步改成异步。想要在同步方式下实现，书上说还没发现有什么办法可以解决。就我的惨痛经历来说，我试了N种方法，也没有发现解决办法，最后只能改成异步模式，就把问题解决了。用同步模式是为了图简单，结果反而造成了巨大的麻烦，还是要用回异步模式，血的教训。</p>
<p>	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e4%b8%8d%e8%a6%81%e6%8c%87%e6%9c%9b%e7%94%a8%e5%90%8c%e6%ad%a5%e6%96%b9%e5%bc%8f%e5%90%8c%e6%97%b6%e6%94%b6%e3%80%81%e5%8f%91%e4%b8%b2%e5%8f%a3%e6%95%b0%e6%8d%ae/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
