prettrygb 发表于 2014-10-14 23:45:05

e9 串口编程问题

技术讲串口编程只要模仿 资料区的 TQ210android SerailPort.zip就可以(http://www.armbbs.net/forum.php?mod=viewthread&tid=15967&extra=page%3D1%26filter%3Dtypeid%26typeid%3D178),按此思路,下载,抽取核心代码,始终无法运行,每次运行到SerialPort的静态方法中时就会崩溃,这个静态方法就一条语句System.loadLibrary("serial"); 我以为没有libserial.so(/system/lib中确实没有),故也将相应的文件通过u盘copy到了/system/lib目录下。可还是不行,控制台显示错误为:root@android:/ # init: untracked pid 3601 exited
request_suspend_state: sleep (0->3) at 160406618688 (1970-01-02 03:00:45.249258686 UTC)
==ft5x0x_ts_suspend=
request_suspend_state: wakeup (3->0) at 413461212720 (1970-01-02 03:04:58.303852718 UTC)
==ft5x0x_ts_resume=
cpufreq_interactive_input_connect: connect to ft5x06_ts

以下是主要的程序语句, searialPort来自SerialPort.zip
                        SerialPort sp = new SerialPort(f, 115200);
                        OutputStream out = sp.getOutputStream();
                        String dataString = "123456789";
                        out.write( dataString.getBytes() );
                        out.close();



SerialPort类定义:
public class SerialPort {

        private static final String TAG = "SerialPort";

        /*
       * Do not remove or rename the field mFd: it is used by native method close();
       */
        private FileDescriptor mFd;
        private FileInputStream mFileInputStream;
        private FileOutputStream mFileOutputStream;

        public SerialPort(File device, int baudrate) throws SecurityException, IOException {

                /* Check access permission */
                if (!device.canRead() || !device.canWrite()) {
                        try {
                                /* Missing read/write permission, trying to chmod the file */
                                Process su;
                                su = Runtime.getRuntime().exec("/system/bin/su");
                                String cmd = "chmod 666 " + device.getAbsolutePath() + "\n"
                                                + "exit\n";
                                su.getOutputStream().write(cmd.getBytes());
                                if ((su.waitFor() != 0) || !device.canRead()
                                                || !device.canWrite()) {
                                        throw new SecurityException();
                                }
                        } catch (Exception e) {
                                e.printStackTrace();
                                throw new SecurityException();
                        }
                }

                mFd = open(device.getAbsolutePath(), baudrate);
                if (mFd == null) {
                        Log.e(TAG, "native open returns null");
                        throw new IOException();
                }
                mFileInputStream = new FileInputStream(mFd);
                mFileOutputStream = new FileOutputStream(mFd);
        }

        // Getters and setters
        public InputStream getInputStream() {
                return mFileInputStream;
        }

        public OutputStream getOutputStream() {
                return mFileOutputStream;
        }

        // JNI
        private native static FileDescriptor open(String path, int baudrate);
        public native void close();
        static {
                System.loadLibrary("serial");
        }
}

参考帖子(http://www.armbbs.net/forum.php?mod=viewthread&tid=19544&extra=page%3D2)后发现,直接通过以下代码就可以发送,不过这与demo中的实现方式有什么区别? 只发现下面的代码是没有波特率的,没有JNI。
                                       File file = new File(/dev/ttySAC0");
                                        OutputStream oStream = new FileOutputStream( file );
                                        String dataString = "123456789";
                                        oStream.write( dataString.getBytes() );
                                        oStream.close();


请大侠帮忙解决一下,先谢谢了


wbz073 发表于 2014-10-15 09:26:30

在FAQ里面已经有个E9现成的串口so,你可以直接使用。

prettrygb 发表于 2014-10-15 14:49:07

wbz073 发表于 2014-10-15 09:26
在FAQ里面已经有个E9现成的串口so,你可以直接使用。

感谢回复。 嗯,我用的就是FAQ中的libserial.so。将其copy进入到/system/lib目录下的(之前是没有)。然后用资料发布区的TQ210 android串口代码,只用里面的SerialPort类,其它没用。 里面有一句 System.loadLibrary("serial");,每次执行到这里就会出错。不知道什么原因?

wbz073 发表于 2014-10-15 17:52:10

prettrygb 发表于 2014-10-15 14:49
感谢回复。 嗯,我用的就是FAQ中的libserial.so。将其copy进入到/system/lib目录下的(之前是没有)。然 ...

这是jni不同引起的,我已上传最新的E9串口程序源码到论坛,去论坛FAQ下载。

姚庆瑞 发表于 2014-11-20 15:38:24

qingwenyixia:nimendeFQAzainaline?

姚庆瑞 发表于 2014-11-20 15:42:22

我是新手,弱弱的问一下你们的FAQ下载在哪里呢?

freewing 发表于 2015-7-27 17:36:16

姚庆瑞 发表于 2014-11-20 15:42
我是新手,弱弱的问一下你们的FAQ下载在哪里呢?

在论坛中直接搜索FAQ就可以找了!
页: [1]
查看完整版本: e9 串口编程问题