use of print in exported (standalone) application
in
Programming Questions
•
2 years ago
Hi, what can I do to use print and echo some stuff in a terminal shell with when I export my porcessing app?
for example, when I run my code (below) from the processing IDE I have the resul of the print in the console view but if I made an .exe and launch it, not mor terminal even if I launch the exec from a shell....
my code:
for example, when I run my code (below) from the processing IDE I have the resul of the print in the console view but if I made an .exe and launch it, not mor terminal even if I launch the exec from a shell....
my code:
- import processing.serial.*;
import java.io.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.awt.*;
Serial myPort;
char rx;
int irx = 0;
boolean flagrx = false;
char[] tbl = new char[24];
int[] val = new int[8];
int[] mesures0 = new int[1];
int[] mesures1 = new int[1];
int[] mesures2 = new int[1];
int[] mesures3 = new int[1];
boolean flagprint = false;
boolean flagsend = false;
JFileChooser dialogue = new JFileChooser(); //creation dialog box chargement fichier
File fichier;
FileWriter fstream;
BufferedWriter out;
void setup(){
Object[] listPort = Serial.list();
if(listPort.length > 0){
Object selectedPort = JOptionPane.showInputDialog(null, "Port Serie:", "Choix du port",JOptionPane.INFORMATION_MESSAGE, null,listPort, listPort[0]);
print("Selected Port = "+selectedPort+"\n");
if(selectedPort != null){
JOptionPane d = new JOptionPane();
String BaudRate = JOptionPane.showInputDialog("BaudRate:","115200");
if(BaudRate != null){
myPort = new Serial(this, (String)selectedPort, Integer.parseInt(BaudRate), 'N', 8, 1.0);
//myPort.bufferUntil(0x0A);
}else{
exit();
}
}
else{
exit();
}
}
else{
JOptionPane.showMessageDialog(null,"Pas de port serie trouvés","Erreur!",JOptionPane.ERROR_MESSAGE,null);
exit();
}
//noLoop();
mesures0[0] = 0;
mesures1[0] = 0;
mesures2[0] = 0;
mesures3[0] = 0;
//size(160,64);
String s = "'ESC' to quit\r\n's' to start/stop\r\n'r' to save\r\n'p' to print received values\r\n'l' to list the tab";
text(s, 5, 20);
}
void draw(){
if(flagprint==true){println(val[0]+" "+val[1]+" "+val[2]+" "+val[3]);}
}
void keyPressed(){
if(key==ESC){myPort.stop();println("Exit!");}
if((key=='S')||(key=='s')){
if(flagsend==true){
println("Stop!");
myPort.write(" \r\n");
flagsend=false;
}else{
println("Start!");
myPort.write("T\r\n");
flagsend=true;
}
}
if((key=='D')||(key=='d')){println(val[0]+" "+val[1]+" "+val[2]+" "+val[3]);}
if((key=='P')||(key=='p')){flagprint = !flagprint;}
if((key=='R')||(key=='r')){
int taille = mesures3.length;
try{
dialogue.showOpenDialog(null); //affichage dialog box choix fichier
fichier = dialogue.getSelectedFile(); //on recup le fichier pointer dans la dialog box
if(fichier != null){
fstream = new FileWriter(fichier);
out = new BufferedWriter(fstream);//on creer un ecriteur de fichier
try{
for(int i = 0;i < taille;i++){
String lignevaleur = "";
lignevaleur = mesures0[i]+"\t"+mesures1[i]+"\t"+mesures2[i]+"\t"+mesures3[i]+"\n";
out.write(lignevaleur);
}
}catch (Exception ex){System.err.println("Error: " + ex.getMessage());}
out.close();
}
}catch (Exception ex){System.err.println("Error: " + ex.getMessage());}
}
if((key=='L')||(key=='l')){
int taille = mesures3.length;
for(int i = 0;i < taille;i++){
System.out.println(mesures0[i]+" "+mesures1[i]+" "+mesures2[i]+" "+mesures3[i]);
}
}
}
void serialEvent(Serial p){
rx = p.readChar();
//print(hex(tbl[irx]));
//print(" ");
if(rx != 0xFF){
tbl[irx] = rx;
irx++;
flagrx = false;
}else{
if(flagrx == false){
tbl[irx] = rx;
irx++;
flagrx = true;
}else{
//println("");
//println("trame recue");
for(int i=0;i<8;i=i+2){
val[i/2]=tbl[i]+tbl[i+1]*256;
//if(val[i/2]>1023){val[i/2]=1023;}
}
mesures0 = (int[])append(mesures0,val[0]);
mesures1 = (int[])append(mesures1,val[1]);
mesures2 = (int[])append(mesures2,val[2]);
mesures3 = (int[])append(mesures3,val[3]);
//println(val[0]+" "+val[1]+" "+val[2]+" "+val[3]);
irx = 0;
flagrx = false;
}
}
}
1