RFID Video Daemon

sorry but in the documentation i don't see a dispose() method.

that should work, because never really close a video, it keep them in a list so it can be reused:

import processing.serial.*;
import processing.video.*;

Serial myPort;  // The serial port
HashMap <String, Movie> listOfMovie = new HashMap<String, Movie>();//the list of open movie
Movie playingMovie; //the pointer to the actual playing movie, no movie = null

void setup() {
  size(400,400,P3D);
  // Open whatever port is the one you're using.

  myPort = new Serial(this, Serial.list()[1], 2400);
  myPort.buffer(10);//that means don't call serialEvent until 10 carater are recived
  background(0);

  //here load and put all movie in the map.
  listOfMovie.put("3600A9C9F8", new Movie(this, "file1.mov") );
  listOfMovie.put("0000000000", new Movie(this, "file2.mov") );
  ///etc etc
}

void draw() {
  synchronized(playingMovie) {//to be sure we don't change video while it is changed by Serial command
    if (playingMovie != null) { //if video is rendering
      if ( playingMovie.available() ) { //if a new frame is available
        playingMovie.read(); //load it
      }
      image(playingMovie, 0, 0); //show the frame
    }
  }
}

void serialEvent(Serial p) { 
  synchronized(myPort) {//to be sure only one thread at time can enter here
    while (myPort.available() >= 10) {
      //Video Code:
      String command = "";
      for (int i=0;i<10;i++) {
        command += myPort.readChar();
      }
      println(command);//here you should have the correct command

        //myMovie.setSize();
      if ( listOfMovie.containsKey(command) ) {//if the command is related to a video
        synchronized(playingMovie) {//to be sure we don't change video while it is drawn
          playingMovie.stop(); //stop old video
          playingMovie = listOfMovie.get(command); //get the command's video
          playingMovie.jump(0); //restart video from beginning
          playingMovie.play(); //play it
        }
      }
    }
  }
}

Wow.

I have renamed my files to file1 and file2 which is a lot more practical than the original way.

An error is produced when it is run, not when the tag is used.

I am recieving a NullPointerException at synchronized(playingMovie)

Apparently it is a runner exception.

Movie playingMovie; //the pointer to the actual playing movie, no movie = null

i make an introduction movie to run on startup if the problem is there is no movie, this will graphically look better.

This is brilliant, the buffer functions is really good idea, the Serial Event is also amazing.

Here is what I have tried:

void setup() {
size(400,400,P3D);
// Open whatever port is the one you're using.

myPort = new Serial(this, Serial.list()[1], 2400);
myPort.buffer(10);//that means don't call serialEvent until 10 carater are recived
background(0);

//here load and put all movie in the map.
listOfMovie.put("3600A9C9F8", new Movie(this, "file1.mov") );
listOfMovie.put("0000000000", new Movie(this, "file2.mov") );
///etc etc
playingMovie = new Movie(this, "intro.mov");
}

When the playingMovie = new Movie(this, "intro.mov"); line is added there is not a null pointer in playingMovie variable, even though it doesnt play the video.

Your code is amazing and i appreciate it greatly.

Is arduino more for robotics rather than software applications?

It just won't read the output correctly.

Thank you.

Okay i'm sorry, i forgot to update the ID of the second tag!!!

The progblem is still the same. it will only read part of the serial after the first execution.

3600A9C9F8 First

3600A9C
9F8

3600 Second
A9C9F8

3
600A9C9F8 Third

3600A9C9

Sometimes it will run the code twice although the card is only supposed to be read once. In the above example I tried to use it three tiems but the code was produced almost 5.

I am beginning to believe this is a processing/arduino communication error and not a programming error.

Sorry again, and thank you so so much.

360073D274

360073D
274

3600
73D274

3
60073D274

360073D2

3600A9C9F8

3600A9C
9F8

3600
A9C9F8

3
600A9C9F8

3600A9C9

It looks as though it is reading:

10 char's
7 char's + 3 char's
4 char's + 6 char's
1 char + 9 char's
8 char's

This is the same each time for seperate tags.

I can't determine why. First time is fine.

Just an idea,

Daemon files run in the background, does this mean I could have a program in the foreground????

.pde files are relatively new to me but i know .exe files can execute other .exe files on demand.

By this i mean could I have a program that reads the code once, executes a video on a different sketch, closes the sketch and waits for another.

Setup(){
//run intro video
//wait for rfid code
}

draw(){
//send code to daemon
//run daemon with video
//close daemon
}

Thank you, just an idea.

I am guessing there are no solutions to this problem.

It isn't feasible after all.

Does anybody have any possibilities for me please.

I have worked hard on this and got too far to turn back.

There is a solution somewhere, I'm sure of it.

Could someone please look at my code and help me.

Thank you very much.

IMHO the error is here(arduino code):

if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }

Thanks for your post.

I don't understand what the val is in relation to? The command variable?

if (length(command)!=10){ break; }

So there is not a possibility of using another file or program to close and open the daemon file that plays the video?

Thank you for replying, no other idea's out there any where?

Hope to hear something back

sorry, I was wrong. the error is:

if(bytesread == 10) { // if 10 digit read is complete
Serial.println(code); // print the TAG code
}

should be

if(bytesread == 10) { // if 10 digit read is complete
code[10]='\0'; //add end of string signal
Serial.print(code); // print the TAG code
}

add the end string signal and remove the "ln" in the print, or in processing you will read \n as character. probably processing should read 11 char, because the last is \0, i dunno, just test

It is so annoying if the error was at the start, but that would make sense.

Somehow I have updated the arduino with the code and tested the arduino and it works, why i left println instead of print i have no idea.

Your right, 10 variable is 0 inclusive, that would make sense.

I'm still getting a error on the processing side, a null pointer exception in the draw method at this line:

synchronized(playingMovie) {//to be sure we don't change video while it is changed by Serial command

I thought it was because it didn't have a video to play but there is sound coming from the program, it is loading file1 straight away.

Also, the sound turns off after 3 seconds.

I used your code previously submitted.

Should the if (playingMovie != null) code be above the synchronize?

Thanks so much for your help again.

Maybe it is feasible.

oh my, the previous code that I was working with actually works now.

The error was in the arduino board, I would never of thought of that.

That was perfect what you said and println was the problem too.

Now its just a matter of the sound playing all the way through.

I can extract the audio no problem if needed.

I will put the code I was originally using:

import 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);
}

}

Thank you sooooo much, your obviously very knowledgable with arduino!!!!! :grin:

Should I mark this as solved and create a new forum post asking about the audio?

I can't thank you enough lesto.

for the audio open a new thread, this is enough full :slight_smile:

but if you are going to play audio with processing is better use their forum, here is a little off-topic

I have got audio to work now.

The only problem is the video plays as if it has lag.

I've asked for help on the processing forum.

Thought I would mention is here as well.

Thanks again.

maybe this is because you read serial in draw... serial is really slow, so try to use serialEvent

Perfect :grin:

Now I need to work out how to stop the audio files from overlapping.

I was thinking of using: myMovie.dispose(); player.close(); and minim.stop(); but i'm not sure where to put it.

Updated Code:

import processing.serial.*;
import processing.video.*;
import jmcvideo.*;
import ddf.minim.*;

AudioPlayer player;
Minim minim;

Serial myPort;  // The serial port
Movie myMovie;

void movieEvent(Movie m) {
  m.read();
}

void setup() {
    size(320,240,P3D);
     minim = new Minim(this);
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[1], 2400);

  background(0);
 
}

void draw() {

 
  if (myMovie != null){
      image(myMovie, 0, 0);
      smooth();
      ///image(myMovie, 0, 0, 320, 240);
  }
 
}

void serialEvent(Serial p){
  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");
  player = minim.loadFile(command+".wav", 2048);
  //myMovie.setSize();
  myMovie.play();
  player.play(); 
  }
}

Many Thanks

put them before
myMovie = new Movie(this, command+".mov");
player = minim.loadFile(command+".wav", 2048);

you just have to check that myMovie isn't null

Working great now.

I had to put them after the code mentioned.

Sometimes i get a null pointer reference but the program still works.

Thank you this is great.

You've been a great help.

Thank you

The video's are playing and the sound is playing but every so often the file will crash and deliver this report:

Stable Library

Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
3600A9C9F8
360073D274
3600A9C9F8
F0000000F0
The file "F0000000F0.mov" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
error, disabling serialEvent() for //./COM4
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
at quicktime.util.QTHandle.(QTHandle.java:287)
at processing.video.Movie.init(Unknown Source)
at processing.video.Movie.(Unknown Source)
at processing.video.Movie.(Unknown Source)
at dumdum.serialEvent(dumdum.java:80)
... 7 more