Results 1 to 2 of 2
Thread: Java Serial Processing
- 12-24-2010, 04:27 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Java Serial Processing
Hey,
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);
noStroke();
framerate(10);
// 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(p.read()); // 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
delay(100);
}
}
.. All i need to do is send data to a specific serial port..the few errors im getting are
ard.java:9: class, interface, or enum expected
Serial p; // declare serial port object
^
ard.java:12: class, interface, or enum expected
void setup()
^
ard.java:15: class, interface, or enum expected
noStroke();
Thanks ...
- 12-24-2010, 08:27 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Audio processing in Java?
By blind melon in forum New To JavaReplies: 11Last Post: 12-02-2010, 11:22 PM -
serial communication is very slow while reading from serial port
By elsanthosh in forum AWT / SwingReplies: 1Last Post: 07-30-2010, 08:29 AM -
Java Speech Processing
By redvirus in forum CLDC and MIDPReplies: 2Last Post: 10-03-2009, 12:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks