I’m using two libraries in an android app I’m trying to make. New to android. The app is for connecting to serial devices and controlling their console via a terminal.
One library is for setting up a serial connection, setting baud rate etc and can also write read/data over serial.. The other is for creating a terminal session. I have no problem running these libraries to get simple separate examples up and running. Eg, with the first library I can set up a serial connection with a router and send/receive data via textboxes which looks like this:
https://lh5.ggpht.com/R4CAJXY9ZPDVsgt8jUZg5hc-v81aa70sctiegIGDjzv2lyvuG6OZyYas_4I-h_es-4Aq
With the second library I am able to set up local terminal on a tablet and look at the directories etc. My problem lies in incorporating both of these together to have a terminal that is connected to a serial device and with the layout/passing of data.
In the terminal library I need to supply an InputStream and OutputStream to provide input and output to the terminal. So I have to call setTermIn(java.io.InputStream) and setTermOut(java.io.OutputStream) to connect the input and output streams to the emulator.
In the serial library however there are two methods for sending and receiving and these deal with arrays of bytes.
sendData(byte[] data) for sending data and a dataListener for receiving data. I have to implement this and code the method onDataReceived(int id, byte[] data) with id being the name of the device.
So my question is, how do I hook these up? Do I create java.io.InputStream/OutputStream implementations on top of sendData and OnDataReceived, just convert the arrays to streams and call the setTermIn/Out methods?
For OnDataReceived I suppose all I do is receive the byte[] data and convert it to a stream inside the method and send this to the terminalActivity?
but what about sendData, I am not implementing this, I just send an array of bytes, how do I send it as a stream instead to setTermIn?
I am also very confused about having these things happening in different activities and how that works. Because I have the serial stuff happening in one activity, so I hit connect, it reads the relevant baud rate etc and connects to the serial device, then a terminal is opened in a new terminalActivity which is currently connected to nothing, just looks like a blank terminal. I’m not sure how everything should be laid out. Like if I hit the enter key in a terminal, should the implementation for sending data over serial not be in that same activity, not the one I am initially in where I am connecting to a serial device? But to know if I am connected to a serial device in the first place I need to send/receive data…should there be implementations of these methods in both activities?! Or maybe I should simplify it and add the connection options and the terminal to the same activity?
Should I be combining these both in one activity maybe?
Simplest way was to combine into one activity.