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 9096325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:49:01+00:00 2026-06-16T23:49:01+00:00

I am connecting to a terminal emulator using a library in android, this connects

  • 0

I am connecting to a terminal emulator using a library in android, this connects to a serial device (a switch) and shows me sent/received data.

However I am just sending byte arrays over and back so I don’t know what status the switch is in, is it in enable more or configuration mode etc. This leads me to possibly enter commands in the wrong mode and they won’t work. The switch is then in an unrecoverable mode as I have sent a wrong command and there is no way to delete it or get to a new line. The problem I am trying to deal with for now is the one where I don;t know the mode the switch is in. I know that I can have three different return prompts after I send a command:

switch>
switch#
switch(config)#

So I was thinking that if I read the last two characters received I could tell which mode I’m in. h>, h# and )#

I get data back in this method, whenever data is received this is run:

public void onDataReceived(int id, byte[] data) 
{

    String str = new String(data);
    ((MyBAIsWrapper) bis).renew(data);

    mSession.write(str);
    mSession.notifyUpdate();
    viewHandler.post(updateView);
}

Would the best way to do this be search the byte array somehow or to convert it to a string and search the string for h>, h# and )#, then I could set a global variable depending on the value I get back? Maybe search from the end backwards?

  • 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-16T23:49:03+00:00Added an answer on June 16, 2026 at 11:49 pm

    I would search the byte[] and avoid the overhead from the conversion to a String.

    If it is more performant to start search from the end, depends on the data you get. I cannot judge this by the little example you posted in your question.

    If you only need to look at the last two characters:

    if(data[data.length-2]=='h' && data[data.length-1]=='>') // "h>"
    
    
    if(data[data.length-2]=='h' && data[data.length-1]=='#') // "h#"
    

    Or if it is not so simple, use a loop to iterate the array.

    P.s. I assumes ASCII encoding for the code above

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

Sidebar

Related Questions

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
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
I am trying to connect to a terminal emulator using a library in android,
Updated question: I am trying to connect to a terminal emulator using a library
We have a terminal emulator (its more then just this, but for the question
I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus
Background To capture data from a logic controller, I'm using screen as a terminal
When connecting to sql server, I have the hardcoded string (local). Is this a

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.