iT邦幫忙

DAY 29
0

x86 android 設備與外部硬體溝通研究系列 第 29

x86 android 設備與外部硬體溝通研究 - cdc-acm.c (29/30)

  • 分享至 

  • xImage
  •  

今天我們把CDC serial driver 中的 setParameters 修改如下:

        @Override
        public void setParameters(int baudRate, int dataBits, int stopBits, int parity) throws IOException {
            byte stopBitsByte;
            switch (stopBits) {
                case STOPBITS_1: stopBitsByte = 0; break;
                case STOPBITS_1_5: stopBitsByte = 1; break;
                case STOPBITS_2: stopBitsByte = 2; break;
                default: throw new IllegalArgumentException("Bad value for stopBits: " + stopBits);
            }

            byte parityBitesByte;
            switch (parity) {
                case PARITY_NONE: parityBitesByte = 0; break;
                case PARITY_ODD: parityBitesByte = 1; break;
                case PARITY_EVEN: parityBitesByte = 2; break;
                case PARITY_MARK: parityBitesByte = 3; break;
                case PARITY_SPACE: parityBitesByte = 4; break;
                default: throw new IllegalArgumentException("Bad value for parity: " + parity);
            }
            // byte[] baudRate = le32_to_cpu( baudRate );  
            // little endian binary (32bit) formate
            byte[] msg = {
                    (byte) ( baudRate & 0xff),
                    (byte) ((baudRate >> 8 ) & 0xff),
                    (byte) ((baudRate >> 16) & 0xff),
                    (byte) ((baudRate >> 24) & 0xff),
                    stopBitsByte,
                    parityBitesByte,
                    (byte) dataBits};
            
            /* Fix Arduino Frimata protocol connect , need setDTR msg before set parameters control msgs.
             對應昨天看到的 acm_set_control(acm, acm->ctrlout = newctrl); 這行指令
             ref :
             	http://lxr.free-electrons.com/ident?i=acm_tty_set_termios 
             	http://lxr.free-electrons.com/source/drivers/usb/class/cdc-acm.c#L989
             */
            
            setDTR(true); 
            
            sendAcmControlMessage(SET_LINE_CODING, 0, msg);
        }

重新打包封裝 APP 後,push 到 zenfone 6 上面測試....

燈!燈!燈! 可以收到由 arduino 送出來的資料了,有圖為證:

Android Serial Driver 專案放在這邊: https://github.com/jyyan/usb-serial-for-android

我們明天見 :P


上一篇
x86 android 設備與外部硬體溝通研究 - cdc-acm.c (28/30)
下一篇
x86 android 設備與外部硬體溝通研究 (30/30)
系列文
x86 android 設備與外部硬體溝通研究30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言