Hello every body, I'm new on Processing and i've a problem with a sketch which was given to me. In short, i want to control many printers with processing. So i sent from a max patch two kind of osc message, one for say which image Processing has to charge and the second one for say on which printer it has to use for print. the first message reception is good and processing charge correctly all my image but for the second one processing send a message of error type:
ERROR @ OscP5 ERROR. an error occured while forwarding
an OscMessage
to a method in your program. please check your code for any
possible errors that might occur in the method where incoming
OscMessages are parsed e.g. check for casting errors, possible
nullpointers, array overflows ... .
method in charge : oscEvent java.lang.reflect.InvocationTargetException
when i desactivate one line which is // setPrinter(printerId)
it works correctly but prints only on the default printer...
(this line is on the second point allmost at the end and is now desactivate.)
But I don't manage to find what is the probleme in this fonction....
I send you the three sketchs and thank you for your help...
thank you A LOT.
thanks again. Caroline
ERROR @ OscP5 ERROR. an error occured while forwarding
an OscMessage
to a method in your program. please check your code for any
possible errors that might occur in the method where incoming
OscMessages are parsed e.g. check for casting errors, possible
nullpointers, array overflows ... .
method in charge : oscEvent java.lang.reflect.InvocationTargetException
when i desactivate one line which is // setPrinter(printerId)
it works correctly but prints only on the default printer...
(this line is on the second point allmost at the end and is now desactivate.)
But I don't manage to find what is the probleme in this fonction....
I send you the three sketchs and thank you for your help...
thank you A LOT.
- // DECLARATION DES RESSOURCES
import java.awt.image.BufferedImage; // importer librairie java
import java.awt.print.*;
import java.awt.*;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.PrintJobEvent;
PImage b;
boolean imageChargee;
// INITIALISATION DES RESSOURCES
void setup() {
size(420, 595);
/* create a new instance of oscP5.
* 11000 is the port number you are listening for incoming osc messages.
*/
oscP5 = new OscP5(this,11000);
imageChargee = false;
printersList();
}
// EXECUTION
void draw() {
background(255, 0, 0);
if (imageChargee)
image(b, 0, 0);
}
- /**
* oscP5broadcastClient by andreas schlegel
* an osc broadcast client.
* an example for broadcast server is located in the oscP5broadcaster exmaple.
* oscP5 website at http://www.sojamo.de/oscP5
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
/* a NetAddress contains the ip address and port number of a remote location in the network. */
NetAddress myBroadcastLocation;
/* create a new instance of oscP5.
* 11000 is the port number you are listening for incoming osc messages.
*/
int myListeningPort = 11000;
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* get and print the address pattern and the typetag of the received OscMessage */
theOscMessage.print();
// si nous reçevons un message avec un identifiant "/image"
if (theOscMessage.checkAddrPattern("/image") == true) {
// si nous reçevons dans ce message un symbol (le nom de l'image)
if (theOscMessage.checkTypetag("s")) {
String nomImage = theOscMessage.get(0).stringValue();
// Images must be in the "data" directory to load correctly
b = loadImage(nomImage); // ex : monImage-1.jpg
imageChargee = true;
}
}
// sinon, si nous reçevons un message avec un identifiant "/imprime"
else if (theOscMessage.checkAddrPattern("/imprime") == true) {
// si nous reçevons dans ce message un int (le numéro d'imprimante)
if (theOscMessage.checkTypetag("i")) {
int printerId = theOscMessage.get(0).intValue();
//setPrinter(printerId);
delay(1000);
printStage();
delay(5000);
}
}
}
- PrinterJob job;
// called by the main code to start a new print job as a thread
void printStageThreaded() {
// Create an object that will hold all print parameters, such as
// page size, printer resolution. In addition, it manages the print
// process (job).
job = PrinterJob.getPrinterJob();
Runnable printRunner = new Runnable() {
public void run() {
handlePrint();
}
};
javax.swing.SwingUtilities.invokeLater(printRunner);
}
// called by the main code to start a new print job
void printStage() {
// Create an object that will hold all print parameters, such as
// page size, printer resolution. In addition, it manages the print
// process (job).
job = PrinterJob.getPrinterJob();
handlePrint();
}
// called by printThread to set the print job for the stage.
void handlePrint() {
job.setJobName("Mon impression");
job.setCopies(1);
job.setPrintable(new Printable() {
public int print (Graphics pg, PageFormat f, int pageIndex) {
switch (pageIndex)
{
case 0 :
pg.drawImage(g.image, 0, 0, null);
return Printable.PAGE_EXISTS;
default:
return NO_SUCH_PAGE; // No other pages left
}
}
}
);
try {
println("try print");
job.print();
}
catch (PrinterException e) {
System.out.println(e);
}
}
void printersList() {
PrintService defServ = PrintServiceLookup.lookupDefaultPrintService();
println("Default PrintService: " + defServ);
PrintService[] serv = PrintServiceLookup.lookupPrintServices(null, null);
if (serv.length==0) {
println("no PrintService found");
}
else {
println("number of Services " + serv.length);
}
for (int i = 0; i<serv.length; i++) {
PrintServiceAttributeSet psa = serv[i].getAttributes();
println("printer name "+(i+1) + " " + psa.get(PrinterName.class));
println("accepting " + psa.get(PrinterIsAcceptingJobs.class));
}
}
void setPrinter(int printerId) {
PrintService[] serv = PrintServiceLookup.lookupPrintServices(null, null);
try {
job.setPrintService(serv[printerId-1]);
}
catch (PrinterException e) {
System.out.println(e);
}
}
thanks again. Caroline
1