|
@@ -144,21 +144,27 @@ public final class SerialPortManager {
|
|
|
*/
|
|
|
private Observable<Object> rxSendData(final byte[] data, final String name) {
|
|
|
|
|
|
+
|
|
|
return Observable.create(new ObservableOnSubscribe<Object>() {
|
|
|
@Override
|
|
|
public void subscribe(ObservableEmitter<Object> emitter) throws Exception {
|
|
|
- try {
|
|
|
- mReadThread.setmName(name);
|
|
|
- sendData(data);
|
|
|
- emitter.onComplete();
|
|
|
- } catch (IOException e) {
|
|
|
- Log.e(TAG, "发送:" + ByteUtils.bytes2HexStr(data) + " 失败", e);
|
|
|
- if (!emitter.isDisposed()) {
|
|
|
- emitter.onError(e);
|
|
|
- return;
|
|
|
+ Log.d(TAG, "subscribe: "+emitter);
|
|
|
+ if (!emitter.equals("null")) {
|
|
|
+ try {
|
|
|
+ Log.d(TAG, "subscribe: "+emitter);
|
|
|
+ mReadThread.setmName(name);
|
|
|
+ sendData(data);
|
|
|
+ emitter.onComplete();
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log.e(TAG, "发送:" + ByteUtils.bytes2HexStr(data) + " 失败", e);
|
|
|
+ if (!emitter.isDisposed()) {
|
|
|
+ emitter.onError(e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+ emitter.onComplete();
|
|
|
+ Log.d(TAG, "subscribe: "+emitter);
|
|
|
}
|
|
|
- emitter.onComplete();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -169,10 +175,12 @@ public final class SerialPortManager {
|
|
|
*/
|
|
|
public void sendCommandFrame(final CommandFrame commandFrame, final String name) {
|
|
|
// Log.i(TAG, "发送命令(raw):" + Arrays.toString(commandFrame.getFrameData()));
|
|
|
+ Log.d(TAG, "sendCommandFrame: "+name);
|
|
|
Log.i(TAG, name+"发送命令:" + commandFrame);
|
|
|
//已经从我们的去读取出来转换成了字节数了。
|
|
|
byte[] bytes = commandFrame.getFrameData();
|
|
|
Log.d("log",new String(bytes).toString());
|
|
|
+
|
|
|
rxSendData(bytes,name).subscribeOn(Schedulers.io()).subscribe(new Observer<Object>() {
|
|
|
@Override
|
|
|
public void onSubscribe(Disposable d) {
|