Ir para conteúdo
  • Cadastre-se

dev botao

ACBRPostPrinter


Recommended Posts

Ola
Pessoal eu já tentei de tudo que vcs imanagem com Delphi alexandria.

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, ACBrBase, ACBrPosPrinter, System.Permissions,

  {$IFDEF ANDROID}
  Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os,
  FMX.ListBox, ACBrUtil.FilesIO, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo
  {$ENDIF} ;

type
  TfrmImpressora = class(TForm)
    Label1: TLabel;
    ACBrPosPrinter1: TACBrPosPrinter;
    cbxImpressorasBth: TComboBox;
    btnBuscarDispositivos: TButton;
    chbTodasBth: TCheckBox;
    Memo1: TMemo;
    procedure FormActivate(Sender: TObject);
    procedure btnBuscarDispositivosClick(Sender: TObject);
  private
    function PedirPermissoes: Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmImpressora: TfrmImpressora;

implementation

{$R *.fmx}
function TfrmImpressora.PedirPermissoes: Boolean;
begin
  Result := ACBrPosPrinter1.Device.PedirPermissoesBlueTooth;
end;

procedure TfrmImpressora.btnBuscarDispositivosClick(Sender: TObject);
var
  sl: TStringList;
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add('Iniciando...');
  if not PedirPermissoes then
  begin
    Memo1.Lines.Add('Sem permissão : not PedirPermissoes');
    exit;
  end else
  begin
    Memo1.Lines.Add('OK permissão : PedirPermissoes');
  end;

  cbxImpressorasBth.Items.Clear;
  try
    Memo1.Lines.Add('Iniciando...[AcharPortasBlueTooth]');
    ACBrPosPrinter1.Device.AcharPortasBlueTooth( cbxImpressorasBth.Items, chbTodasBth.IsChecked );
    cbxImpressorasBth.Items.Add('NULL');
    Memo1.Lines.Add('Finalzando...[FIM]');
  except
    on E:Exception do
    Memo1.Lines.Add('AcharPortasBlueTooth...[ERRO] '+E.Message);
  end;

  Memo1.Lines.Add('Iniciando...[FilesIO]');
  sl := TStringList.Create;
  try
    ACBrUtil.FilesIO.FindFiles('/dev/tty*', sl, True );
    cbxImpressorasBth.Items.AddStrings(sl);
  finally
    Memo1.Lines.Add('Iniciando...[FilesIO]');
    sl.Free;
  end;

end;

procedure TfrmImpressora.FormActivate(Sender: TObject);
var
  PermissionBLUETOOTH : String;
begin
    PedirPermissoes();
    Label1.Text := '1.5';
    
    
    PermissionBLUETOOTH := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH);
    PermissionsService.RequestPermissions([PermissionBLUETOOTH], (nil));


    PermissionBLUETOOTH := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH_ADMIN);
    PermissionsService.RequestPermissions([PermissionBLUETOOTH], (nil))

end;


end.

No OnActive eu coloquei 

    
    PermissionBLUETOOTH := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH);
    PermissionsService.RequestPermissions([PermissionBLUETOOTH], (nil));


    PermissionBLUETOOTH := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH_ADMIN);
    PermissionsService.RequestPermissions([PermissionBLUETOOTH], (nil))


Mas era só teste ta. Na teoria o ACBR na parte de pedirPermissão faria isto.

NA IDEI em todos ambientes de desenvolvimento marquei as duas opções de .BLUETOOTH.
Testei também desmarcado. 

Fora do ACBR tentei tb este tutorial porém eu sei que e muito antigo https://github.com/adrianosantostreina/impressora-bluetooth
Da erro external.

Tudo que tento da errado. Nem o demo do Acbr da certo.  Mesmo porque no meu exemplo iria fazer aos poucos. O codigo compartilhado acima e justamente do ACBR, e consiste incialmente somente em jogar os dispositivos no COMBO.

Eu estou a 2 dias com isso e tudo que tenho não funciona. 

Ah no codigo acima eu coloquei um memo pra saber se deu certo permissão então aconteceu em if not PedirPermissoes then e que passa em function TACBrDeviceBlueTooth.PedirPermissoes: Boolean;  tem directiva de  {$IfDef DELPHI28_UP}  normal ne? n e isso problema, na teoria isto era pra simplesmente funcionar e não funciona.

Editado por johnbh3
erro
Link para o comentário
Compartilhar em outros sites

Claro eu marquei além das duas permissões na IDE de BLUETOOTH e marquei também dangerous (rum time use aproval) adverse, connet e scan.
O Acbr já faz isto em

      LPermissions[0] := 'android.permission.BLUETOOTH_ADVERTISE';
      LPermissions[1] := 'android.permission.BLUETOOTH_CONNECT';
      LPermissions[2] := 'android.permission.BLUETOOTH_SCAN';

Por algum motivo da erro. Eu marquei tamném da IDE. E passei o  ACBrPosPrinter1.Device.PedirPermissoesBlueTooth para onAcative do form.

Eu refiz o demo, só com que precisava.

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, ACBrBase, ACBrPosPrinter, System.Permissions,
  System.TypInfo, System.StrUtils,

  {$IFDEF ANDROID}
  Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os,
  FMX.ListBox, ACBrUtil.FilesIO, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo,
  System.ImageList, FMX.ImgList, FMX.Gestures, FMX.Edit, FMX.EditBox,
  FMX.SpinBox, FMX.Layouts, FMX.TabControl
  {$ENDIF} ;

type
  TfrmImpressora = class(TForm)
    tabsPrincipal: TTabControl;
    tabConfig: TTabItem;
    ToolBar1: TToolBar;
    lblTituloConfig: TLabel;
    ListBox1: TListBox;
    ListBoxGroupHeader1: TListBoxGroupHeader;
    ListBoxGroupHeader5: TListBoxGroupHeader;
    lbiClasse: TListBoxItem;
    GridPanelLayout6: TGridPanelLayout;
    rbClasseInterna: TRadioButton;
    rbClasseExterna: TRadioButton;
    lbModelos: TListBoxItem;
    cbxModelo: TComboBox;
    cbxPagCodigo: TComboBox;
    Layout2: TLayout;
    cbControlePorta: TCheckBox;
    cbSmartPOS: TCheckBox;
    ListBoxGroupHeader2: TListBoxGroupHeader;
    lbImpressoras: TListBoxItem;
    cbxImpressorasBth: TComboBox;
    btnProcurarBth: TCornerButton;
    chbTodasBth: TCheckBox;
    ListBoxGroupHeader3: TListBoxGroupHeader;
    lbLarguraEspacejamento: TListBoxItem;
    GridPanelLayout1: TGridPanelLayout;
    Label2: TLabel;
    Label3: TLabel;
    Label7: TLabel;
    seColunas: TSpinBox;
    seEspLinhas: TSpinBox;
    seLinhasPular: TSpinBox;
    ListBoxGroupHeader4: TListBoxGroupHeader;
    lbCodBarras: TListBoxItem;
    GridPanelLayout5: TGridPanelLayout;
    Label1: TLabel;
    Label4: TLabel;
    cbHRI: TCheckBox;
    seBarrasLargura: TSpinBox;
    seBarrasAltura: TSpinBox;
    cbSuportaBMP: TCheckBox;
    lbBotoes: TListBoxItem;
    GridPanelLayout2: TGridPanelLayout;
    btLerConfig: TCornerButton;
    btSalvarConfig: TCornerButton;
    Layout1: TLayout;
    SpeedButton1: TSpeedButton;
    btnAtivar: TCornerButton;
    tabTeste: TTabItem;
    ToolBar2: TToolBar;
    lblTituloTestes: TLabel;
    btnBack: TSpeedButton;
    GridPanelLayout3: TGridPanelLayout;
    btnTiposLetra: TButton;
    btAlinhamento: TButton;
    btnBarras: TButton;
    btQRCode: TButton;
    btAcentos: TButton;
    btnLerStatus: TButton;
    btnLerInfo: TButton;
    btBeep: TButton;
    btnAbrirGaveta: TButton;
    btnCortarPapel: TButton;
    mImp: TMemo;
    GridPanelLayout4: TGridPanelLayout;
    btnImprimir: TCornerButton;
    btnLimpar: TCornerButton;
    StyleBook1: TStyleBook;
    GestureManager1: TGestureManager;
    ImageList1: TImageList;
    ACBrPosPrinter1: TACBrPosPrinter;
    procedure FormActivate(Sender: TObject);
    procedure btnProcurarBthClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnAtivarClick(Sender: TObject);
    procedure btnTiposLetraClick(Sender: TObject);
    procedure btnImprimirClick(Sender: TObject);
  private
    fsTemPermissao: Boolean;
    function PedirPermissoes: Boolean;
    function PedirPermissoes2: Boolean;
    procedure ConfigurarACBrPosPrinter;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmImpressora: TfrmImpressora;

implementation

{$R *.fmx}

function TfrmImpressora.PedirPermissoes2: Boolean;
var
  Ok: Boolean;
  LPermissions: TArray<String>;
begin
  Ok := fsTemPermissao;

  if not Ok then
  begin
    if (TOSVersion.Major < 12) then
    begin
      SetLength(LPermissions, 2);
      LPermissions[0] := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH);
      LPermissions[1] := JStringToString(TJManifest_permission.JavaClass.BLUETOOTH_ADMIN);
    end
    else
    begin
      SetLength(LPermissions, 3);
      LPermissions[0] := 'android.permission.BLUETOOTH_ADVERTISE';
      LPermissions[1] := 'android.permission.BLUETOOTH_CONNECT';
      LPermissions[2] := 'android.permission.BLUETOOTH_SCAN';
    end;
    mImp.Lines.Add('4');
    PermissionsService.RequestPermissions(LPermissions,
      procedure(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray)
      begin
        mImp.Lines.Add('5');
        Ok := (Length(AGrantResults) = Length(LPermissions));

        if Ok then
        begin
          for var GR in AGrantResults do
          begin
            if (GR <> TPermissionStatus.Granted) then
            begin
              Ok := False;
              Break;
            end;
          end;
        end;
      end, nil);
  end;

  fsTemPermissao := Ok;
  Result := Ok;
end;

function TfrmImpressora.PedirPermissoes: Boolean;
begin
  Result := ACBrPosPrinter1.Device.PedirPermissoesBlueTooth;
end;

procedure TfrmImpressora.ConfigurarACBrPosPrinter;
begin
  if not PedirPermissoes then
    exit;

  if rbClasseExterna.IsChecked then
  begin
    {if cbSmartPOS.IsChecked then
    begin
      fE1Printer.Modelo := TElginE1Printers.prnSmartPOS;
      fE1Lib.Modelo     := TElginE1LibPrinters.prnSmartPOS;
    end
    else
    begin
      fE1Printer.Modelo := TElginE1Printers.prnM8;
      fE1Lib.Modelo     := TElginE1LibPrinters.prnM8;
    end;

    case cbxModelo.ItemIndex of
      0: ACBrPosPrinter1.ModeloExterno := fE1Printer;
      1: ACBrPosPrinter1.ModeloExterno := fE1Lib;
      //2: ACBrPosPrinter1.ModeloExterno := fGEDIPrinter;
    else
      ACBrPosPrinter1.ModeloExterno := fSunmiPrinter;
    end;
    }
    cbxImpressorasBth.ItemIndex := cbxImpressorasBth.Items.IndexOf('NULL');
  end
  else
  begin
    if Assigned(cbxModelo.Selected) then
      ACBrPosPrinter1.Modelo := TACBrPosPrinterModelo(cbxModelo.ItemIndex)
    else
      ACBrPosPrinter1.Modelo := ppTexto;

    if Assigned(cbxImpressorasBth.Selected) then
      ACBrPosPrinter1.Porta := cbxImpressorasBth.Selected.Text
    else if cbxImpressorasBth.ItemIndex = cbxImpressorasBth.Items.IndexOf('NULL') then
      cbxImpressorasBth.ItemIndex := -1;
  end;

  if Assigned(cbxPagCodigo.Selected) then
    ACBrPosPrinter1.PaginaDeCodigo := TACBrPosPaginaCodigo(cbxPagCodigo.ItemIndex);

  ACBrPosPrinter1.ColunasFonteNormal := Trunc(seColunas.Value);
  ACBrPosPrinter1.EspacoEntreLinhas := Trunc(seEspLinhas.Value);
  ACBrPosPrinter1.LinhasEntreCupons := Trunc(seLinhasPular.Value);
  ACBrPosPrinter1.ConfigLogo.KeyCode1 := 1;
  ACBrPosPrinter1.ConfigLogo.KeyCode2 := 0;
  ACBrPosPrinter1.ControlePorta := cbControlePorta.IsChecked;
end;

procedure TfrmImpressora.btnAtivarClick(Sender: TObject);
begin
  ConfigurarACBrPosPrinter;
  ACBrPosPrinter1.Ativar;

  lblTituloTestes.Text := 'Testes em: '+ACBrPosPrinter1.Porta;
  mImp.Lines.Clear;
  tabsPrincipal.Next;
end;

procedure TfrmImpressora.btnImprimirClick(Sender: TObject);
begin
  ACBrPosPrinter1.Buffer.Text := mImp.Lines.Text;
  ACBrPosPrinter1.Imprimir;
 // ACBrPosPrinter1.Imprimir(mImp.Lines.Text);
end;

procedure TfrmImpressora.btnProcurarBthClick(Sender: TObject);
var
  sl: TStringList;
begin
  if not PedirPermissoes then
    exit;

  cbxImpressorasBth.Items.Clear;
  try
    ACBrPosPrinter1.Device.AcharPortasBlueTooth( cbxImpressorasBth.Items, chbTodasBth.IsChecked );
    cbxImpressorasBth.Items.Add('NULL');
  except
  end;

  sl := TStringList.Create;
  try
    ACBrUtil.FilesIO.FindFiles('/dev/tty*', sl, True );
    cbxImpressorasBth.Items.AddStrings(sl);
  finally
    sl.Free;
  end;
end;

procedure TfrmImpressora.btnTiposLetraClick(Sender: TObject);
begin
  mImp.Lines.Clear;
  mImp.Lines.Add('</zera>');
  mImp.Lines.Add('</linha_dupla>');
  mImp.Lines.Add('FONTE NORMAL: '+IntToStr(ACBrPosPrinter1.ColunasFonteNormal)+' Colunas');
  mImp.Lines.Add(LeftStr('....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8', ACBrPosPrinter1.ColunasFonteNormal));
  mImp.Lines.Add('<e>EXPANDIDO: '+IntToStr(ACBrPosPrinter1.ColunasFonteExpandida)+' Colunas');
  mImp.Lines.Add(LeftStr('....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8', ACBrPosPrinter1.ColunasFonteExpandida));
  mImp.Lines.Add('</e><c>CONDENSADO: '+IntToStr(ACBrPosPrinter1.ColunasFonteCondensada)+' Colunas');
  mImp.Lines.Add(LeftStr('....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8', ACBrPosPrinter1.ColunasFonteCondensada));
  mImp.Lines.Add('</c><n>FONTE NEGRITO</N>');
  mImp.Lines.Add('</corte_total>');
end;

procedure TfrmImpressora.FormActivate(Sender: TObject);
var
  PermissionBLUETOOTH : String;
begin
    if not PedirPermissoes2() then
    begin
      mImp.Lines.Add('Sem permissão onActive');
    end;

    ShowMessage('Versão 1.1');
end;


procedure TfrmImpressora.FormCreate(Sender: TObject);
var
  p: TACBrPosPaginaCodigo;
begin
  cbxPagCodigo.Items.Clear ;
  For p := Low(TACBrPosPaginaCodigo) to High(TACBrPosPaginaCodigo) do
    cbxPagCodigo.Items.Add( GetEnumName(TypeInfo(TACBrPosPaginaCodigo), integer(p) ) ) ;

end;

end.

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está agora fechado para novas respostas
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.