Ver Mensaje Individual
  #6 (permalink)  
Antiguo 07/04/2015, 12:17
dragonfire256
 
Fecha de Ingreso: septiembre-2011
Ubicación: Caracas
Mensajes: 240
Antigüedad: 12 años, 7 meses
Puntos: 9
Respuesta: Enviar comandos a la impresora via socket

Cita:
Iniciado por Profesor_Falken Ver Mensaje
Puedes poner como ha quedado el codigo tras hacer la adaptacion?
Has intentado seguir el tutorial que te he puesto por tu cuenta?


Un saludo
Hola Falken

Aqui te anexo la version modificada

Código Java:
Ver original
  1. char ESC = (char)27; //Ascii character for Escape
  2. char CR = (char) 13; //Ascii character for Carriage Return
  3. //I make another stuff here
  4. Socket socket = null;
  5. PrintWriter out = null;
  6. BufferedReader in =null;
  7. String response;
  8. // Aqui hago la captura de la excepcion
  9. socket = new Socket(address,port);
  10. out = new PrintWriter(conec.getOutputStream(), true);
  11. in = new BufferedReader(new InputStreamReader(conec.getInputStream()));
  12. //Aqui continuo con la excepcion
  13. if (socket != null && in != null && out != null)
  14.             {
  15.                 try
  16.                 {
  17.                     String cmd=ESC+command+CR;
  18.                     out.print(cmd);
  19.  
  20.                         while ((response= in.readLine()) != null) {    
  21.                             System.out.println(response);
  22.                         }
  23.  
  24.                     out.close();
  25.                     in.close();
  26.                     socket.close();
  27.                 }
  28.                 catch (Exception e)
  29.                 {
  30.                     System.out.println(e.toString());
  31.  
  32.                 }
  33.             }