Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to load/save data from serial port to a .txt file?

$
0
0

Hello there,

Last week thanks to the help of GoToLoop I manage to get a RFIP reader to work. And eventually I made this code that shows a picture for a a few second if the RFID reader reads the correct card.

import processing.serial.Serial;

static final String COMPARADOR = "4500B8C02A17";
static final String DEPOSITO = "Deposito $50";
static final String SALDO = "Saldo en 0";

String mensaje = "Texto inicial";

int tiempo;
int espera = 5000;

PImage imagen;

int contador = 1;

void setup() {
  size(900, 600);
  frame.setBackground(new java.awt.Color(0, 0, 0));
  imagen = loadImage("1.jpg");

  String[] portas = Serial.list();
  printArray(portas);

  new Serial(this, portas[0], 9600).bufferUntil(ENTER);

  tiempo = millis();
}

void draw () {


  if (COMPARADOR.equals(mensaje)) {
    imageMode(CENTER);
    image(imagen, width/2, height/2);
    if (millis() - tiempo >= espera) {
      mensaje = SALDO;
      tiempo = millis();
      contador++;
    }
  } else {
    background(0);
  }



  println(mensaje);
  print("Pasada #: ");
  println(contador);
  print("Tiempo: ");
  println(tiempo);
}

void serialEvent(Serial s) {
  mensaje = s.readString().trim();
}

The thing is that there will be many cards and what I want is that each card can be used only once. So If a card is read for the first time, the image is displayed. If the same card is read later nothing happens.

So far I read about saving/loading data from a .txt file, and I guess this is the easiest way. To store (in a .txt file) the cards that have been read, and to check (in the same .txt file) every time a new card is read and if has been already read nothing happens, and if it is the first time is read the image is displayed.

I am trying but with no success, any ideas?

Thanks!


Viewing all articles
Browse latest Browse all 2896

Trending Articles