Pages: 1 ... 3 4 [5] 6 7   Go Down
Author Topic: RFID Video Daemon  (Read 4972 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi lesto, the previous code actually works however the program reacts the same.

The first RFID tag reads:3600A9C9F8 and executes fine, but when the second tag is used it reads as:360073D

For some reason it will only read the first 7 numbers of the second tag.

Its really weird.

This code is a lot more organised which is better but still a boggle as to what is causing the problem.

The line highlighted is:   myMovie = new Movie(this, command+".mov");

I think this is because command isn't reading properly.

Quote
while (myPort.available() >= 10) {

  String command = "";
  for (int i=0;i<10;i++){
     command += myPort.readChar();
  }
  println(command);
  myMovie = new Movie(this, command+".mov");

If the sequencing is okay, the problem must be somewhere above.

Also, when the image(myMovie, 0, 0); code is changed to image(myMovie, 0, 0,width,height); the video plays back terribly.

Thank you for the upgraded code.

I'm sorry it didn't work.
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if the error is
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.

then it's ok, when you solve the reading problem you should solve everything.
Maybe the error is in the arduino code? can you post your actual code?

tru to put the wile into
syncronize(Serial){
//while's code
}

maybe 2 call of draw() are executing together
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Quote
// 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
    }
  }
}

PROCESSING
Quote
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);
  }
 
}



THE ERROR

Quote
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.
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
« Last Edit: April 10, 2011, 03:29:06 pm by 4kingrich » Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah, the error is at second loading... probably you haven't closed the myMovie...

Code:
while (myPort.available() >= 10) {
  //Video Code:
  String command = "";
  for (int i=0;i<10;i++){
     command += myPort.readChar();
  }
  println(command);
   [color=yellow]
   if (myMovie!=null){
     myMovie.stop();
   }
   [/color]
  myMovie = new Movie(this, command+".mov");
  //myMovie.setSize();
    myMovie.play();
}

but maybe the Video class isn't supporting the opening/closing of video: so you have to have a Video variable for each of your code.. try with the code in yellow, if not i'll work out something smiley
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you but for some reason it is throwing an nullpointerexception again and not playing a video first time round at all.

The command variable is still 3 digits short of a full code variable.

I put the
Quote
image(myMovie, 0, 0);
line below the myMovie.play(); function as it was in the if(myMovie != null) function to begin with.

The error is thrown faster but I don't know if thats good or bad. No further forward or backward though.

I am repeating the process in my head trying to debug but I don't understand why it is happening.

Why would the first time work but not the second, that confuses me so much.`

Thank you again, it needs to reset but that is not possible???

Could i set a state as a function and call that function to reset the screen, image, command and movie?

Please, Thank you
« Last Edit: April 10, 2011, 04:08:24 pm by 4kingrich » Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why would the first time work but not the second, that confuses me so much.`
simply because processing open the file, play it, but it doesn't close it.
That's a shame.
you have to live with this (a file already open cannot be opened again)

tomorrow i will write a workaround.
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see that the video image is still on the processing screen after it has played, I didn't realise this means the video is still open.

Would there be a possibility of writing over the top of the previous video, if it would work a few times this would be better than once.

Of course running ultimately without a restart would be perfect.

I understand the logic of loading the references into video pointers and then calling each pointer however, can a string point to ao object.

The background(0); variable wouldn't write over the image would it?

I need to look at the Image(); function and see what is avaiable here.

It is important that this program is successful.

I am really determined and althought my knowledge of processing is minimal I am willing to learn and try.

Please if anyone has any information, the help would be highly appreciated.

Thank you so much.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had an idea of using a delay and then stopping the video.

The stop function would stop the video in previous attempts without a delay.

Stop doesnt Close the video though.

Maybe the command variable can be updated?

Would it be a good idea to create a seperate function that reads the code from the arduino?

E.G.

function readCode(myPort){
//Read Code
//Store into a temporary variable
Return Command;
}

Outside of this function command can be set to seperate variables called Command1 Command2 Command3????


String Command1 = readCode(myPort);

Would this be feasible?

Thank you
« Last Edit: April 11, 2011, 07:27:45 am by 4kingrich » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

movie.dispose();

This line of code disposes/gets rid the movies.

After a delay this could be a possibility.

I will update the progress soon.

Thank you.
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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
        }
      }
    }
  }
}
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
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.
« Last Edit: April 11, 2011, 08:51:01 am by 4kingrich » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

« Last Edit: April 11, 2011, 08:53:09 am by 4kingrich » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
360073D274

360073D
274

3600
73D274

3
60073D274


360073D2


Quote
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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am guessing there are no solutions to this problem.

It isn't feasible after all.
Logged

Pages: 1 ... 3 4 [5] 6 7   Go Up
Jump to: