Jump to content

dev botao

Exemplo de utilização ACBr32.dll


  • Este tópico foi criado há 4213 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts

Estou utilizando a dll ACBr32.dll em um projeto em Deplhi 6 para controle de impressoras. Não consegui instalar os componentes do ACBr no Delphi por conta de outros pacotes que o meu sistema utiliza e que não podem ser retirados (algum outro programador criou) que não permitem que o ACBr seja instalado (dá erro na instalação do ACBrSerial.dpk).

Fiz um projetinho simples em Delphi apenas para testar a ativação da porta da impressora mas não sei o que posso estar fazendo de errado. Alguém pode me ajudar. Abaixo vai o código com o click do botão que ativa a impressora:

unit Unit1; 


interface 


uses 

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 

Forms, Dialogs, StdCtrls; 


type 

TForm1 = class(TForm) 

Button1: TButton; 

procedure Button1Click(Sender: TObject); 

private 

{ Private declarations } 

public 

{ Public declarations } 

end; 


var 


Form1: TForm1; 

Function ECF_Create(const ecfHandle: pointer) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_SetModelo(const ecfHandle: pointer; const Modelo : Integer) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_SetPorta(const ecfHandle: pointer; const Porta : pChar) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_Ativar(const ecfHandle: pointer) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_Desativar(const ecfHandle: pointer) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_AbreCupom(const ecfHandle: pointer; const CPF_CNPJ, Nome, Endereco : pChar) : Integer; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 

Function ECF_CancelaCupom(const ecfHandle: pointer) : Integer ; {$IFDEF STDCALL} stdcall; {$ENDIF} {$IFDEF CDECL} cdecl; {$ENDIF} external 'ACBr32.dll'; 


implementation 


//*Modelos de ECF 

const 

ECF_Nenhum = 0; 

ECF_NaoFiscal = 1; 

ECF_Bematech = 2; 

ECF_Sweda = 3; 

ECF_Daruma = 4; 

ECF_Schalter = 5; 

ECF_Mecaf = 6; 

ECF_Yanco = 7; 

ECF_DataRegis = 8; 

ECF_Urano = 9; 

ECF_ICash = 10; 

ECF_Quattro = 11; 

ECF_FiscNET = 12; 

ECF_Epson = 13; 

ECF_NCR = 14; 

ECF_SwedaSTX = 15; 


//*ESTADOS DO ECF 

ESTADO_NaoInicializada = 0; 

ESTADO_Desconhecido = 1; 

ESTADO_Livre = 2; 

ESTADO_Venda = 3; 

ESTADO_Pagamento = 4; 

ESTADO_Relatorio = 5; 

ESTADO_Bloqueada = 6; 

ESTADO_RequerZ = 7; 

ESTADO_RequerX = 8; 

ESTADO_NaoFiscal = 9; 


{$R *.dfm} 


procedure TForm1.Button1Click(Sender: TObject); 

var 

ihandle : ^integer; 

i: integer; 

begin 

ECF_Create(@ihandle); 

ECF_SetPorta(ihandle,PChar('COM1')); //AQUI DÁ UM ERRO DE ACCESS VIOLATION 

ECF_SetModelo(ihandle,ECF_Daruma); 

i:= ECF_Ativar(ihandle); 

showmessage(inttostr(i)); //AQUI PEGO O RETORNO DA FUNÇÃO PARA VER SE ESTÁ ATIVANDO 

end; 

Alguém pode me ajudar?

Link to comment
Share on other sites

usa esse exemplo


unit UnitDeclaracao;


interface


{$IFDEF MSWINDOWS}

function DefineModelo(ModeloStr, Porta : String ; Timeout : Integer ): Boolean; stdcall; External 'ACBrECFDLL.DLL';

function IdentificaConsumidor( CPF_CNPJ : String; Nome : String = ''; Endereco : String = '') : Integer ; stdcall;  External 'ACBrECFDLL.DLL';

Function AbreCupom( CPF_CNPJ : String = ''; Nome : String = '';

                    Endereco : String = '') : Integer ; stdcall; External 'ACBrECFDLL.DLL';

Function VendeItem( Codigo, Descricao : String; AliquotaICMS : String;

                    Qtd : Double ; ValorUnitario : Double; DescontoPorc : Double = 0;

                    Unidade : String = ''; TipoDescontoAcrescimo : String = '%') : Integer ; stdcall; External 'ACBrECFDLL.DLL';

Function SubtotalizaCupom( DescontoAcrescimo : Double = 0;

                             MensagemRodape : String = '') : Integer ; stdcall ; External 'ACBrECFDLL.DLL';

Function EfetuaPagamento( CodFormaPagto : String; Valor : Double;

                           Observacao : String = ''; ImprimeVinculado : Boolean = false) : Integer ; stdcall ; External 'ACBrECFDLL.DLL';

Function FechaCupom( Observacao : String = '') : Integer ; stdcall ; External 'ACBrECFDLL.DLL';

Function LeituraX : Integer ; stdcall ;  External 'ACBrECFDLL.DLL';

Function ReducaoZ( DataHora : TDateTime = 0 ) : Integer ; stdcall ; External 'ACBrECFDLL.DLL';

Function CancelaCupom  : Integer ; stdcall ;  External 'ACBrECFDLL.DLL';

Function CancelaItemVendido( NumItem : Integer ) : Integer ; stdcall ;  External 'ACBrECFDLL.DLL';

{$ENDIF}


{$IFDEF LINUX}

function DefineModelo(ModeloStr, Porta : String ; Timeout : Integer ): Boolean; cdecl; External 'libACBrECFDLL.so';

function IdentificaConsumidor( CPF_CNPJ : String; Nome : String = ''; Endereco : String = '') : Integer ; cdecl;  External 'libACBrECFDLL.so';

Function AbreCupom( CPF_CNPJ : String = ''; Nome : String = '';

                    Endereco : String = '') : Integer ; cdecl; External 'libACBrECFDLL.so';

Function VendeItem( Codigo, Descricao : String; AliquotaICMS : String;

                    Qtd : Double ; ValorUnitario : Double; DescontoPorc : Double = 0;

                    Unidade : String = ''; TipoDescontoAcrescimo : String = '%') : Integer ; cdecl; External 'libACBrECFDLL.so';

Function SubtotalizaCupom( DescontoAcrescimo : Double = 0;

                             MensagemRodape : String = '') : Integer ; cdecl ; External 'libACBrECFDLL.so';

Function EfetuaPagamento( CodFormaPagto : String; Valor : Double;

                           Observacao : String = ''; ImprimeVinculado : Boolean = false) : Integer ; cdecl ; External 'libACBrECFDLL.so';

Function FechaCupom( Observacao : String = '') : Integer ; cdecl ; External 'libACBrECFDLL.so';

Function LeituraX : Integer ; cdecl ;  External 'libACBrECFDLL.so';

Function ReducaoZ( DataHora : TDateTime = 0 ) : Integer ; cdecl ; External 'libACBrECFDLL.so';

Function CancelaCupom  : Integer ; cdecl ;  External 'libACBrECFDLL.so';

Function CancelaItemVendido( NumItem : Integer ) : Integer ; cdecl ;  External 'libACBrECFDLL.so';

{$ENDIF}


implementation


end.


http://www.rdwtecnologia.com.br/

Rodnei Hernandes Lino

Um pouco ce conhecimento é uma coisa perigosa.

Então é muito. (-Albert Einstein)

Guaíra-SP

Link to comment
Share on other sites

Como eu faria isso? se eu tento alterar a dll (ACBrECFDLL.dll), na hora de compilar, dá o erro: "Record, object or class type required"

Esse erro dá na seguinte linha da unit ACBrEAD:

Procedure TACBrEAD.CalcularModuloeExpoente( var Modulo, Expoente : AnsiString );

Var

  Bio : pBIO;

  Ver : String ;

begin

  Ver := OpenSSL_Version;

  if pos('1.0',Ver) > 0 then

     raise Exception.Create( ACBrStr('Método CalcularModuloeExpoente ainda não é '+

                                     'compatível com OpenSSL 1.0.0 ou superior'));


  LerChavePrivada();


  Modulo   := '';

  Expoente := '';

  Bio := CriarMemBIO;

  try

    BN_print( Bio , fsKey.pkey.rsa.e); //AQUI DÁ O ERRO, COMO SE ELE NÃO RECONHECESSE ESSE "e" NO FINAL.  

    Modulo := BioToStr( Bio );


    BIO_reset( Bio );

    BN_print( Bio , fsKey.pkey.rsa.d);

    Expoente := BioToStr( Bio );

  finally

    LiberarBIO( Bio ) ;

    LiberarChave;

  end ;

end ;

Link to comment
Share on other sites

Pessoal, há dois problemas básicos aí:

1. O projeto ACBrECFDLL.dll não é a mesma coisa que o ACBr32.dll.

O ACBr32.dll fica em "Projetos\ACBr32_DLL" e o ACBrDLL em "Projetos\ACBrDLL"

Assim como o ACBr32.dll, este outro projeto é também uma tentativa de exportar o componente ECF do ACBr para uma DLL, mas feito de forma diferente do ACBr32.dll; Alguma coisa é semelhante, mas não há compatibilidade nem suporte pelo ACBr32.dll

2. O projeto ACBr32.dll foi feito para o uso em QUALQUER linguagem de programação. Inclusive em Delphi.

Em Delphi, concordamos que o natural é utilizar os componentes ACBr, mas não há impedimentos em utilizar a ACBr32.dll.

Neste caso, não temos um exemplo feito em Delphi, o programador pode basear-se nos exemplos feitos em C ou em FoxPro que utiliza a DLL diretamente, basta seguir as declarações da DLL no código em Delphi.

O problema nesse caso, não é que não exista a função para desativar a impressora, você só não declarou as funções em seu código Delphi, por isso não funciona.

***

Com o aumento da audiência do ACBr32.dll, eu estou escrevendo um artigo sobre o trabalho desenvolvido até agora, e acredito que será útil para quem quiser contribuir com o desenvolvimento deste projeto, e talvez mais útil ainda para quem quiser entender o porquê das "doideiras" desse projeto.

Abs,

Rafael Batiati

ACBrFramework - Automação comercial para todos.

MultiClubes - Soluções para a área de clubes, parques, lazer e entretenimento.

Link to comment
Share on other sites

  • Este tópico foi criado há 4213 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.