Serial port logging


Some simple programming for datalogging from RS-232.

Horiba VA-3000 logging


Programming:


import processing.serial.*;
Serial myPort; // The serial port:
PrintWriter output;
PFont fontA;
PFont fontB;
int x = 30;
String inString; // Input string from serial port:
String archivo;
int lf = 03; // ASCII end of text
byte[] myArray = {1,48,48,48,48,48,48,82,76,77,68,2,64,53,52,3};


void setup() {

 size(600, 300); //tamaƱo de la ventana en x,y

background(102);
stroke(255);
//smooth();
println(Serial.list()); // List all the available serial ports:
myPort = new Serial(this, Serial.list()1, 9600); //puerto 1 es COM5 para HoribaPC
// Create a new file in the sketch directory
archivo = (year() + "-" + month() + "-" + day() + " " + hour() + "h" + minute() + "m" + second() + "s.txt");
output = createWriter(archivo); //year() + "-" + month() + "-" + day() + " " + hour() + "h" + minute() + "m" + second() + "s.txt");
frameRate(0.2); //velocidad de captura de datos en FPS
fontA = loadFont("CourierNewPSMT-24.vlw");
fontB = loadFont("TheSans-Plain-12.vlw");
textFont(fontA, 24); // Set the font and its size (in units of pixels)
// Use fill() to change the value or color of the text
fill(0);
text("Rutina para leer datos Horiba VA-3000", x, 60);
fill(51);
text("por Fernando Vallejos-Burgos", x, 95);
fill(204);
text("Universidad de Concepcion, 2009", x, 130);
textFont(fontB, 12);
fill(71);
text("Manten presionada cualquier tecla para terminar", 330, 280);

}

void draw()
{

   fill(20);

rect(x-10, 160, 500, 100);
//point(mouseX, mouseY);
myPort.write(myArray);
myPort.bufferUntil(lf);
// Write the coordinate to a file with a
// "\t" (TAB character) between each entry
//output.println(hour() + ":" + minute() + ":" + second() + "\t" + mouseX + "\t" + mouseY);
output.println(inString);
output.flush(); // escribe los datos inmediatamente
textFont(fontB, 12);
fill(255);
text("Guardando en:", x, 180);
text(" " + archivo, x, 200);
text("Ultimos datos recibidos:", x, 220);
text(" " + inString, x, 240);
//text(hour() + ":" + minute() + ":" + second() + " " + mouseX + " " + mouseY, x, 260);

}

void keyPressed() { // Press a key to save the data

 output.flush(); // Write the remaining data

output.close(); // Finish the file
exit(); // Stop the program

}

void serialEvent(Serial p) {

 inString = (myPort.readString());

println(inString);

}



banner