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

The Archive Base Latest Questions

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

I’m sending a JSON object from an Arduino board to a java application on

  • 0

I’m sending a JSON object from an Arduino board to a java application on my PC via the USB serial connection. The java application receives “chunks” from the serial port in a serial event listener.

This is the body of the listener:

public synchronized void serialEvent(SerialPortEvent oEvent) {
    if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
            int available = input.available();
            byte chunk[] = new byte[available];
            input.read(chunk, 0, available);

            // buffering of bytes must happen here to 
            // ultimately de-serialize into JSON object
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

The problem I have is that it’s not clear when the end of the JSON object has been received. From what I’ve researched, there needs to be some sort of event that causes the attempt to read from serial port to return a -1. The problem is that with this model, I only ever enter the listener when there’s data available to be read.

I added some code to check the return value of the call to input.read and it seems to return the same value as the number of bytes available and I’ve also tested for other events and none other appear to happen.

Unless there’s an easy way to modify this to detect the end of a serial transmission, I’m thinking this model of serial input isn’t going to work for receiving something like a JSON object.

Should I move to a design that creates a separate thread with a blocking “readline” call to the serial port?

I’m stumped.

  • 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-01T23:00:48+00:00Added an answer on June 1, 2026 at 11:00 pm

    Since whitespace is allowed in JSON (see json.org), you can put a newline character after the very last character of the JSON string. Make sure you don’t use a newline character anywhere else in the JSON string. Once you encounter the newline character, that’s your signal that you received the entire string.

    I’ve done this before with serial streaming JSON. In my situation, there’s a device continuously streaming a JSON string. Data values vary within the JSON string (it’s environmental data like temperature and humidity). So I find the start of the string by looking for an identifier (in my case, it’s {"environment data": and I find the end by looking for a newline character (which is used nowhere else in the string).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to

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.