rapid updating data not text out in loops

I know how bad I am at coding. That said, I do not understand why this code will not update the display with real-time data in the while loop i placed lots of test lines and prints to try and debug so it is a mess. This line however should be refreshing;

println( ("index is = ")+index ); // text( index , 150, 25);

Please note that all the debug println are working EXACTLY as expected, only the text out not working.

Code outside of a loop seems to work fine; Like this line;

total_count++; text( ("total count is = ")+total_count, 700, 25);

I have added random delays and such to try and debug to no avail. Any help appreciated.

PLEASE NOTE; PROGRAM DIRECTORY MUST HAVE FILE CALLED setup.txt and I have loaded with these TAB delimited numbers as experiment;

            0   0
            0   0
            0   0
            0   0
            0   0
            0   0
            0   0
            10  0
            10  2
            10  4
            10  5
            10  10
            11  13
            13  18
            14  21

Just to understand what my goal is, I want to read an PLC device over serial port; this device will be polled by my code and output TONS of data registers. I want to have TWO pages; 1 setup page that holds user adjustable parameters, and one page that simply displays the serial data in friendly, non-hex format. This program is just to learn Processing and read the setup.txt that will hold user settings.

Hardware engineers should never try and write code!

                int currentScreen;
                PFont f; 
                Button setup_screen_Button;  // setup screen button
                Button save_setup_screen_Button;  // SAVE button
                int clk = 1;       // number of times the button is clicked
                PrintWriter output; // THIS IS USED FOR SENDING DATA TO FILE  **NOT USED YET**************
                BufferedReader reader; // this is used to read files from OS
                String line;// **********************temp buffer for read line from setup file********************
                String [] tempstring = new String[1000];
                int count= 1;
                int index;
                long total_count;

                //**************INITALIZED ALL GLOBALS*************************
                void setup() { // **********************************setup program function***********************
                             //output = createWriter("SETUP_FILE.txt"); // USE ONLY IF NEED CREATE NEW FILE-SHOULD EXIST!
                             fullScreen();
                             noStroke();
                             smooth();
                             // *****************create the button object*********************
                             setup_screen_Button = new Button("SETUP SCREEN", 520, 120, 100, 50);
                             save_setup_screen_Button = new Button("SAVE SETUP", 200, 20, 100, 50);
                             reader = createReader("setup.txt"); /*NAME OF SETUP DEFAULT FILE**************************


                             f = createFont("Arial",20,true); // STEP 2 Create Font
                            }  // *******END **********************************setup program function***********************

                void draw() {

                  background(255, 0, 0);
                   println ("**************in top main loop*********************");  
                  fill(255);
                 // ellipse(100, 100, 400, 400);


                  // save_setup_screen_Button.Remove();
                  textSize(12);
                  setup_screen_Button.Draw();// ***********draw the button in the window******************
                  textSize(22);
                   //text("value from file read line 1 = " + tempstring[1], 220, 250); 

                  // delay (800);
                 if (line == null){
                                            try {
                        line = reader.readLine();
                      } 

                      catch (IOException e) {
                        e.printStackTrace();
                        line = null;
                        text("FILE SETUP.TXT NOT EXIST OR INVALID!!!", 20, 50);
                      }

                   while (line != null) {
                    // Stop reading because of an error or file is empty
                    //noLoop();  


                        //String[] pieces = split(line, TAB);
                        String[] pieces = split(line, TAB);
                         tempstring[count] =(line);
                        fill(0, 102, 153);
                          println ("in new setup loop");
                        println ("RAW " + line);
                        println ("Peices0= " + pieces[0]);
                        println ("Peices1= " + pieces[1]);
                        text("in else loop line is = "+line, 110, 360);
                        //int x = int(pieces[0]);
                        //int y = int(pieces[1]);
                        //point(x, y);
                        count++;
                        try {
                        line = reader.readLine();
                      } 
                  catch (IOException e) {
                        e.printStackTrace();
                        line = null;
                        text("FILE SETUP.TXT NOT EXIST OR INVALID!!!", 20, 50);
                      }
                              }
                                            }
                    println(++++++++++++++++in middle main loop/////////////////////////////"); 

                 while (tempstring[index] != null){

                              // println (tempstring[index]);
                                text( ("total count is = ")+index, 700, 125);
                               //delay (100);
                               text( tempstring[index], 220, (index * 50)); 
                               String[] pieces = split(tempstring[index], TAB);
                               fill(255);
                               //rect(370, ((index * 50)-85), 65, 25);
                               fill(0);
                               textAlign(RIGHT);
                               text( pieces[0]+(" ")+(pieces[1]+1), 420, (index * 50)); 
                               println( pieces[0]+(" ")+(pieces[1]+1));
                               println ("in while loop");
                               println( ("total count is = ")+total_count);
                               index++;
                               //text( ("________________________________________________"), 1, 25);
                 //              textAlign(LEFT);
                               text( ("index is = "), 1, 25);
                               fill(255);
                               //rect(115, 5, 65, 25);
                               fill(0);
                 //              textAlign(RIGHT);
                 //              text( ("total count is = ")+index, 700, 125);
                               println( ("index is = ")+index );
                //               text( index , 150, 25);


                           } 


                      //tempstring[index] ="0  0";       

                 for (int i = 1; i < 12; i = i+1) {

                   text(tempstring[1], 220, (i * 50)); 
                   fill(255);
                 //rect(370, ((index * 50)-85), 65, 25);
                 fill(0);
                 delay (100);
                 textAlign(RIGHT);
                 String[] pieces = split(tempstring[i], TAB);
                 text( pieces[0]+(" ")+pieces[1], 920, (i * 50)); 
                   println ("in for loop");
                   text( ("total count for i = ")+i, 700, 75);

                 }








                 index = 1;// reset index to force to run again;
                 total_count++;
                 text( ("total count is = ")+total_count, 700, 25);
                 println ("in bottom main loop*********************");                          



                }



                 // **********************************the Button class*****************************
                class Button {
                              String label; // button label
                              float x;      // top left corner x position
                              float y;      // top left corner y position
                              float w;      // width of button
                              float h;      // height of button

                  // constructor
                             Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
                                                                    label = labelB;
                                                                    x = xpos;
                                                                    y = ypos;
                                                                    w = widthB;
                                                                    h = heightB;
                                                                    }

                  void Draw() {
                              fill(218);
                              stroke(141);
                              rect(x, y, w, h, 10);
                              textAlign(CENTER, CENTER);
                              fill(0);
                              text(label, x + (w / 2), y + (h / 2));
                              }
                  void Remove() { // ********************NOT SURE THIS WORKS!!*******************
                                w=0;
                                h=0;
                                fill(218);
                                stroke(141);
                                rect(x, y, w, h, 10);
                                //textAlign(CENTER, CENTER);
                                fill(0);
                                //text(label, x + (w / 2), y + (h / 2));
                              }

                  boolean MouseIsOver() {
                                        if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
                                                      return true;
                                                      }
                                        return false;
                                        }
                     }// END **********************************the Button class*****************************           

Answers

Sign In or Register to comment.