Página 1 de 1

Dúvida sobre AcbrPosPrinte

Enviado: 19 Jan 2023 17:49
por rossine
Boa tarde,

Alguém usar o AcbrLib , PosPrinter para retornar informações da Impressora e gaveta ?

Estou com dúvida neste parâmetro "status", como passar ele:

Código: Selecionar todos


SEQ.  NOME        TIPO       OPICIONAL   DESCRIÇÃO
01    Tentativas  Integer         Não       Quantidade de tentativas de receber as informações da impressora.
02    status      LongInt         Não       Número que representa as situações da impressora usando bit flags. <- Aqui...

Status:

    stNone = 0
    stErro = 1 << 0
    stNaoSerial = 1 << 1
    stPoucoPapel = 1 << 2
    stSemPapel = 1 << 3
    stGavetaAberta = 1 << 4
    stImprimindo = 1 << 5
    stOffLine = 1 << 6
    stTampaAberta = 1 << 7
    stErroLeitura = 1 << 8
    stSlip = 1 << 9
    stMICR = 1 << 10
    stAguardandoSlip = 1 << 11
    stTOF = 1 << 12
    stBOF = 1 << 13
Acima ele diz que a variável status é "bit flags", o que seria isto e como retornar os valores acima ?

Obrigado,

Dúvida sobre AcbrPosPrinte

Enviado: 19 Jan 2023 22:33
por alxsts
Olá!

Não entendo nada de C mas, pesquisando no Google, encontrei isto: https://wagnergaspar.com/operacoes-bit- ... a-direita/

Parece um left ou right nos bits de um byte de 8 bits...

Espero que ajude.

Dúvida sobre AcbrPosPrinte

Enviado: 19 Jan 2023 23:17
por lucimauro
Eu uso acbrPosprinter para abrira gaveta mais não faço tratamento.

Dúvida sobre AcbrPosPrinte

Enviado: 23 Jan 2023 09:01
por rossine
Bom dia,

Obrigado pelas informações e conseguindo resolver isto, posto a solução aqui.

Rossine.

Dúvida sobre AcbrPosPrinte

Enviado: 23 Jan 2023 11:00
por rossine
Olá,

O Marcos Gambeta me enviou este exemplo para exemplicar como trabalhar com "bits" no harbour:

Código: Selecionar todos

/*
SEQ.  NOME        TIPO       OPICIONAL   DESCRIÇÃO
01    Tentativas  Integer       Não      Quantidade de tentativas de receber as informações da impressora.
02    status      LongInt       Não      Número que representa as situações da impressora usando bit flags. <- Aqui...

Status:

    stNone = 0
    stErro = 1 << 0
    stNaoSerial = 1 << 1
    stPoucoPapel = 1 << 2
    stSemPapel = 1 << 3
    stGavetaAberta = 1 << 4
    stImprimindo = 1 << 5
    stOffLine = 1 << 6
    stTampaAberta = 1 << 7
    stErroLeitura = 1 << 8
    stSlip = 1 << 9
    stMICR = 1 << 10
    stAguardandoSlip = 1 << 11
    stTOF = 1 << 12
    stBOF = 1 << 13
*/

procedure main()

   local nStatus := 12345 // valor aleatorio para teste

   ? "DECIMAL=", nStatus
   ? "BINARIO=", dectobin(nStatus)
   ?

   //
   
   ? "VALORES"
   ? "stNone = 0"
   ? "stErro = 1 << 0", hb_bitshift(1, 0)
   ? "stNaoSerial = 1 << 1", hb_bitshift(1, 1)
   ? "stPoucoPapel = 1 << 2", hb_bitshift(1, 2)
   ? "stSemPapel = 1 << 3", hb_bitshift(1, 3)
   ? "stGavetaAberta = 1 << 4", hb_bitshift(1, 4)
   ? "stImprimindo = 1 << 5", hb_bitshift(1, 5)
   ? "stOffLine = 1 << 6", hb_bitshift(1, 6)
   ? "stTampaAberta = 1 << 7", hb_bitshift(1, 7)
   ? "stErroLeitura = 1 << 8", hb_bitshift(1, 8)
   ? "stSlip = 1 << 9", hb_bitshift(1, 9)
   ? "stMICR = 1 << 10", hb_bitshift(1, 10)
   ? "stAguardandoSlip = 1 << 11", hb_bitshift(1, 11)
   ? "stTOF = 1 << 12", hb_bitshift(1, 12)
   ? "stBOF = 1 << 13", hb_bitshift(1, 13)
   ?

   //
   
   ? "USANDO HB_BITTEST"

   if nStatus == 0
      ? "stNone = 0"
   endif

   if hb_bittest(nStatus, 0)
      ? "stErro = 1 << 0"
   endif

   if hb_bittest(nStatus, 1)
      ? "stNaoSerial = 1 << 1"
   endif

   if hb_bittest(nStatus, 2)
      ? "stPoucoPapel = 1 << 2"
   endif

   if hb_bittest(nStatus, 3)
      ? "stSemPapel = 1 << 3"
   endif

   if hb_bittest(nStatus, 4)
      ? "stGavetaAberta = 1 << 4"
   endif

   if hb_bittest(nStatus, 5)
      ? "stImprimindo = 1 << 5"
   endif

   if hb_bittest(nStatus, 6)
      ? "stOffLine = 1 << 6"
   endif

   if hb_bittest(nStatus, 7)
      ? "stTampaAberta = 1 << 7"
   endif

   if hb_bittest(nStatus, 8)
      ? "stErroLeitura = 1 << 8"
   endif

   if hb_bittest(nStatus, 9)
      ? "stSlip = 1 << 9"
   endif

   if hb_bittest(nStatus, 10)
      ? "stMICR = 1 << 10"
   endif

   if hb_bittest(nStatus, 11)
      ? "stAguardandoSlip = 1 << 11"
   endif

   if hb_bittest(nStatus, 12)
      ? "stTOF = 1 << 12"
   endif

   if hb_bittest(nStatus, 13)
      ? "stBOF = 1 << 13"
   endif
   
   ?

   //
   
   ? "USANDO HB_BITAND"

   if nStatus == 0
      ? "stNone = 0"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 0)) == hb_bitshift(1, 0)
      ? "stErro = 1 << 0"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 1)) == hb_bitshift(1, 1)
      ? "stNaoSerial = 1 << 1"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 2)) == hb_bitshift(1, 2)
      ? "stPoucoPapel = 1 << 2"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 3)) == hb_bitshift(1, 3)
      ? "stSemPapel = 1 << 3"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 4)) == hb_bitshift(1, 4)
      ? "stGavetaAberta = 1 << 4"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 5)) == hb_bitshift(1, 5)
      ? "stImprimindo = 1 << 5"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 6)) == hb_bitshift(1, 6)
      ? "stOffLine = 1 << 6"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 7)) == hb_bitshift(1, 7)
      ? "stTampaAberta = 1 << 7"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 8)) == hb_bitshift(1, 8)
      ? "stErroLeitura = 1 << 8"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 9)) == hb_bitshift(1, 9)
      ? "stSlip = 1 << 9"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 10)) == hb_bitshift(1, 10)
      ? "stMICR = 1 << 10"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 11)) == hb_bitshift(1, 11)
      ? "stAguardandoSlip = 1 << 11"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 12)) == hb_bitshift(1, 12)
      ? "stTOF = 1 << 12"
   endif

   if hb_bitand(nStatus, hb_bitshift(1, 13)) == hb_bitshift(1, 13)
      ? "stBOF = 1 << 13"
   endif

return

Valeu demais Marcos,

Dúvida sobre AcbrPosPrinte

Enviado: 23 Jan 2023 11:45
por JoséQuintas
Se entendi direito, já que retorna longint....
Vai retornar 0, 1, 2, 4, 8, 16, 32, 64, 128, ....
que pode ser testado pelo bit.
Só não dá pra saber se retorna vários status juntos, o que precisaria de cálculos, caso não use por bit.

Dúvida sobre AcbrPosPrinte

Enviado: 23 Jan 2023 12:56
por Nascimento
tai uma coisa que gostei muito , deslocamento de bits usando o harbour , passei perrenga um tempo atrás

Dúvida sobre AcbrPosPrinte

Enviado: 23 Jan 2023 15:57
por rossine
Olá,

Acredito estar fazendo a coisa certa porque vejam abaixo os exemplos em Java e C#, ambos passam para a função um parâmetro "por referencia".

Exemplo em Java:

Código: Selecionar todos

    public Set<ACBrPosTipoStatus> lerStatusImpressora(int tentativas) throws Exception {
        IntByReference status = new IntByReference(0);
        int ret = PosPrinterLib.INSTANCE.POS_LerStatusImpressora(tentativas, status);
        checkResult(ret);

        return ACBrPosTipoStatus.valueOf(status.getValue());
    }
Exemplo em C#

Código: Selecionar todos


    public ACBrPosTipoStatus LerStatusImpressora(int tentativas = 1)
        {
            var status = 0;
            var method = GetMethod<POS_LerStatusImpressora>();
            var ret = ExecuteMethod(() => method(libHandle, tentativas, ref status));

            CheckResult(ret);

            return (ACBrPosTipoStatus)status;
        }
... e no meu método também fiz da mesma maneira, mas o retorno de "nStatus" é sempre igual a ZERO.

Código: Selecionar todos

METHOD LerStatusImpressora( nTentativas, cRet ) CLASS ACBrGaveta

   local nStatus := 0

   __DefaultNIL( @nTentativas, 1 )
   __DefaultNIL( @cRet, "" )

   nResult := ::MyDllCall( "POS_LerStatusImpressora", nTentativas, @nStatus )

   ? nStatus

return ::CheckResult( nResult )
Ou está faltando algo aí ou é algum problema na DLL.

Link da documnentação:https://acbr.sourceforge.io/ACBrLib/POS ... ssora.html