2017-04-11 1 views
1

TX 포트에서 글쓰기를 계속하기 위해 Arduino가 구성되어 있습니다. 안드로이드 Things Developer Preview 3 (내 RX/TX 케이블이 올바르게 구성되어 있고 전압은 정상입니다).Android Things 3 Rxtberry PI 3에서 rxtx를 읽을 수 없습니다.

Android Things libs의 PeripheralManagerService를 사용하여 데이터를 읽고 데이터를 쓰는 데 오랜 시간이 걸립니다.

04-11 16 : 나는 응용 프로그램을 시작할 때

는 오류가 26 : 13.665 163-163 /? (0 : 44) : name = "ttyAMA0"dev = "tmpfs"ino = 1203에 대해 avc : {읽기 쓰기}를 거부했습니다. scontext = u : r : 주변 사람 : s0 tcontext = u : object_r : 장치 : s0 tclass = chr_file 허용 = 1

04-11 16 : 26 : 13.665 163-163 /?/dev/ttyAMA0 "dev ="tmpfs "ino = 1203 scontext = u : r : 주변 사람 : s0 tcontext = u : object_r : 장치 : s0 tclass = chr_file 허용 = 1

04-11 16 : 26 : 13.665 163-163 /?/dev/ttyAMA0 "dev ="tmpfs "ino = 1203 ioctlcmd = 5401 scontext = u : r : peripheralman : s0 tcontext에 대해 I/peripheralman : type = 1400 audit (0.0 : 46) : avc : {ioctl}을 거부했습니다. = U : object_r : 장치 : S0 인 TClass = chr_file 허용 =

1 내 코드 :

public class MainActivity extends Activity { 

private final int BUFFER_SIZE = 64; 
private UartDevice rxtx; 


public void configureUartFrame(UartDevice uart) throws IOException { 
    // Configure the UART port 
    uart.setBaudrate(9600); 
} 

public void writeUartData(UartDevice uart, String msg) throws IOException { 
    byte[] buffer = msg.getBytes(); 
    int count = uart.write(buffer, buffer.length); 
    Log.d(TAG, "Wrote " + count + " bytes to peripheral"); 
} 

public void readUartBuffer(UartDevice uart) throws IOException { 
    byte[] buffer = new byte[BUFFER_SIZE]; 
    int count; 
    while ((count = uart.read(buffer, buffer.length)) > 0) { 
     Log.d(TAG, "Read " + count + " bytes from peripheral"); 
     Log.d("Message", new String(buffer)); 
    } 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
     try { 
      writeUartData(rxtx, "teste"); 
      readUartBuffer(rxtx); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    PeripheralManagerService manager = new PeripheralManagerService(); 

    manager.getUartDeviceList(); 
    List<String> portList = manager.getUartDeviceList(); 

    if (portList.isEmpty()) { 
     Log.i(TAG, "No UART port available on this device:"); 
    } else { 
     Log.i(TAG, "List of RXTX available ports: - " + portList); 
    } 

    try{ 
     rxtx = manager.openUartDevice(portList.get(0)); 
     configureUartFrame(rxtx); 
    }catch (IOException e){ 
     e.printStackTrace(); 
    } 
}} 

누군가가 무엇을 할 수 알아?

+0

몇 일 후에 결국 죽을 링크 대신 텍스트 코드 및 관련 오류를 게시 (복사 및 붙여 넣기)하면 더 많은 도움을받을 수 있습니다. 그냥 생각 : –

+0

Ok! 나는 편집했다. thx – Stould

+0

RPi3 헤더의 RX/TX 핀 (8/10)에 직접 연결 하시겠습니까? 아니면 USB-TTL 케이블입니까? 기본 UART를 사용하는 경우 문서별로 올바르게 모드를 구성 했습니까? https://developer.android.com/things/hardware/raspberrypi.html#configuring_the_uart_mode – Devunwired

답변

1

코드에 UartDeviceCallback이 등록 된 곳이 보이지 않습니다. 새로운 들어오는 데이터에 대해 UART를 어떻게 폴링합니까? 콜백이 등록되지 않았다면, 앱은 새로운 수신 바이트에 대해 UartDevice.read()을 통해 UART를 정기적으로 폴링해야하며, 코드에도 해당 코드가 표시되지 않습니다. 이것이 호출 된 것으로 보이는 유일한 곳은 활성 콜백 onStart()입니다.

콜백은 훨씬 효율적인 방법이므로 추가하는 것이 좋습니다. 자세한 내용은 UART Peripheral I/O Guide을 참조하십시오.

+0

나는 Arduino Uno와는 다른 구성을 사용하는 Intel Arduino 101을 사용하면서 무슨 일이 일어나고 있는지 발견했습니다. Arduino Uno를 사용하면 모든 것이 잘 동작합니다. 응답 해 주셔서 감사합니다. 콜백을 사용하여 데이터를 폴링하는 것이 훨씬 좋습니다. 그러나 나는 위에서 언급 한 것처럼이 오류가 무엇인지 알고 싶습니다. – Stould