We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I start an external .exe with open() but starts an external flat bed scanner scan that takes about 20 seconds
The program continues and before the scan finishes and puts a file in the directory I use to put up image, it gets to the load file statement and can't find it , it's not there yet.
I am trying to use this code to test the file exists before letting the program continue but it complains "unexpected token boolean"
boolean fileExists(String "test.png")
File file = new File("test.png");
while(!file.exists());
Am I on the right tract?
Answers
Don't instantiate a File unless you specify the full path. Prefer sketchFile() & dataFile() instead.
Take notice that exec(), launch() and the like don't block the sketch.
They create a separate Thread instead.
so would this work to test if the file is in the directory yet?
while(!dataFile("test.png").exists());
The while would loop until the file existed?
I tryed it but it just hangs at the while loop.
actually while contains full path
while(!dataFile("c:\processing\test.png").exists());
If i use delay(9000) to wait for scanner, it works without above at all. But different scanner setting take more or less time and I don't wanna just set a brute force delay.
You can invoke a separate function to deal w/ the checking using thread():
https://Processing.org/reference/thread_.html
Wrap up the whole check inside an infinite loop + delay():
tried this.
boolean ok; is above setup()
thread("fileCheck"); is in draw loop, executed when mouse pressed once
The void FileCheck() is at the end of the sketch file.
It gives unexpected char:'p' error
If you want that behavior, you're better off using mousePressed() or mouseClicked().
In Draw strscan=("c:/acquire/acquire.exe /SCAN/HIDE/GAMMA1.0/C0/GRAY/H6/W8"+strdpi+strxoff+stryoff+" epsproc.bmp");
open(strscan);
thread("fileCheck");
Outside Draw
void fileCheck() { while(!dataFile("c:\processing\test.png").exists()) delay(50); ok=true; }
Still don't understand why i get error , unexpected char:'p' error
OK got this to run without error. slashes in quotes were wrong "c:/processing/test.png" not "c:\processing\test.png"
but when thread is called , draw loop continues without waiting for thread call to fileCheck.
fileCheck finishes and ok=true but program reaches image("test.png",0,0); before file is present still.
I thought thread would pass control to the thread process draw would wait for it to finish before continuing.
Am i missing something?
A while loop in the draw loop doesn't seem to stop any execution.
thread(fileCheck); while(ok==false);
Shouldn't this just loop until ok=true? Then allow the draw function to continue?
If i put delay(9000); after the scan, it makes the draw loop wait . This works as a brute force constant way to delay the program but there has to be a more elegant way that will only make it wait until something becomes true right.
How about going w/ the same approach I did in this forum thread?: *-:)
https://forum.Processing.org/two/discussion/16097/launch-won-t-work-inside-selectinput-function#Item_3
http://Tutorials.Jenkov.com/java-concurrency/index.html
Only problem is I don't wanna go out of draw() once its started. The scan is initiated within draw and somehow i need to check when the file arrives on the hard drive so i can access it with other software.
then the next event does some image processing and shows a report.
Then draw loops waiting for a mouse pressed event to start the sequence over.
https://forum.Processing.org/two/discussions/tagged?Tag=#state
using this solution but now i need to try to make the path for SCANNED_IMG_PATH universal to work with any directory path instead of c:\processing\test.png I just want to use test.png and have it find it in the directory the program is started in.
what would be the syntax for that ? Or can i only specify a specific path with a drive letter? I need it to be drive letter independent.
Thanks
Re-read my very 1st reply of almost 1 year ago: Use dataFile() or dataPath().
useing datafile() now with SCANNED_IMG_PATH set to just test.png but it does not find it in the starting directory. Windows puts the file in the Virtual Store under AppData automatically it works if i specify a path like c:\processing\test.png so guess i will just have to do that.
Functions dataFile() & dataPath() point to the subfolder "data/" where the sketch is run.
For using Processing's own loading functions, we don't need them.
That is, if you have
loadImage("test.png");
and "test.png" is inside subfolder "data/", loadImage() is gonna find it.This is how we proceed to have our sketches to be able to load resources no matter its actual path running location.
Read more about it at loadImage()'s reference: :-B https://Processing.org/reference/loadImage_.html
thks