Results 1 to 2 of 2
  1. #1
    prashbabu123 is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default Java Serial Processing

    Im trying to work on java serial processing. Trying to get this code to work.. But im having issues.. IM trying to compile this from the terminal. I added serial.jar to the CLASSPATH..but i still get errors..

    // This Processing example reads byte-values from the serial
    // port at 9600 bits-per-second (bps). It uses these values
    // to set the color of a square on the canvas.
    // Also, if the mouse moved, its relative x-position (0..7)
    // is sent over the serial port.

    import processing.serial.*; // load serial library
    Serial p; // declare serial port object

    void setup()
    size(200, 200);

    // open the port that the Wiring board is connected to (in my case 2)
    // at the same speed that the board is transmitting (9600 bps).
    p = new Serial(this, Serial.list()[2], 9600);

    void draw()
    background(102); // clear background to grey
    if (p.available() > 0) { // if data is available to read
    fill(; // read it and use as fill() color
    rect(50, 50, 100, 100); // draw a square

    if (mouseX != pmouseX) // if mouseX changed
    int x = int(8*(mouseX/width)); // compute the relative x-position
    p.write(x); // send it onto the serial line

    .. All i need to do is send data to a specific serial port..the few errors im getting are class, interface, or enum expected
    Serial p; // declare serial port object
    ^ class, interface, or enum expected
    void setup()
    ^ class, interface, or enum expected

    Thanks ...

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Quote Originally Posted by prashbabu123 View Post
    Java Code:
    import processing.serial.*;         // load serial library
    Serial p;                           // declare serial port object
    This all has nothing to do with serial ports; Java uses the class notion as a compilation unit; everything has to be a member of a class (or interface). Your code violates this principle (see above). You have to define a class and methods and member variables in that class to make it legal Java. There are numerous tutorials that'll explain the details.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Audio processing in Java?
    By blind melon in forum New To Java
    Replies: 11
    Last Post: 12-02-2010, 11:22 PM
  2. Replies: 1
    Last Post: 07-30-2010, 08:29 AM
  3. Java Speech Processing
    By redvirus in forum CLDC and MIDP
    Replies: 2
    Last Post: 10-03-2009, 12:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts