/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BodegaPOS.printer;

import BodegaPOS.*;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sebastian
 */
public class Print extends Thread {

    private List<String> lista;

    public Print() {
    }

    public List getLista() {
        return lista;
    }

    public void setLista(List lista) {
        this.lista = lista;
    }


    public void run() {
       
        PrinterCom printer = new PrinterCom("COM4");
        
        for (int i = 0; i < lista.size(); i++) {
            System.out.println(lista.get(i));
            try {
                printer.send((lista.get(i) + "\n").getBytes());
            } catch (IOException ex) {
                Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        byte[] cortar = new byte[3];
        cortar[0] = 0x1B;
        cortar[1] = 0x64;
        cortar[2] = 0x02;
        try {
            printer.send(cortar);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            printer.closeComms();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
