使用说明:
1,将serialport模块导入项目中(导入后最好先单独编译此模块一次)。
---先找个地方定义一个串口对象,用以读写和关闭。如:SerialPort mSerialPort;---
2,打开串口:getSerialPort()
3,读数据:int len/*返回读到的长度*/ = mSerialPort.getInputStream().read(recvBuf/*字节数组,接收缓冲*/);
4,写数据:mSerialPort.getOutputStream().write(sendBytes/*字节数组*/);
3,关闭串口:closeSerialPort()
-------------打开方法---------------
private SerialPort getSerialPort() throws SecurityException, IOException, InvalidParameterException {
// mSerialPort 这个需要定义在别的地方,比如网络管理类,或全局都可以。
if (mSerialPort == null) {
/* Read serial port parameters */
// SharedPreferences sp = getSharedPreferences("android_serialport_api.sample_preferences", MODE_PRIVATE);
// String path = sp.getString("DEVICE", "");
// int baudrate = Integer.decode(sp.getString("BAUDRATE", "-1"));
//
// /* Check parameters */
// if ( (path.length() == 0) || (baudrate == -1)) {
// throw new InvalidParameterException();
// }
String path = "/dev/ttyS0";
int baudrate = 115200;
// }
/* Open the serial port */
mSerialPort = new SerialPort(new File(path), baudrate, 0);
}
return mSerialPort;
}
-------------关闭方法---------------
private void closeSerialPort() {
if (mSerialPort != null) {
mSerialPort.close();
mSerialPort = null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
android seriaport (365个子文件)
feature_tests.bin 90KB
feature_tests.bin 90KB
feature_tests.bin 90KB
CMakeDetermineCompilerABI_CXX.bin 86KB
CMakeDetermineCompilerABI_CXX.bin 86KB
CMakeDetermineCompilerABI_CXX.bin 86KB
CMakeDetermineCompilerABI_C.bin 86KB
CMakeDetermineCompilerABI_C.bin 86KB
CMakeDetermineCompilerABI_C.bin 86KB
feature_tests.bin 14KB
feature_tests.bin 14KB
feature_tests.bin 14KB
feature_tests.bin 13KB
feature_tests.bin 13KB
feature_tests.bin 13KB
CMakeDetermineCompilerABI_CXX.bin 10KB
CMakeDetermineCompilerABI_C.bin 10KB
CMakeDetermineCompilerABI_CXX.bin 10KB
CMakeDetermineCompilerABI_CXX.bin 10KB
CMakeDetermineCompilerABI_C.bin 10KB
CMakeDetermineCompilerABI_C.bin 10KB
CMakeDetermineCompilerABI_CXX.bin 9KB
CMakeDetermineCompilerABI_CXX.bin 9KB
CMakeDetermineCompilerABI_CXX.bin 9KB
CMakeDetermineCompilerABI_C.bin 9KB
CMakeDetermineCompilerABI_C.bin 9KB
CMakeDetermineCompilerABI_C.bin 9KB
CMakeDetermineCompilerABI_CXX.bin 8KB
CMakeDetermineCompilerABI_CXX.bin 8KB
CMakeDetermineCompilerABI_CXX.bin 8KB
CMakeDetermineCompilerABI_C.bin 8KB
CMakeDetermineCompilerABI_C.bin 8KB
CMakeDetermineCompilerABI_C.bin 8KB
feature_tests.bin 8KB
feature_tests.bin 8KB
feature_tests.bin 8KB
SerialPort.c 5KB
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
feature_tests.c 762B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
cmake.check_cache 86B
CMakeCXXCompiler.cmake 6KB
CMakeCXXCompiler.cmake 6KB
CMakeCXXCompiler.cmake 6KB
CMakeCXXCompiler.cmake 6KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCXXCompiler.cmake 5KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
CMakeCCompiler.cmake 3KB
cmake_install.cmake 2KB
cmake_install.cmake 2KB
cmake_install.cmake 2KB
cmake_install.cmake 2KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
cmake_install.cmake 1KB
CMakeSystem.cmake 444B
CMakeSystem.cmake 444B
CMakeSystem.cmake 444B
共 365 条
- 1
- 2
- 3
- 4
maoqx
- 粉丝: 0
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0