AndroidSerialPort
AndroidSerialPort copied to clipboard
打开串口失败
PC上面 是可以的,Android设备上面提示波特率不对 是什么原因。
I/SerialPortManager: openSerialPort: 打开串口 /dev/ttyUSB0 波特率 8000000
E/serial_port: Invalid baudrate
W/System.err: java.lang.NullPointerException: fd == null
W/System.err: at java.io.FileInputStream.
看 SerialPort.c
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;
}
}
因为你设置的波特率不在这里边,看看你的ndk版本,或者改成一个里边有的波特率吧
@BDZNH 因为硬件波特率传输只能是8000000, 这要怎么改?
@zhaoxiuyu 这个波特率NDK的预定义里面没有。可能你需要找一下NDK对这方面的定义了,手动改一下NDK也许可行。在Android studio里面按住control点击B4000000就可以跳转过去了。
不过也许NDK没有定义这个值,有可能是安卓不支持哟。
我的设置成9600也不行,报的错一样的,不知道什么原因- -