Dúvida sobre AcbrPosPrinte

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

rossine
Usuário Nível 3
Usuário Nível 3
Mensagens: 325
Registrado em: 06 Ago 2007 09:57
Localização: Divinópolis-MG

Dúvida sobre AcbrPosPrinte

Mensagem 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,
Rossine.

Harbour 3.4, MingW / Msvc, QT, Qt5xhb, GtQtc, DbfCdx, MySql/MariaDB.
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

Dúvida sobre AcbrPosPrinte

Mensagem 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.
[]´s
Alexandre Santos (AlxSts)
lucimauro
Usuário Nível 3
Usuário Nível 3
Mensagens: 465
Registrado em: 21 Set 2004 21:02
Localização: Sobral-CE

Dúvida sobre AcbrPosPrinte

Mensagem por lucimauro »

Eu uso acbrPosprinter para abrira gaveta mais não faço tratamento.
rossine
Usuário Nível 3
Usuário Nível 3
Mensagens: 325
Registrado em: 06 Ago 2007 09:57
Localização: Divinópolis-MG

Dúvida sobre AcbrPosPrinte

Mensagem por rossine »

Bom dia,

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

Rossine.
Rossine.

Harbour 3.4, MingW / Msvc, QT, Qt5xhb, GtQtc, DbfCdx, MySql/MariaDB.
rossine
Usuário Nível 3
Usuário Nível 3
Mensagens: 325
Registrado em: 06 Ago 2007 09:57
Localização: Divinópolis-MG

Dúvida sobre AcbrPosPrinte

Mensagem 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,
Rossine.

Harbour 3.4, MingW / Msvc, QT, Qt5xhb, GtQtc, DbfCdx, MySql/MariaDB.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Dúvida sobre AcbrPosPrinte

Mensagem 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.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
Nascimento
Usuário Nível 4
Usuário Nível 4
Mensagens: 763
Registrado em: 19 Jul 2008 12:11
Localização: OLINDA-PE

Dúvida sobre AcbrPosPrinte

Mensagem por Nascimento »

tai uma coisa que gostei muito , deslocamento de bits usando o harbour , passei perrenga um tempo atrás
A arte de programar é simplesmente fazer seus pensamentos serem interpretados por uma maquina :) clipper 5.3 /harbour/minigui
rossine
Usuário Nível 3
Usuário Nível 3
Mensagens: 325
Registrado em: 06 Ago 2007 09:57
Localização: Divinópolis-MG

Dúvida sobre AcbrPosPrinte

Mensagem 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
Rossine.

Harbour 3.4, MingW / Msvc, QT, Qt5xhb, GtQtc, DbfCdx, MySql/MariaDB.
Responder