树莓派 多java读取串口数据实例读取

使用树莓派和pc通过网线直连, 不用串口 - tedeum - ITeye技术网站
博客分类:
入手一个红版512M树莓派,准备用来做媒体中心,这里记录下使用网线直连PC进行配置的经验和童靴们分享。
本人使用的是win7系统,其实准备的东西也很简单的,就一个putty和一个Win32DiskImager,一根网线。
树莓派和PC通过网线直连
树莓派刷系统在windows下很简单的,用win32DiskImager就write就行了,可是刚拿到手的时侯,手边没有合适的显示器或者相关的线材。这要怎么配置呢,网上有用网线和串口进行连接的,可是实际上有一个普通网线就可以了,不需要是交叉线。方法是把刷了系统的SD卡插入电脑,打开里面cmdline.txt,在里面加入下面的语句ip=192.168.0.2,这个就是设置的pi的ip地址,ip地址要怎么设呢?要分两种情况,1)如果你的本地连接设置了ip,那么pi的ip就设置为最后一位不一样就行了;2)如果本地连接没有设置IP,那么pi的ip就设置为:
169.254.0.2
好了,保存后给pi装上卡,可以用这个ip进行配置了。
好多人最近都卖了树莓派啊,这个东西到底是啥呢?可以看作是一个arm开发板,嵌入式电脑。
浏览: 215083 次
来自: 昆明
tedeum 写道produces 注意版本问题,老的版本不支 ...
并没有下载地址啊
请教一下博主,Geoserver的相关开发资料从哪找得到,官方 ...
问下 这是什么原因 Connection attempt us ...
http://download.csdn.net/detail ...二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(4895)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'Mac下用USB转串口连接树莓派的方法',
blogAbstract:'在网上搜了下,大部分用串口连接RPI都是在windows下做的,在此贡献一个在Mac下连接的方法。1、搞到一个USB转串口的设备(不是废话吗),此类设备基本上有三种主流芯片:PL2302、CP2102、FT232,看了下RPI的设备兼容列表,最终选择了PL2302这款,这个片子价钱便宜,配合RPI也稳定,在ML下还有对应的驱动。',
blogTag:'mac,raspberry,pi',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:7,
permalink:'blog/static/',
commentCount:2,
mainCommentCount:2,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list} 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
树莓派串口调试描述
下载积分:900
内容提示:树莓派串口调试描述
文档格式:DOCX|
浏览次数:8|
上传日期: 14:43:05|
文档星级:
该用户还上传了这些文档
树莓派串口调试描述
官方公共微信C实现树莓派串口通信(附源码)_树莓派RaspberryPi讨论区_云汉芯城电子工程师论坛-云汉芯城电子工程师社区
发表于& 20:56:52
参考了IBM的文章,代码太老了编译不通过,做了些修改总算是能跑起来了。
Win8.1-PL2303-树莓派,9600波特率通信正常。
论坛的代码块可能会屏蔽部分代码,若有问题请参考我博客:/wjne/p/3804904.html
(IBM原文:/developerworks/cn/linux/l-serials/)
&stdlib.h&
&unistd.h&
&sys/types.h&
&sys/stat.h&
&termios.h&
&string.h&
#define TRUE 0
#define FALSE -1
int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,
B38400, B19200, B9600, B4800, B2400, B1200, B300, };
int name_arr[] = {38400,
void set_speed(int fd, int speed){
struct termios
tcgetattr(fd, &Opt);
for( i= 0;
i & sizeof(speed_arr) / sizeof(int);
if(speed == name_arr[i]){
tcflush(fd, TCIOFLUSH);
cfsetispeed(&Opt, speed_arr[i]);
cfsetospeed(&Opt, speed_arr[i]);
status = tcsetattr(fd, TCSANOW, &Opt);
if (status != 0)
perror("tcsetattr fd1");
tcflush(fd,TCIOFLUSH);
设置串口数据位,停止位和效验位
打开的串口文件句柄*
databits 类型
int 数据位
取值 为 7 或者8*
stopbits 类型
int 停止位
取值为 1 或者2*
效验类型 取值为N,E,O,,S
int set_Parity(int fd,int databits,int stopbits,int parity){
if( tcgetattr( fd,&options)
perror("SetupSerial 1");
return FALSE;
options.c_cflag &= ~CSIZE;
switch (databits){ /*设置数据位数*/
options.c_cflag |= CS7;
case 8:options.c_cflag |= CS8;
default:fprintf(stderr,"Unsupported data sizen");return FALSE;
switch (parity){
options.c_cflag &= ~PARENB;
/* Clear parity enable */
options.c_iflag &= ~INPCK;
/* Enable parity checking */
options.c_cflag |= (PARODD | PARENB);
/* 设置为奇效验*/
options.c_iflag |= INPCK;
/* Disnable parity checking */
options.c_cflag |= PARENB;
/* Enable parity */
options.c_cflag &= ~PARODD;
/* 转换为偶效验*/
options.c_iflag |= INPCK;
/* Disnable parity checking */
/*as no parity*/
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
fprintf(stderr,"Unsupported parityn");
return (FALSE);
/* 设置停止位*/
switch (stopbits){
options.c_cflag &= ~CSTOPB;
options.c_cflag |= CSTOPB;
fprintf(stderr,"Unsupported stop bitsn");
return FALSE;
/* Set input parity option */
if (parity != 'n')
options.c_iflag |= INPCK;
options.c_cc[VTIME] = 150; // 15 seconds
options.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
if(tcsetattr(fd,TCSANOW,&options) != 0){
perror("SetupSerial 3");
return FALSE;
return TRUE;
int OpenPort(char *Dev){
int fd = open( Dev, O_RDWR );
//| O_NOCTTY | O_NDELAY
if (-1 == fd){ /*设置数据位数*/
perror("Can't Open Serial Port");
return -1;
int main(int argc, char **argv){
char buff[512];
char *dev = "/dev/ttyAMA0";
fd = OpenPort(dev);
set_speed(fd,9600);
printf("Can't Open Serial Port!n");
if(set_Parity(fd,8,1,'N')== FALSE){
printf("Set Parity Errorn");
while((nread = read(fd,buff,512))&0){
printf("n长度:%dn",nread);
buff[nread+1]='';
printf("n内容为:%sn",buff);
memset(buff,0,512);
close(fd);
注意:论坛代码块插件屏蔽了(反斜杠n)
原创技术先锋,加分鼓励!
这个家伙很懒,什么也没有留下
上一帖子:
下一帖子:
发表于& 21:15:04
调试时候发现输出的数据和发送的不一致
第一次发送222,pi接收后计算的长度是3,输出到终端的是222
第二次发送1,pi接收后计算的长度是1,输出到终端的却是12
长度正确,但是输出显示不正常,问题出在使用了printf函数没有考虑缓冲区
所以选择了在读取数据后用memset(buff,0,512);清空缓冲区
这个家伙很懒,什么也没有留下
发表于& 21:20:36
有兴趣的可以看下这篇文章
http://blog.csdn.net/seton040/article/details/4504825
这个家伙很懒,什么也没有留下
边城工作室
发表于& 22:34:35
这个家伙很懒,什么也没有留下
发表于& 07:47:15
顶起。。。
/?spm=a1z10.1-c.0.0.pt2dA1</stron
发表于& 08:47:03
谢谢分享 &顶
这个家伙很懒,什么也没有留下
发表于& 09:26:34
不错,有点意思,分数送上
发表于& 09:28:41
这个家伙很懒,什么也没有留下
发表于& 21:48:31
我的树莓派用这个程序怎么可以向外发送数据,但收不到数据,这是为什么
这个家伙很懒,什么也没有留下
发表于& 08:29:50
不错,有点意思
日拱一卒,功不唐捐 为者常成,行者常至
兰生幽谷,不为莫服而不芳;舟行江海,不为莫乘而不浮;君子行义,不为莫知而止休
发表于& 11:23:35
是直接把GPIO口当成串口来操作的吗?
可否外接更多的串口模块
把唐砖看了一遍又一遍

我要回帖

更多关于 arduino读取串口数据 的文章

 

随机推荐