Ir para conteúdo
  • Cadastre-se

dev botao

Configurar Impressora no ACBrMonitor.INI automaticamente


Ver Solução Respondido por Daniel Simoes,
  • Este tópico foi criado há 2122 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts

Bom dia.

Como faço para obter o nome correto da impressora igual o do acbr ?

Gostaria de saber como o ACBrMonitor obtem o nome das impressoras do sistema, pois estou utilizando a impressora MP-4200 TH e lá no acbr em DF-e > Impressão > (aba NFC-e) > Impressora Padrão - este checkbox aparece a impressora com o nome exatamente MP-4200 TH.

No meu sistema, feito em Vb.Net, estou utilizando o método abaixo para obter o nome da impressora. Porém, o nome que me é retornado é Bematech MP-4200 TH (COM4). Tentei colocar este nome lá no acbrmonitor.ini e o mesmo não aceitou, coloquei só Bematech MP-4200 TH e também não. Ele só aceita se colocar MP-4200 TH. Que é uma das opções que aparece no checkbox.

Preciso desta solução pois 2 clientes meus por algum motivo desconhecido perderam a configuração da impressora no ACBRMonitor. Entrei lá para verificar e o campo da impressora estava em branco.

Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_PnPEntity")

 For Each queryObj As ManagementObject In searcher.Get()
    If InStr(queryObj("Caption"), "(COM") > 0 Then
        'Console.WriteLine("serial port : {0}", queryObj("Caption"))
        edt_portaECF.Items.Add(queryObj("Caption").ToString)
    End If
Next

 

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

  • Fundadores
  • Solution

O Lazarus/FPC facilita muito isso..

  cbxBOLImpressora.Items.Clear;
  cbxBOLImpressora.Items.Assign(Printer.Printers); 

Ou seja, Printer.Printers retorna uma Lista com as impressoras do Sistema... seja em Windows ou Linux...

GetPrinters, em Windows, irá evocar o método abaixo:

//Enum all defined printers. First printer it's default
procedure TWinPrinter.DoEnumPrinters(Lst: TStrings);
var
  Flags          : DWORD;
  Level          : DWORD;
  PrtCount       : DWORD;
  Needed         : DWORD;
  Buffer         : PByte;
  InfoPrt        : PByte;
  i              : Integer;
  DefaultPrinter : string;
  PDev           : TPrinterDevice;
  TmpDevModeW     : PDeviceModeW;
  PrtStr         : string;
  BoolRes: LCLType.BOOL;
  B: Boolean;
begin
  {$IFDEF NOPRINTERS}
  Lst.Clear;
  exit;
  {$ENDIF}
  DefaultPrinter := GetDefaultPrinter;

  Flags := PRINTER_ENUM_CONNECTIONS or PRINTER_ENUM_LOCAL;
  Level := 2;

  //Evaluate buffer size
  Needed := 0;
  EnumPrintersW(Flags, nil, Level, nil, 0, @Needed, @PrtCount);
  if Needed <> 0 then
  begin
    GetMem(Buffer, Needed);
    Fillchar(Buffer^, Needed, 0);
    try
      //Enumerate Printers
      BoolRes := EnumPrintersW(Flags, nil, Level, Buffer, Needed, @Needed, @PrtCount);
      if BoolRes then
      begin
        InfoPrt := Buffer;
        for i := 0 to PrtCount - 1 do
        begin
          if Level = 2 then
          begin
            PDev := TPrinterDevice.Create;
            PDev.Name := UTF8Encode(widestring(PPRINTER_INFO_2W(InfoPrt)^.pPrinterName));
            PDev.Driver := UTF8Encode(widestring(PPRINTER_INFO_2W(InfoPrt)^.pDriverName));
            PDev.Port := UTF8Encode(widestring(PPRINTER_INFO_2W(InfoPrt)^.pPortName));
            TmpDevModeW := PPRINTER_INFO_2W(InfoPrt)^.pDevMode;


            if (TmpDevModeW <> nil) then
            begin
              // the devmode structure obtained this way have two problems
              // 1. It's not the full devmode, because it doesn't have
              //    the private info
              // 2. It's not initialized with the current settings and
              //    have not extra settings at all.
              //
              // PDev.DevMode:=PPRINTER_INFO_2(InfoPrt)^.PDevMode^;
              PDev.Device := UTF8Encode(widestring(TmpDevModeW^.dmDeviceName));
              PDev.DefaultPaperName := UTF8Encode(widestring(TmpDevModeW^.dmFormName));
              PDev.DefaultPaper := TmpDevModeW^.dmPaperSize;
              PDev.DefaultBin   := TmpDevModeW^.dmDefaultSource;

            end
            else begin
              PDev.Device:='';
              PDev.DefaultPaper:=0;
              PDev.DefaultBin  := 0
            end;
            PrtStr := PDev.Name;
            B := CompareText(PrtStr, DefaultPrinter)<>0;

            if B then
              Lst.AddObject(PrtStr,PDev)
            else
            begin
              Lst.Insert(0,PrtStr);
              Lst.Objects[0]:=PDev;
            end;
            Inc(InfoPrt,SizeOf(_PRINTER_INFO_2W));
          end;
        end;
      end;
    finally
      FreeMem(Buffer);
    end;
  end;
end;   

 

Consultor SAC ACBr

Daniel Simões de Almeida
O melhor TEF, é com o Projeto ACBr - Clique e Conheça
Ajude o Projeto ACBr crescer - Assine o SAC

Projeto ACBr     Telefone:(15) 2105-0750 WhatsApp(15)99790-2976.

Link para o comentário
Compartilhar em outros sites

  • Este tópico foi criado há 2122 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.
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.

The popup will be closed in 10 segundos...