Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9283933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:45:29+00:00 2026-06-18T18:45:29+00:00

I am using a terminal emulator library to create a terminal and then I

  • 0

I am using a terminal emulator library to create a terminal and then I use it to send the data entered over serial to a serial device. When the data is sent back I want to parse it and show the most important information to the user in an editText. Currently I receive byte arrays/chunks and I convert them to a string. When I get a \r or a \n I crete a new string and the process repeats. This is fine for most commands, however some commands return results over multiple lines like “show vlan” here:

enter image description here

When I loop through this I get a string for each line. The first would contain VLAN Name Status and Ports, as an example. So now I have a problem, how can I VLAN 1 has x ports active. They are in different strings. Here is the code and screenshot for a current easier command where I am interested in one line:

enter image description here

Handler viewHandler = new Handler();
Runnable updateView = new Runnable() {
    @Override

    public void run() {

        mEmulatorView.invalidate();

        if (statusBool == true) {
            for (int i = 0; i < dataReceived.length(); i++) {
                parseCommand = parseCommand + dataReceived.charAt(i);

 if (dataReceived.charAt(i) == '\n' || dataReceived.charAt(i) == '\r'){

    if(parseCommand.contains("KlasOS"))
            {

        String[] tokens = parseCommand.split("\\s{1,}");

        final String ReceivedText = mReceiveBox.getText().toString() + " "
        + new String("Software Version: " + tokens[1] + "\n" );

        runOnUiThread(new Runnable() {
            public void run() {
                                mReceiveBox.setText(ReceivedText);
                                mReceiveBox.setSelection(ReceivedText.length());

                            }
                        });         

                            }

                parseCommand = "";

            }               
            }

            statusBool = false;
            viewHandler.postDelayed(updateView, 1000);
        }
    }
};

Now I would like to change this so i can deal with multiple lines. Would the ebst way be to store strings if they contain certain information?

I need this outputted on the right hand editText:

“The following ports are on vlan 1: Fa1/0, fa1/1, fa1/2, fa1/3, fa1/4, fa1/5, fa1/6, fa1/7, fa1/8, fa1/9, fa1/10, fa1/11, Gi0”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:45:31+00:00Added an answer on June 18, 2026 at 6:45 pm

    Basically, you need a way to reliably detect the end of a command result. Then it boils down to sending your command, reading data from the device until you encounter the end of result, and finally parsing that result.

    I would scan for the prompt (switch#) as you do in your own answer. Maybe your are even able to force the device to use a more peculiar character sequence, which is unlikely to occur in the regular output of commands and makes it easier to detect the end of a result. For example, you could try to configure the prompt to include a control character like ^G or ^L. Or if your users don’t mind, you could always send a second command that emits such a sequence, for example, “show vlan; echo ^G”.

    You should also be prepared for command errors, which result in a different output, for example, more or fewer lines as expected or a totally different output format. A result may even contain both, a regular output and a warning or an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a terminal emulator library to create a terminal and then I
I am using a terminal emulator library to create a terminal and then I
I am trying to connect to a terminal emulator using a library in android,
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
Updated question: I am trying to connect to a terminal emulator using a library
I am writing a terminal emulator in ruby using the PTY library. /dev/tty0 is
I am trying to connect to a terminal emulator using a library in android,
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.