Okay, I need to explain the problem better.
code is the variable being outputted by the arduino which is recieved by processing and is the name of my video files. (except the .mov)
In processing when the program is run, it reads the
code variable being sent from the arduino and loads it into a
command variable.
This command variable is then a new movie called
myMovie that is played, if the video isnt null the image is loaded.
Up until now the program works good. now comes the problem.
When the tag is read AGAIN, the second time the process happens there is an error collecting the
code variable from the arduino and assigning it to the
command variable in the program.
The error is a
nullPointerException however instead of reading
The file "360073D.mov" is missing................it reads
The file "
360073D.mov" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.It is as if the output is incorrect but when I restart the program and try the
same tag it will work first time but not the second time.
If it was okay to stop and run the program each time after use it would be okay but I plan to make an unmanned station, so I need to be able to load another video either on top of the current video or as a replacement.
I think the problem is at the recieving end (the processing file). The variable might get mixed up along the way some how which causes it to stop prematurely.
I am unsure as to why it won't read the tag twice and throws an error, but the fact that it works once at least ensures my video's are correct.
I dont mind overlapping video's, I just can't figure out why it won't do the same brilliant job twice.
Here are the full codes:
ARDUINO// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
int val = 0;
char code[10];
int bytesread = 0;
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}
void loop() {
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.println(code); // print the TAG code
}
bytesread = 0;
digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
delay(1500); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
}
}
}
PROCESSINGimport processing.serial.*;
import processing.video.*;
import jmcvideo.*;
Serial myPort; // The serial port
Movie myMovie;
void movieEvent(Movie m) {
m.read();
}
void setup() {
size(400,400,P3D);
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[1], 2400);
background(0);
}
void draw() {
while (myPort.available() >= 10) {
//Video Code:
String command = "";
for (int i=0;i<10;i++){
command += myPort.readChar();
}
println(command);
myMovie = new Movie(this, command+".mov");
//myMovie.setSize();
myMovie.play();
}
if (myMovie != null){
image(myMovie, 0, 0);
//image(myMovie, 0, 0, width, height);
}
}
THE ERRORThe file "
360073D.mov" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
processing.app.debug.RunnerException: NullPointerException
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NullPointerException
at quicktime.util.QTHandle.<init>(QTHandle.java:287)
at processing.video.Movie.init(Unknown Source)
at processing.video.Movie.<init>(Unknown Source)
at processing.video.Movie.<init>(Unknown Source)
at sketch_apr05a.draw(sketch_apr05a.java:52)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
I am really struggling with this, I dont understand why its second time unlucky.
Thank you Thank you