资源简介
Android与串口链接发送以及接收信息,可直接用,
代码片段和文件信息
/*
* Copyright 2009-2011 Cedric Priscal
*
* Licensed under the Apache License Version 2.0 (the “License“);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing software
* distributed under the License is distributed on an “AS IS“ BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include
#include
#include
#include
#include
#include
#include
#include “SerialPort.h“
#include “android/log.h“
static const char *TAG=“serial_port“;
#define LOGI(fmt args...) __android_log_print(ANDROID_LOG_INFO TAG fmt ##args)
#define LOGD(fmt args...) __android_log_print(ANDROID_LOG_DEBUG TAG fmt ##args)
#define LOGE(fmt args...) __android_log_print(ANDROID_LOG_ERROR TAG fmt ##args)
static speed_t getBaudrate(jint baudrate)
{
switch(baudrate) {
case 0: return B0;
case 50: return B50;
case 75: return B75;
case 110: return B110;
case 134: return B134;
case 150: return B150;
case 200: return B200;
case 300: return B300;
case 600: return B600;
case 1200: return B1200;
case 1800: return B1800;
case 2400: return B2400;
case 4800: return B4800;
case 9600: return B9600;
case 19200: return B19200;
case 38400: return B38400;
case 57600: return B57600;
case 115200: return B115200;
case 230400: return B230400;
case 460800: return B460800;
case 500000: return B500000;
case 576000: return B576000;
case 921600: return B921600;
case 1000000: return B1000000;
case 1152000: return B1152000;
case 1500000: return B1500000;
case 2000000: return B2000000;
case 2500000: return B2500000;
case 3000000: return B3000000;
case 3500000: return B3500000;
case 4000000: return B4000000;
default: return -1;
}
}
/*
* Class: android_serialport_SerialPort
* Method: open
* Signature: (Ljava/lang/String;II)Ljava/io/FileDescriptor;
*/
JNIEXPORT jobject JNICALL Java_android_1serialport_1api_SerialPort_open
(JNIEnv *env jclass thiz jstring path jint baudrate jint flags)
{
int fd;
speed_t speed;
jobject mFileDescriptor;
/* Check arguments */
{
speed = getBaudrate(baudrate);
if (speed == -1) {
/* TODO: throw an exception */
LOGE(“Invalid baudrate“);
return NULL;
}
}
/* Opening device */
{
jboolean iscopy;
const char *path_utf = (*env)->GetStringUTFChars(env path &iscopy);
LOGD(“Opening serial port %s with flags 0x%x“ path_utf O_RDWR | flags);
fd = open(path_utf O_RDWR | flags);
LOGD(“open() fd = %d“ fd);
(*env)->ReleaseStringUTFChars(env path path_utf);
if (fd == -1)
{
/* Throw an exception */
LOGE(“Cannot open port“);
/* TODO: throw an exception */
return NULL;
}
}
/* Configure device */
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 466 2016-05-11 00:27 ComAssistant-master\.classpath
文件 378 2016-05-11 00:27 ComAssistant-master\.gitattributes
文件 904 2016-05-11 00:27 ComAssistant-master\.gitignore
文件 815 2016-05-11 00:27 ComAssistant-master\.project
文件 53 2016-05-11 00:27 ComAssistant-master\.settings\org.eclipse.core.resources.prefs
文件 203 2016-05-11 00:27 ComAssistant-master\.settings\org.eclipse.jdt.core.prefs
文件 2421 2016-05-11 00:27 ComAssistant-master\AndroidManifest.xm
文件 786 2016-05-11 00:27 ComAssistant-master\jni\Android.mk
文件 35 2016-05-11 00:27 ComAssistant-master\jni\Application.mk
文件 90 2016-05-11 00:27 ComAssistant-master\jni\gen_SerialPort_h.sh
文件 4589 2016-05-11 00:27 ComAssistant-master\jni\SerialPort.c
文件 745 2016-05-11 00:27 ComAssistant-master\jni\SerialPort.h
文件 37888 2016-05-11 00:27 ComAssistant-master\libs\armeabi\libserial_port.so
文件 37892 2016-05-11 00:27 ComAssistant-master\libs\armeabi-v7a\libserial_port.so
文件 130344 2016-05-11 00:27 ComAssistant-master\libs\core.jar
文件 21941 2016-05-11 00:27 ComAssistant-master\libs\library.jar
文件 210289 2016-05-11 00:27 ComAssistant-master\libs\push.jar
文件 9152 2016-05-11 00:27 ComAssistant-master\libs\x86\libserial_port.so
文件 86716 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi\libserial_port.so
文件 33944 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi\objs\serial_port\SerialPort.o
文件 9667 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi\objs\serial_port\SerialPort.o.d
文件 86592 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi-v7a\libserial_port.so
文件 33436 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi-v7a\objs\serial_port\SerialPort.o
文件 9671 2016-05-11 00:27 ComAssistant-master\obj\local\armeabi-v7a\objs\serial_port\SerialPort.o.d
文件 33974 2016-05-11 00:27 ComAssistant-master\obj\local\x86\libserial_port.so
文件 33104 2016-05-11 00:27 ComAssistant-master\obj\local\x86\objs\serial_port\SerialPort.o
文件 9842 2016-05-11 00:27 ComAssistant-master\obj\local\x86\objs\serial_port\SerialPort.o.d
文件 1248 2016-05-11 00:27 ComAssistant-master\proguard.cfg
文件 361 2016-05-11 00:27 ComAssistant-master\project.properties
文件 8370 2016-05-11 00:27 ComAssistant-master\res\drawable-hdpi\ic_launcher.png
............此处省略47个文件信息
- 上一篇:Java多线程实现生产者消费者
- 下一篇:基于二次误差度量的网格简化
相关资源
- 简单的java多人聊天小程序
- 网页木马全集
- Java Number Cruncher
- java网络对战的国际象棋源码
- 基于Android的文件管理系统源代码
- Java三种生成条形码的源码barcode4j、
- 截屏源码截屏源码
- Android 调用前摄像头拍照存储,根据打
- android ListView显示和隐藏二级内容
- android TestUsb
- android 滑动选择日期jar包
- AndroidRClassGenerator
- android定时开关机或重启的代码
- java简单文件管理系统源码
- Android wifi列表显示
- 简单的JAVA 3D球编码
- android书架效果,可以触底刷新
- 异常捕获或自动重启app
- 闹钟java源码
- Android图片涂鸦源码
- Android 在线播放器代码
- android-support-v4.jar解决了友盟反馈
- JAVA写的四子棋
- 学生成绩管理系统 java源码 以及项目
- 数字时钟java源码
- Android蓝牙串口传输心电数据画图的小
- Java 、Android实现MP4裁剪功能
- 微信扫码支付源码
- 老罗Android开发视频教程合集.txt
- android手机的远程视频监控系统
评论
共有 条评论