@@ -367,9 +367,14 @@ private void trySend() {
367367 }
368368
369369 private void appendError (String func , Throwable tr ) {
370- mTvConsole . append (func + "异常:" + tr + "\n " );
370+ appendText (func + "异常:\n " + tr + "\n " );
371371 }
372372
373+ private void appendText (String text ) {
374+ mTvConsole .append (text );
375+ }
376+
377+
373378 private void send01 () {
374379
375380 if (checkSlave () && checkOffset () && checkAmount ()) {
@@ -383,7 +388,7 @@ public void onSuccess(ReadCoilsResponse readCoilsResponse) {
383388
384389 boolean [] sub =
385390 ArrayUtils .subarray (readCoilsResponse .getBooleanData (), 0 , amount );
386- mTvConsole . append ("F01读取:" + ArrayUtils .toString (sub ) + "\n " );
391+ appendText ("F01读取:\n " + ArrayUtils .toString (sub ) + "\n " );
387392 }
388393
389394 @ Override
@@ -414,7 +419,7 @@ public void onSuccess(
414419 boolean [] sub =
415420 ArrayUtils .subarray (readDiscreteInputsResponse .getBooleanData (), 0 ,
416421 amount );
417- mTvConsole . append ("F02读取:" + ArrayUtils .toString (sub ) + "\n " );
422+ appendText ("F02读取:\n " + ArrayUtils .toString (sub ) + "\n " );
418423 }
419424
420425 @ Override
@@ -442,7 +447,7 @@ private void send03() {
442447 // public void onSuccess(
443448 // ReadHoldingRegistersResponse readHoldingRegistersResponse) {
444449 // byte[] data = readHoldingRegistersResponse.getData();
445- // mTvConsole.append ("F03读取:" + ByteUtil.bytes2HexStr(data) + "\n");
450+ // appendText ("F03读取:" + ByteUtil.bytes2HexStr(data) + "\n");
446451 // }
447452 //
448453 // @Override
@@ -466,7 +471,7 @@ private void send03() {
466471 public void onSuccess (
467472 ReadHoldingRegistersResponse readHoldingRegistersResponse ) {
468473 byte [] data = readHoldingRegistersResponse .getData ();
469- mTvConsole . append ("F03读取:" + ByteUtil .bytes2HexStr (data ) + "\n " );
474+ appendText ("F03读取:\n " + ByteUtil .bytes2HexStr (data ) + "\n " );
470475 }
471476
472477 @ Override
@@ -488,7 +493,7 @@ private void send04() {
488493 public void onSuccess (
489494 ReadInputRegistersResponse readInputRegistersResponse ) {
490495 byte [] data = readInputRegistersResponse .getData ();
491- mTvConsole . append ("F04读取:" + ByteUtil .bytes2HexStr (data ) + "\n " );
496+ appendText ("F04读取:\n " + ByteUtil .bytes2HexStr (data ) + "\n " );
492497 }
493498
494499 @ Override
@@ -513,7 +518,7 @@ private void send05() {
513518 new ModbusCallback <WriteCoilResponse >() {
514519 @ Override
515520 public void onSuccess (WriteCoilResponse writeCoilResponse ) {
516- mTvConsole . append ("F05写入成功\n " );
521+ appendText ("F05写入成功\n " );
517522 }
518523
519524 @ Override
@@ -537,7 +542,7 @@ private void send06() {
537542 new ModbusCallback <WriteRegisterResponse >() {
538543 @ Override
539544 public void onSuccess (WriteRegisterResponse writeRegisterResponse ) {
540- mTvConsole . append ("F06写入成功\n " );
545+ appendText ("F06写入成功\n " );
541546 }
542547
543548 @ Override
@@ -561,7 +566,7 @@ private void send15() {
561566 new ModbusCallback <WriteCoilsResponse >() {
562567 @ Override
563568 public void onSuccess (WriteCoilsResponse writeCoilsResponse ) {
564- mTvConsole . append ("F15写入成功\n " );
569+ appendText ("F15写入成功\n " );
565570 }
566571
567572 @ Override
@@ -587,7 +592,7 @@ private void send16() {
587592 @ Override
588593 public void onSuccess (WriteRegistersResponse writeRegistersResponse ) {
589594 // 发送成功
590- mTvConsole . append ("F16写入成功\n " );
595+ appendText ("F16写入成功\n " );
591596 }
592597
593598 @ Override
0 commit comments