Reputation: 1
I have an ODROID-C4 that I am trying to get to communicate with an external controller using the UART1 port on the 40-pin header. I am programming in Android and using Android-Serialport-API library for setting up the port and reading/writing.
I am able to send commands, the external controller receives and responds to the commands correctly (I attached a sniffer to check). However, I am unable to receive communications in the ODroid. When I enter debug mode, I see an array of zeros, sometimes a 2 or 64 gets in there. Additionally, the output from the external controller does not change so I'm not sure why the input to the ODroid does.
Has anyone used this library? Any tips for reading in?
Thanks
This is my current code:
port.getInputStream().read(savedBuf);
String msg = new String(savedBuf);
String[] arr;
arr = msg.split("\r");
In an alternate approach I tried setting up a separate Thread for reading:
Init:
File dev = new File("/dev/ttyS1");
port = new SerialPort(dev, 57600);
mOutputStream = port.getOutputStream();
mInputStream = port.getInputStream();
mReadThread = new ReadThread();
mReadThread.start();
private class ReadThread extends Thread {
@Override
public void run() {
super.run();
while (!isInterrupted()) {
int size;
try {
if (mInputStream == null)
return;
size = mInputStream.read(buffer);
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
}
Then I read and handle the Input in a different function as shown below. This function gets called about 1x/sec. It gets called after writing to the external controller. I have tried adding a delay between the write and the read and I have tried having no delay between the two.
savedBuf = buffer;
String msg = new String(savedBuf);
String[] arr;
arr = msg.split("\r");
The result was about the same for both approaches
Any help is much appreciated!
Upvotes: 0
Views: 38