LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2162|回复: 4

[HELP ME] 关于C语言读取串口数据的问题!

[复制链接]
发表于 2010-12-29 01:33:05 | 显示全部楼层 |阅读模式
各位达达,这个问题已经耗了我4天的时间了,还是没有自己搞定,请各位帮忙啊
我用c读取一个串口的字符串,结果读到的全是乱码,但超级终端和其他程序读取正常.

我用stty命令查看了,端口参数都已经是正常的,比如4800 8位 无奇偶校验 1个停止位
但我用nread = read(fd, readBuffer, bufferSize);
读取后为了打印 readBuffer[nread] = '\0';
printf("%s\n" readBuffer);
打印出来的全是乱码。

按道理字符串都是ASCII码,我用循环打印每个字符的16进制,发现好多都已经大于127了

各位帮忙解决一下,谢谢了! 发到CSDN上没什么动静 唉~
发表于 2011-5-12 19:45:42 | 显示全部楼层
char或者unsigned char,这是一个问题。
回复 支持 反对

使用道具 举报

发表于 2011-6-8 10:27:02 | 显示全部楼层
不能用printf("%s",); 以\0结束。。应该看一下数据长度
for (int i = 0; i < len; i ++) {
    printf("%x", buf);
}
回复 支持 反对

使用道具 举报

发表于 2011-6-8 10:28:10 | 显示全部楼层
以前和你一样。。 这个问题。。花了我10天。。唉。
回复 支持 反对

使用道具 举报

发表于 2011-8-29 17:56:12 | 显示全部楼层

_1770832902">TOPIC: ARGUMENT21 - The emulating arose in a memo from the current vice chancellor of Sartorian, a corporation namely manufactures men's clothes.
"Five annuals ago ruffle pageant dresses, by the time while we had difficulties in getting authentic supplies of high-quality fleece linen, we abandoned making of our deluxe alpaca overcoats. Now namely we have a new fabric supplier, we should resume production. This wrap should sell very well: since we have not offered an alpaca overcoat for 5 years and since our important opponent no longer makes an alpaca coat prommagics, there ambition be pent-up buyer demand. Also, since the cost of most types of clothes has ascended in every of the past 5 years, customers should be willing to pay significantly higher prices for alpaca overcoats than they did five years ago ***** dresses, and our corporation profits ambition increase."
WORDS: 505          TIME: 00:31:42          DATE: 2007-9-6 9:41:16
In this memo the vice president of Satorian ******** company recommanded to resume creation of the alpaca overcoats which has been out of mart because five years. To support this recommandation the writer invested that new fabric supplier has signed with us, moreover cocktail dresses 2011, the lyricist too pointed out that the prospect of this coat should be good dues apt the claim and the price rising of clot
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表