impresora en puerto com3
Publicado por Miguel Angel (1 intervención) el 05/12/2014 17:35:30
Que tal buen día, empiezo con la programación en java y mi primer proyecto en una parte tiene que imprimir en una impresora de tickets (thermal printer csn-a2-t) que tengo conectada al puerto com3 pero hasta ahora no he podido imprimir nada tengo esta clase que es la que mas me a ayudado, espero contar con su apoyo, muchas gracias.
public void print() throws Exception
{
Enumeration commports= CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier myCPI = null;
//Scanner mySC;
PrintStream myPS= null;
while(commports.hasMoreElements()){
myCPI=(CommPortIdentifier) commports.nextElement();
if(myCPI.getName().equals("COM3"))
System.out.println("Este es el puerto...");
break;
}
CommPort puerto=myCPI.open("COM3",2000);
SerialPort mySP= (SerialPort) puerto;
mySP.setSerialPortParams(19200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE );
//mySC = new Scanner(mySP.getInputStream());// recoge valores de entrada en el puierto
myPS = new PrintStream(mySP.getOutputStream());
try{
myPS.println("Prueba de impresion");
}catch(Exception ex){System.out.println(ex);}
/*while(!mySC.hasNextInt()){ //regresa el valor de entrada del puerto
mySC.close();
mySC=null;
mySC=new Scanner(mySP.getInputStream());
}
int valor=mySC.nextInt(); //se guarda el valor */
}
public void print() throws Exception
{
Enumeration commports= CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier myCPI = null;
//Scanner mySC;
PrintStream myPS= null;
while(commports.hasMoreElements()){
myCPI=(CommPortIdentifier) commports.nextElement();
if(myCPI.getName().equals("COM3"))
System.out.println("Este es el puerto...");
break;
}
CommPort puerto=myCPI.open("COM3",2000);
SerialPort mySP= (SerialPort) puerto;
mySP.setSerialPortParams(19200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE );
//mySC = new Scanner(mySP.getInputStream());// recoge valores de entrada en el puierto
myPS = new PrintStream(mySP.getOutputStream());
try{
myPS.println("Prueba de impresion");
}catch(Exception ex){System.out.println(ex);}
/*while(!mySC.hasNextInt()){ //regresa el valor de entrada del puerto
mySC.close();
mySC=null;
mySC=new Scanner(mySP.getInputStream());
}
int valor=mySC.nextInt(); //se guarda el valor */
}
Valora esta pregunta


0