Android-SerialPort-Tool icon indicating copy to clipboard operation
Android-SerialPort-Tool copied to clipboard

Battery and charging command callback

Open alirazaseptems opened this issue 4 years ago • 7 comments

alirazaseptems avatar Nov 10 '20 08:11 alirazaseptems

Hello, can you please guide me how can I get the status of a command. For example when I sent a battery command "40BF". it does not always return the battery level. I want to know If I could get some data that tells me if the command is executed successfully or not. The same happens when I send command for charging one out of 10 times. Can you please guide me about this. Thank you.

alirazaseptems avatar Nov 10 '20 08:11 alirazaseptems

@alirazaseptems https://github.com/licheedev/SerialportApiSample i just wrote a simple demo.i hope that will help you.

licheedev avatar Nov 10 '20 11:11 licheedev

I have used serialport manager in java. Can I get some code in java using serial port manager. thanks.

mOpened = SerialPortManager.instance().open(mDevice) != null; if (mOpened) { // ToastUtil.showOne(this, "成功打开串口"); Toast.makeText(this, "成功打开串口", Toast.LENGTH_SHORT).show(); SerialPortManager.instance().sendCommand(batteryCommand);

and I get callback in this method. which does not always give me callback. @Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(IMessage message) { }

alirazaseptems avatar Nov 10 '20 13:11 alirazaseptems

oh, forget the terrible code on Android-SerialPort-Tool,i wrote it just for finding out which serialport is avaiable.

in fact, the major code from https://github.com/licheedev/SerialportApiSample is in java,like this SerialWorker.java now the send-receive operation is synchronized, you can wrap the send method with some concurrency tools, like Java Concurrency package or RxJava very easily. so you can write the callback by your own.

licheedev avatar Nov 10 '20 13:11 licheedev

@alirazaseptems ok, i copy the Android-SerialPort-Tool repo https://github.com/licheedev/Android-SerialPort-Tool_Copy i change the code like this SerialPortManager.java

now you can get the response from the callback directly

  SerialPortManager.instance().sendCommand(text, new Callback<byte[]>() {
            @Override
            public void onSuccess(@Nullable byte[] bytes) {
                // TODO: 2020/11/10  
                ToastUtil.showOne(MainActivity.this, "send success with response");
            }

            @Override
            public void onFailure(@NonNull Throwable tr) {
                // TODO: 2020/11/10  
                ToastUtil.showOne(MainActivity.this, "send success without response");
            }
        });

licheedev avatar Nov 10 '20 14:11 licheedev

想问下 日后像升级这能开多一个新库吗 别把之前的删除 我之前一直用着 'com.github.licheedev.Android-SerialPort-API:serialport:1.0.1' 觉得蛮好的 哈哈

roshenLiang avatar Mar 08 '21 03:03 roshenLiang

想问下 日后像升级这能开多一个新库吗 别把之前的删除 我之前一直用着 'com.github.licheedev.Android-SerialPort-API:serialport:1.0.1' 觉得蛮好的 哈哈

@roshenLiang 其实也没删,我改版本之前建了个分支 https://github.com/licheedev/Android-SerialPort-API/tree/1.x.x Jitpack上构建的老版本还在 https://jitpack.io/#licheedev/Android-SerialPort-API

licheedev avatar Mar 08 '21 03:03 licheedev