Skip to content

Commit e3b5727

Browse files
committed
[*] Atualizado as dependências.
[+] Iniciado a função para retornar as informações da impressora.
1 parent e23bc79 commit e3b5727

22 files changed

Lines changed: 203 additions & 48 deletions

src/OpenAC.Net.EscPos.Demo/Form1.Designer.cs

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/OpenAC.Net.EscPos.Demo/Form1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ private void txtModoPagina_Click(object sender, EventArgs e)
436436
posprinter.Imprimir();
437437
}
438438

439+
private void btnInfo_Click(object sender, EventArgs e)
440+
{
441+
using var posprinter = GetPosPrinter();
442+
443+
posprinter.Conectar();
444+
var info = posprinter.LerInfoImpressora();
445+
}
446+
439447
#endregion EventHandlers
440448
}
441449
}

src/OpenAC.Net.EscPos.Demo/OpenAC.Net.EscPos.Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="NLog" Version="4.7.15" />
1313
<PackageReference Include="NLog.Windows.Forms" Version="4.5.0" />
14-
<PackageReference Include="OpenAC.Net.Devices" Version="1.5.0-preview.1" />
14+
<PackageReference Include="OpenAC.Net.Devices" Version="1.5.0-preview.3" />
1515
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0-preview.2.22152.2" />
1616
</ItemGroup>
1717

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// ***********************************************************************
2+
// Assembly : OpenAC.Net.EscPos
3+
// Author : Rafael Dias
4+
// Created : 17-03-2022
5+
//
6+
// Last Modified By : Rafael Dias
7+
// Last Modified On : 17-03-2022
8+
// ***********************************************************************
9+
// <copyright file="InformacoesImpressora.cs" company="OpenAC .Net">
10+
// The MIT License (MIT)
11+
// Copyright (c) 2014 - 2021 Projeto OpenAC .Net
12+
//
13+
// Permission is hereby granted, free of charge, to any person obtaining
14+
// a copy of this software and associated documentation files (the "Software"),
15+
// to deal in the Software without restriction, including without limitation
16+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+
// and/or sell copies of the Software, and to permit persons to whom the
18+
// Software is furnished to do so, subject to the following conditions:
19+
// The above copyright notice and this permission notice shall be
20+
// included in all copies or substantial portions of the Software.
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
// DEALINGS IN THE SOFTWARE.
28+
// </copyright>
29+
// <summary></summary>
30+
// ***********************************************************************
31+
32+
namespace OpenAC.Net.EscPos.Commom
33+
{
34+
public class InformacoesImpressora
35+
{
36+
#region Constructors
37+
38+
public InformacoesImpressora(string fabricante, string modelo, string firmware, bool guilhotina)
39+
{
40+
Fabricante = fabricante;
41+
Modelo = modelo;
42+
Firmware = firmware;
43+
Guilhotina = guilhotina;
44+
}
45+
46+
#endregion Constructors
47+
48+
#region Properties
49+
50+
public string Fabricante { get; }
51+
52+
public string Modelo { get; }
53+
54+
public string Firmware { get; }
55+
56+
public bool Guilhotina { get; }
57+
58+
public static InformacoesImpressora Empty = new("", "", "", false);
59+
60+
#endregion Properties
61+
}
62+
}

src/OpenAC.Net.EscPos/EscPosPrinter.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Linq;
3636
using System.Reflection;
3737
using System.Text;
38+
using System.Threading;
3839
using OpenAC.Net.Core;
3940
using OpenAC.Net.Core.Extensions;
4041
using OpenAC.Net.Core.Logging;
@@ -286,13 +287,15 @@ public EscPosTipoStatus LerStatusImpressora(int tentativas = 1)
286287
{
287288
Guard.Against<OpenException>(!Conectado, "A porta não está aberta");
288289

290+
if (interpreter.Status == null) return EscPosTipoStatus.ErroLeitura;
291+
289292
try
290293
{
291294
byte[][] ret;
292295
var leituras = 0;
293296
do
294297
{
295-
var dados = interpreter.StatusCommand;
298+
var dados = interpreter.Status.Commands;
296299
if (dados.IsNullOrEmpty()) return EscPosTipoStatus.Nenhum;
297300

298301
ret = dados.Select(dado => device.WriteRead(dado, 10)).ToArray();
@@ -301,7 +304,7 @@ public EscPosTipoStatus LerStatusImpressora(int tentativas = 1)
301304

302305
if (!ret.Any()) return EscPosTipoStatus.ErroLeitura;
303306

304-
var status = interpreter.ProcessarStatus(ret);
307+
var status = interpreter.Status.Resolve(ret);
305308
if (!Gaveta.SinalInvertido) return status;
306309

307310
if (status.HasFlag(EscPosTipoStatus.GavetaAberta))
@@ -318,6 +321,31 @@ public EscPosTipoStatus LerStatusImpressora(int tentativas = 1)
318321
}
319322
}
320323

324+
/// <summary>
325+
/// Le as informações da impressora.
326+
/// </summary>
327+
/// <returns></returns>
328+
public InformacoesImpressora LerInfoImpressora()
329+
{
330+
Guard.Against<OpenException>(!Conectado, "A porta não está aberta");
331+
332+
if (interpreter.InfoImpressora == null) return InformacoesImpressora.Empty;
333+
334+
try
335+
{
336+
var dados = interpreter.InfoImpressora.Commands;
337+
if (dados.IsNullOrEmpty()) return null;
338+
339+
var ret = dados.Select(dado => device.WriteRead(dado, 500)).ToArray();
340+
return !ret.Any() ? InformacoesImpressora.Empty : interpreter.InfoImpressora.Resolve(ret);
341+
}
342+
catch (Exception ex)
343+
{
344+
this.Log().Error("Erro ao ler as informações da impressora", ex);
345+
return InformacoesImpressora.Empty;
346+
}
347+
}
348+
321349
/// <summary>
322350
/// Adiciona o comando de pular linhas ao buffer.
323351
/// </summary>

src/OpenAC.Net.EscPos/Interpreter/Bematech/BematechInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal BematechInterpreter(Encoding enconder) : base(enconder)
5353
/// <inheritdoc />
5454
protected override void IniciarInterpreter()
5555
{
56-
StatusResolver = new BematechStatusResolver();
56+
Status = new BematechStatusResolver();
5757

5858
CommandResolver.AddResolver<TextCommand, DefaultTextResolver>(new DefaultTextResolver(Enconder, DefaultCommands.EscBema));
5959
CommandResolver.AddResolver<ZeraCommand, DefaultZeraResolver>(new DefaultZeraResolver(DefaultCommands.EscBema));

src/OpenAC.Net.EscPos/Interpreter/Bematech/BematechStatusResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace OpenAC.Net.EscPos.Interpreter.Bematech
3838
{
39-
public sealed class BematechStatusResolver : StatusResolver
39+
public sealed class BematechStatusResolver : InfoResolver<EscPosTipoStatus>
4040
{
4141
public BematechStatusResolver() :
4242
base(new[] { new byte[] { CmdConst.GS, 248, (byte)'1' } },

src/OpenAC.Net.EscPos/Interpreter/Daruma/DarumaInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal DarumaInterpreter(Encoding enconder) : base(enconder)
5151

5252
protected override void IniciarInterpreter()
5353
{
54-
StatusResolver = new DarumaStatusResolver();
54+
Status = new DarumaStatusResolver();
5555
RazaoColuna.Condensada = 0.8421M; // 48 / 57
5656

5757
var commandos = new Dictionary<CmdEscPos, byte[]>

src/OpenAC.Net.EscPos/Interpreter/Daruma/DarumaStatusResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace OpenAC.Net.EscPos.Interpreter.Daruma
3838
{
39-
public sealed class DarumaStatusResolver : StatusResolver
39+
public sealed class DarumaStatusResolver : InfoResolver<EscPosTipoStatus>
4040
{
4141
public DarumaStatusResolver() :
4242
base(new[] { new byte[] { CmdConst.ENQ }, new byte[] { CmdConst.GS, CmdConst.ENQ } },

src/OpenAC.Net.EscPos/Interpreter/Datecs/DatecsInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal DatecsInterpreter(Encoding enconder) : base(enconder)
5656
/// <inheritdoc />
5757
protected override void IniciarInterpreter()
5858
{
59-
StatusResolver = new EpsonStatusResolver();
59+
Status = new EpsonStatusResolver();
6060

6161
var commandos = DefaultCommands.EscPos.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
6262
commandos[CmdEscPos.Beep] = new[] { CmdConst.BELL };

0 commit comments

Comments
 (0)