<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[Linux在串口下接收数据时忽略了0X0D问题]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 17 Jul 2009 03:13:28 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	今天在做GSM模块收发短信中，遇到了一个问题，0X0D和0X0A会自动只收到0X0A，在网上查了下，果真有这个问题。<br/><br/>现在把原因及解决方法写出来：<br/><br/> <br/><br/>在我们发送字符0x0d的时候，往往接受端得到的字符是0x0a 这是怎么回事，原因是在串口配置中c_iflag和c_oflag中存在从NL-CR 和CR-NL的映射，也就是说，串口能够把回车和换行看成一个字符，所以，此时我们应该屏蔽掉这些，用options.c_oflag &amp;=~(INLCR&#124;IGNCR&#124;ICRNL&#124;);和options.c_oflag &amp;=~(ONLCR&#124;OCRNL); 进行配置。<br/><br/> <br/><br/>还有一个例子：<br/><br/>&nbsp;&nbsp;struct&nbsp;&nbsp;termios Opt;<br/>&nbsp;&nbsp;int&nbsp;&nbsp;m_fd = open(&quot;/dev/ttyAM1&quot;, O_RDWR &#124; O_NOCTTY &#124; O_NDELAY);<br/>&nbsp;&nbsp;if(m_fd==-1) perror(&quot;lcd_drawlib: Cannot open ttyAM1! &#92;n&quot; ) ;<br/>&nbsp;&nbsp;//设置 串口的NL-CR 和CR-NL 的映射<br/>&nbsp;&nbsp;tcgetattr(m_fd,&amp;Opt);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //首先读取系统默认设置options<br/>&nbsp;&nbsp;Opt.c_iflag &amp;=~(INLCR&#124;IGNCR&#124;ICRNL);<br/>&nbsp;&nbsp;Opt.c_oflag &amp;=~(ONLCR&#124;OCRNL);&nbsp;&nbsp;<br/>&nbsp;&nbsp;tcflush(m_fd,TCIFLUSH); /* Update the options and do it NOW */&nbsp;&nbsp;&nbsp;&nbsp;//刷新和立刻写进去<br/>//设置波特率&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;cfsetispeed(&amp;Opt,B9600);<br/>&nbsp;&nbsp;cfsetospeed(&amp;Opt,B9600);<br/>&nbsp;&nbsp;tcsetattr(m_fd,TCSANOW,&amp;Opt);<br/>&nbsp;&nbsp;write(m_fd, &quot;&#92;x0a&quot;, 1);<br/>&nbsp;&nbsp;close(m_fd);<br/><br/><br/>参考资料：http://www.oldlinux.org/oldlinux/viewthread.php?tid=7903，http://www.idcnews.net/html/edu/20070101/285934.html注意：参考中Opt.c_iflag写错，我已进行了修改
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Linux在串口下接收数据时忽略了0X0D问题]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>