Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Displaying Serial inputs in G4P TextArea.

$
0
0

Hi,

I am new to G4P and now try to display ASCII line inputs in TextArea using code below. appendText works but I like to use the insertText method with newline addition . I then get the IndexOutofBound exeption error. What am I doing wrong?

import g4p_controls.*;
import processing.serial.*;

public static final short portIndex = 0;
public static final char LF = 10;
public static final char CR = 13;
Serial myPort;
GTextArea myTxArea;
String myString="";

public void createGUI()
{
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  myTxArea = new GTextArea(this, 133, 2, 354, 262, G4P.SCROLLBARS_VERTICAL_ONLY);
  myTxArea.setOpaque(true);
}

public void setup()
{
  size(480, 320, JAVA2D);
  createGUI();
  println(" Connecting to -> " + Serial.list()[portIndex]);
  myPort = new Serial(this,Serial.list()[portIndex], 115200);
  myString = myPort.readStringUntil(LF);
  myString = null;
  myTxArea.appendText("");
}

public void draw()
{
  background(230);
  if ( myPort.available() > 0)
  {
      myString = myPort.readStringUntil(LF);
      if (myString!=null)
        //myTxArea.appendText(myString);
         myTxArea.insertText(myString,true,false);
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles