Ver Mensaje Individual
  #8 (permalink)  
Antiguo 22/04/2011, 19:23
geminis19
 
Fecha de Ingreso: febrero-2006
Mensajes: 58
Antigüedad: 18 años, 2 meses
Puntos: 0
Respuesta: imprimiendo en Impresora ibm 4610 1NR

Hola de nuevo, invie el entero inicial y final en vez del caracter, ahora la impresora me responde algo, pero no imprime nada.

Este es el código de retorno:

Los Bytes transformados a enteros
. 48
. 54
. 48
. 54
. 48
. 48
. 48
. 13

Como se logra apreciar el ultimo byte es el 13 en entero, según el manual este byte es porque la impresora esta retornando un error o warning, pero los tres primeros bytes si los junto no aparecen en el manual en la sección de errores.

Esta es la ultima modificación al código, en realidad modifique el metodo que envia el comando.

Código Javascript:
Ver original
  1. import java.util.List;
  2. import giovynet.nativelink.SerialPort;
  3. import giovynet.serial.Baud;
  4. import giovynet.serial.Com;
  5. import giovynet.serial.Parameters;
  6.  
  7. public class Impresora
  8. {
  9.     Com com;
  10.     Boolean sw=false;
  11.    
  12.     public static void main(String[] args)
  13.     {
  14.         new Impresora();
  15.     }
  16.    
  17.     public Impresora()
  18.     {
  19.         if(openCom("COM1"))
  20.         {
  21.             //Linea Inicio Comentario
  22.             sw=setCommand("60", "");
  23.                
  24.             //Linea Comentario
  25.             sw=setCommand("111", "Hola Mundo");
  26.                
  27.             //Linea Fin Comentario
  28.             sw=setCommand("61", "");
  29.                
  30.             //Linea Fin, con corte papel
  31.             sw=setCommand("99", "");
  32.                
  33.             if(!sw)
  34.                 System.out.println("Error en el envio de comandos.");
  35.             else
  36.             {
  37.                 System.out.println("Esperando respuesta!!");
  38.                 System.out.println("Respuesta: "+getResponse());
  39.             }
  40.                
  41.             if(!closeCom())
  42.                 System.out.println("Error al cerrar el puerto.");
  43.         }
  44.         else
  45.             System.out.println("Error al abrir el puerto.");
  46.     }
  47.    
  48.     public boolean openCom(String puerto)
  49.     {
  50.         SerialPort serialPort = new SerialPort();
  51.         List<String> portsFree = null;
  52.         try {
  53.             portsFree=serialPort.getFreeSerialPort();
  54.         }
  55.         catch (Exception e){
  56.             return false;
  57.         }
  58.  
  59.         if(portsFree!=null&&portsFree.size()>0)
  60.         {              
  61.             Parameters parameters = null;
  62.             try{
  63.                 parameters = new Parameters();
  64.             }
  65.             catch (Exception e){
  66.                 return false;
  67.             }
  68.            
  69.             parameters.setPort(puerto);
  70.             parameters.setBaudRate(Baud._19200);
  71.             parameters.setByteSize("8");
  72.             parameters.setParity("n");
  73.                
  74.             try{
  75.                 com=new Com(parameters);
  76.                 return true;
  77.             }
  78.             catch(Exception e) {
  79.                 System.out.println(e.getMessage());
  80.                 return false;
  81.             }
  82.         }
  83.         else
  84.             return false;
  85.     }
  86.    
  87.     public boolean closeCom()
  88.     {
  89.         try {
  90.             com.close();
  91.             return true;
  92.         }
  93.         catch (Exception e) {
  94.             return false;
  95.         }
  96.     }
  97.    
  98.     public boolean setCommand(String line, String comand)
  99.     {
  100.         try{
  101.             com.sendSingleData(135);
  102.         }
  103.         catch (Exception e) {
  104.             return false;
  105.         }
  106.        
  107.         String finalComand=line+comand;
  108.         for(int i=0; i<finalComand.toCharArray().length; i++)
  109.         {
  110.             try{
  111.                 com.sendSingleData(finalComand.toCharArray()[i]);
  112.             }catch(Exception e){
  113.                 return false;
  114.             }
  115.         }
  116.        
  117.         try{
  118.             com.sendSingleData(136);
  119.              return true;
  120.         }
  121.         catch (Exception e) {
  122.             return false;
  123.         }
  124.     }
  125.    
  126.     public String getResponse()
  127.     {
  128.         byte bytes=0;
  129.         String response=new String();
  130.                
  131.         while(bytes!=13 && bytes!=12)
  132.         {
  133.             try{
  134.                 bytes=(byte)com.receiveSingleChar();
  135.             }catch(Exception e){
  136.                 return "Read Port COM Error";
  137.             }
  138.        
  139.             if(bytes==10)
  140.                 break;
  141.             else
  142.                 response+=bytes;
  143.         }
  144.        
  145.         return response;
  146.     }
  147. }

Última edición por geminis19; 22/04/2011 a las 19:50