Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java/android: combining two libraries

  • 07-12-2012 11:41am
    #1
    Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 Mod ✭✭✭✭


    Hi, 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:

    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?


Comments

  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    Using two activites seems a little strange, one should ideally be a background service.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 Mod ✭✭✭✭Tar.Aldarion


    Yeah being new I am really confused about the layout and how data is sent around etc. I will look up background service thanks.


    I was thinking maybe it would be simpler if it was just one activity, just with a settings button to deal with the serial connection stuff, if that would work...


Advertisement