Duvida em converter uma rotina

3 respostas
J

boa tarde a todos...
meu problema e o seguinte:
preciso imprimir um código qrcode em uma impressora Elgin i9
ela não tem se quer dll
e preciso imprimir direto para ela...
o fabricante me mandou este exemplo em C sharp
não trabalho com c sharp
trabalho com java...

alguém ai pode converter esta função para java pra mim por favor...
principalmente do treco:

byte length_low_byte=0, length_high_byte=0;
           length_low_byte = (byte)(length & 0xff);//low byte used in function 180 
           length_high_byte = (byte)((length >> 8) & 0xff);//high byte in function 180
public bool printQrcode(String Strdata,String szPrinterName) {
          int length = Strdata.Length+3; //  string size  + 3
           //int length = Strdata.Length; 
           byte length_low_byte=0, length_high_byte=0;
           length_low_byte = (byte)(length & 0xff);//low byte used in function 180 
           length_high_byte = (byte)((length >> 8) & 0xff);//high byte in function 180 

           //if you don't want to use shift operator:
            //int length_low_byte = length % 256;
            //int length_high_byte = length / 256;


           initializePrinter(szPrinterName);

          //<Function ESC a n> Select justification  
          int[] escAn = { 27,97,0}; 
          RawPrinterHelper.SendBytesToPrinter(szPrinterName,intTobyte(escAn));

         

            //<Function GS L> Set left margin
            int[] fGsl = {29,76,0,0};
            RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(fGsl));
          
            //<Function 165> GS ( k p L p H cn fn n (cn = 49,fn = 65)  QR Code: Select the model
            int[] f165 = {29,40,107,4,0,49,65,50,0};
            RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(f165)); 
          

            //<Function 167> GS ( k pL pH cn fn n (cn = 49, fn = 67) QR Code: Set the size of module
            int[] f167 = { 29, 40, 107, 3, 0, 49, 67,4}; //  size of qrcode:  1-16
            RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(f167)); 
         
           

            //<Function 169> GS ( k pL pH cn fn n (cn = 49, fn = 69) QR Code: Select the error correction level
            int[] f169 = { 29, 40, 107, 3, 0, 49, 69, 48 };
            RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(f169));   
           
             
            //<Function 180> GS ( k pL pH cn fn m d1?dk (cn = 49, fn = 80) QR Code: Store the data in the symbol storage area
            //pL and pH are the low- and high-order bytes of a 16-bit integer value that specifies the length in bytes of the following data  
             
             int[] f180 = { 29, 40, 107, length_low_byte, length_high_byte, 49, 80, 48 };
             RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(f180));
             
          
          
           //send string/url to printer
            //RawPrinterHelper.SendASCiiToPrinter(szPrinterName, Strdata);
             RawPrinterHelper.SendStringToPrinter(szPrinterName, Strdata);
           
           //<Function 181> GS ( k pL pH cn fn m (cn = 49, fn = 81) QR Code: Print the symbol data in the symbol storage area
           int[] f181={29,40,107,3,0,49,81,48};
           RawPrinterHelper.SendBytesToPrinter(szPrinterName, intTobyte(f181));
         
           //


           return true;
        }

3 Respostas

M

Cara, primeiramente, o código que voce postou compila no Java.

Segundo, você precisa achar as APIs equivalentes de RawPrinterHelper para o Java e o seu código já estara funcionando.

J

obrigado,
mas ate agora não achei nada que substitua
esta classe

L

Cara, também estou fazendo a programacao para essa impressora em java (e tenho o mesmo exemplo em c# do fabricante).
Vc precisa acessar diretamente a porta COM pelo java e utilizar o manual de programacao da impressora para enviar os bytes. Estou usando jssc e por enquanto tem funcionado bem.
Já conseguí imprimir texto e ean13, mas ainda nao consegui imprimir code128 e nao tentei qrcode.
Se precisar de ajuda para acessar, eh soh falar.
Se vc conseguiu imprimir os codigos de barras, quem precisa de ajuda sou eu :smile:
Abraço.

Criado 18 de setembro de 2015
Ultima resposta 17 de mar. de 2016
Respostas 3
Participantes 3