Android串口通信:串口读写实例

把之前在新浪博客里写的分享也备份移植到CSDN博客,之前本文博客地址是:http://blog.sina.com.cn/s/blog_14ed06d6c0102wqdl.html在Android串口通信:基本知识梳理(http://gqdy365.iteye.com/admin/blogs/2188846)的基础上,我结合我项目中使用串口的实例,进行总结; Android使用jni直接
摘要由CSDN通过智能技术生成

把之前在新浪博客里写的分享也备份移植到CSDN博客,之前本文博客地址是:http://blog.sina.com.cn/s/blog_14ed06d6c0102wqdl.html

在Android串口通信:基本知识梳理(http://gqdy365.iteye.com/admin/blogs/2188846)的基础上,我结合我项目中使用串口的实例,进行总结; 

Android使用jni直接进行串口设备的读写网上已经有开源项目了,本文是基于网上的开源项目在实际项目中的使用做的调整和优化; 
Google串口开源项目见:https://code.google.com/p/android-serialport-api/ 

下面是我项目中的相关代码及介绍: 

1、SerialPort.cpp 

Java代码    收藏代码
  1.   
  2. #include   
  3. #include   
  4. #include   
  5. #include <<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">assert.h>  
  6.   
  7. #include   
  8. #include   
  9. #include   
  10. #include   
  11. #include   
  12. #include   
  13. #include   
  14.   
  15. #include "android/log.h"  
  16. static const char *TAG "serial_port" 
  17. #define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO,  TAG, fmt, ##args)  
  18. #define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args)  
  19. #define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args)  
  20.   
  21. static speed_t getBaudrate(jint baudrate)  
  22.     switch (baudrate)  
  23.     case 0 
  24.         return B0;  
  25.     case 50 
  26.         return B50;  
  27.     case 75 </
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-每天进步一点点-

你的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值