Andrews serial development library containing demo source code

About Andrews serial development, this article is very clear:

https://blog.csdn.net/qq_35952946/article/details/78863871

But with this program code error:

java.lang.UnsatisfiedLinkError: dlopen failed: ××××.so: has text relocations

This is so because the compiler file is too old.

The following example source code, modify the above-described problems, and provides demonstration examples, operational.

Instructions:

Get a list of serial ports

SerialPortFinder serialPortFinder = new SerialPortFinder();
return serialPortFinder.getAllDevices();

  

Open / Close serial port:

/// dev / ttyS1 behind a number, a serial number, based on actual condition 
Final SerialPortUtils portUtils new new SerialPortUtils = ( "/ dev / ttyS1", 57600,0); 
portUtils.openSerialPort ();
portUtils.closeSerialPort();

  

Processing data received:

// event listener serial data 
        portUtils.setOnDataReceiveListener (new new SerialPortUtils.OnDataReceiveListener () { 
            byte [] mBuffer; 
            Handler Handler Handler new new = (); 

            @Override 
            public void onDataReceive (byte [] Buffer, int size) { 
                Log.d (the TAG "data received:" + Byter.byteToHex (Buffer)); 
                // 
                // direct operations will be reported in the UI thread exception: ViewRootImpl $ CalledFromWrongThreadException 
                // solution: Handler 
                // 
                mBuffer = Buffer; 
                handler.post (Runnable ); 
            } 
            // open thread to update the UI  
            the Runnable Runnable new new = the Runnable () {
                @Override
                public void run() {
                    recvContent.setText("size:"+ String.valueOf(mBuffer.length)+"数据监听:"+ Byter.byteToHex(mBuffer));
                }
            };
        });

  

Code file upload later

 

Guess you like

Origin www.cnblogs.com/lifang-biz/p/11770299.html