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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:45:26+00:00 2026-05-31T13:45:26+00:00

I have an application that is talking to a hardware device over serial. This

  • 0

I have an application that is talking to a hardware device over serial. This device is sending a json object every 30ms. This json object is the devices “state” its a motion controller.

Basically the messages look like this:

{"sr":{"line":2524,"posx":1.000,"posy":21.000,"posz":20.000,"posa":11.459,"feed":0.000,"vel":0.000,"unit":1,"coor":1,"dist":0,"frmo":0,"momo":0,"stat":2}}

I get these 1x every 30ms. I have to parse them. Then “draw” them onto the JavaFX gui.

Here is how I am parsing:

Platform.runLater(new Runnable() {

            public void run() {
                //We are now back in the EventThread and can update the GUI
                try {
                    JsonRootNode json = JDOM.parse(l);

                    xAxisVal.setText(json.getNode("sr").getNode("posx").getText());
                    yAxisVal.setText(json.getNode("sr").getNode("posy").getText());
                    zAxisVal.setText(json.getNode("sr").getNode("posz").getText());
                    aAxisVal.setText(json.getNode("sr").getNode("posa").getText());
                    drawLine();

                } catch (argo.saj.InvalidSyntaxException ex) {
                    //Json line invalid.
                }
            }
        });

And here is the draw code I am using:

public void drawLine() {
    xl.setX(Float.parseFloat(xAxisVal.getText()) + 400);
    y1.setY(Float.parseFloat(yAxisVal.getText()) + 400);
    LineTo tmpL = new LineTo((Float.parseFloat(xAxisVal.getText()) * 2) + 400, (Float.parseFloat(yAxisVal.getText()) * 2) + 400);
    path.getElements().add(tmpL);

}

So basically I am creating a runnable object every 30ms then parsing and drawing. Is this the best way to do this? You can see a video of it in action:

http://www.youtube.com/watch?v=dhBB3QcmHOg&feature=youtu.be

But it seems like its “jerky” and pretty resource hungry. I am hoping for someone to give me suggestions on how to optimize this code? Perhaps point out something I am missing?

As an FYI the motion controller board we are making is called TinyG. Its opensource hardware.
More info is here:
http://www.synthetos.com/wiki/index.php?title=Projects:TinyG

Firmware here:
https://github.com/synthetos/TinyG

Thanks!

  • 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-05-31T13:45:27+00:00Added an answer on May 31, 2026 at 1:45 pm

    You seems to perform too much calculations on event queue which blocks graphic rendering while your data is being parsed. You should make calculations in separate thread and call Platform.runLater() only for relevant ui code:

        try {
    
            JsonRootNode json = JDOM.parse(l);
            final String xVal = json.getNode("sr").getNode("posx").getText();
            final String yVal = json.getNode("sr").getNode("posy").getText();
            final String zVal = json.getNode("sr").getNode("posz").getText();
            final String aVal = json.getNode("sr").getNode("posa").getText();
    
            // here you are calling UI getter, and parse it each time
            // it would be more optimal to store `x` value in separate variable
            // between updates
            final float x = Float.parseFloat(xAxisVal.getText());
            final float y = Float.parseFloat(yAxisVal.getText());
    
            Platform.runLater(new Runnable() {
    
                public void run() {
                    //We are now back in the EventThread and can update the GUI
                    try {
    
                        xAxisVal.setText(xVal);
                        yAxisVal.setText(yVal);
                        zAxisVal.setText(zVal);
                        aAxisVal.setText(aVal);
                        xl.setX(x + 400);
                        y1.setY(y + 400);
                        LineTo tmpL = new LineTo(x * 2 + 400, y * 2 + 400);
                        path.getElements().add(tmpL);
    
                    }
                }
            }
    
        } catch (argo.saj.InvalidSyntaxException ex) {
            //Json line invalid.
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that is talking over Bluetooth to a server on a
I have a web application that is talking to a WCF service hosted within
I have a WPF desktop application ( .NET 4.0 ) that is talking to
I have a desktop client application that is talking to a server application through
I have this application that has a form with a drop-down list and a
I have an Arduino application talking over USB to an application on Windows 8
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have application that brings response via Ajax and creates 5-20 new jQuery click

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.