Skip to content

Commit 4798315

Browse files
committed
[+] Adicionado leitura de informações para o protoclo EscPos.
1 parent 4455016 commit 4798315

8 files changed

Lines changed: 37 additions & 37 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ private void btnInfo_Click(object sender, EventArgs e)
429429

430430
posprinter.Conectar();
431431
var info = posprinter.LerInfoImpressora();
432+
rtbLog.AppendText(info.ToString());
432433
}
433434

434435
#endregion EventHandlers

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.3" />
14+
<PackageReference Include="OpenAC.Net.Devices" Version="1.5.0-preview.4" />
1515
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0-preview.2.22152.2" />
1616
</ItemGroup>
1717

src/OpenAC.Net.EscPos/Commom/InformacoesImpressora.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@
2929
// <summary></summary>
3030
// ***********************************************************************
3131

32+
using System.Linq;
33+
using System.Text;
34+
3235
namespace OpenAC.Net.EscPos.Commom
3336
{
3437
public class InformacoesImpressora
3538
{
3639
#region Constructors
3740

38-
public InformacoesImpressora(string fabricante, string modelo, string firmware, bool guilhotina)
41+
public InformacoesImpressora(string fabricante, string modelo, string firmware, string serial, bool guilhotina)
3942
{
4043
Fabricante = fabricante;
4144
Modelo = modelo;
4245
Firmware = firmware;
46+
Serial = serial;
4347
Guilhotina = guilhotina;
4448
}
4549

@@ -53,10 +57,21 @@ public InformacoesImpressora(string fabricante, string modelo, string firmware,
5357

5458
public string Firmware { get; }
5559

60+
public string Serial { get; }
61+
5662
public bool Guilhotina { get; }
5763

58-
public static InformacoesImpressora Empty = new("", "", "", false);
64+
public static InformacoesImpressora Empty = new("", "", "", "", false);
5965

6066
#endregion Properties
67+
68+
public override string ToString()
69+
{
70+
var props = GetType().GetProperties();
71+
var sb = new StringBuilder();
72+
foreach (var p in props)
73+
sb.AppendLine(p.Name + ": " + p.GetValue(this, null));
74+
return sb.ToString();
75+
}
6176
}
6277
}

src/OpenAC.Net.EscPos/Interpreter/Epson/EpsonInfoImpressoraResolver.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,21 @@ namespace OpenAC.Net.EscPos.Interpreter.Epson
4040
public sealed class EpsonInfoImpressoraResolver : InfoResolver<InformacoesImpressora>
4141
{
4242
public EpsonInfoImpressoraResolver(Encoding encoding) :
43-
base(new[] { new[] { CmdConst.GS, (byte)'I', (byte)'B' }, new[] { CmdConst.GS, (byte)'I', (byte)'C' }, new[] { CmdConst.GS, (byte)'I', (byte)'A' }, new[] { CmdConst.GS, (byte)'I', (byte)'2' } },
43+
base(new[] { new byte[] { CmdConst.GS, 73, 66 }, new byte[] { CmdConst.GS, 73, 67 }, new byte[] { CmdConst.GS, 73, 65 }, new byte[] { CmdConst.GS, 73, 68 }, new byte[] { CmdConst.GS, 73, 50 } },
4444
(dados) =>
4545
{
4646
if (dados.IsNullOrEmpty()) return InformacoesImpressora.Empty;
4747
if (dados.Length < 4) return InformacoesImpressora.Empty;
4848

4949
var bitTest = new Func<int, byte, bool>((value, index) => ((value >> index) & 1) == 1);
5050

51-
var fabricante = dados[0].IsNullOrEmpty() ? "" : encoding.GetString(dados[0]);
52-
var modelo = dados[1].IsNullOrEmpty() ? "" : encoding.GetString(dados[1]);
53-
var firmware = dados[2].IsNullOrEmpty() ? "" : encoding.GetString(dados[2]);
54-
var guilhotina = !dados[3].IsNullOrEmpty() && bitTest(dados[3][0], 1);
51+
var fabricante = dados[0].IsNullOrEmpty() ? "" : encoding.GetString(dados[0]).Trim().TrimStart('_').Replace("\0", string.Empty);
52+
var modelo = dados[1].IsNullOrEmpty() ? "" : encoding.GetString(dados[1]).Trim().TrimStart('_').Replace("\0", string.Empty);
53+
var firmware = dados[2].IsNullOrEmpty() ? "" : encoding.GetString(dados[2]).Trim().TrimStart('_').Replace("\0", string.Empty);
54+
var serial = dados[3].IsNullOrEmpty() ? "" : encoding.GetString(dados[3]).Trim().TrimStart('_').Replace("\0", string.Empty);
55+
var guilhotina = !dados[4].IsNullOrEmpty() && bitTest(dados[4][0], 1);
5556

56-
return new InformacoesImpressora(fabricante, modelo, firmware, guilhotina);
57+
return new InformacoesImpressora(fabricante, modelo, firmware, serial, guilhotina);
5758
})
5859
{ }
5960
}

src/OpenAC.Net.EscPos/Interpreter/GPrinter/GPrinterInterpreter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class GPrinterInterpreter : EscPosInterpreter
4747

4848
internal GPrinterInterpreter(Encoding enconder) : base(enconder)
4949
{
50-
Status = new EpsonStatusResolver();
5150
}
5251

5352
#endregion Constructors
@@ -57,6 +56,9 @@ internal GPrinterInterpreter(Encoding enconder) : base(enconder)
5756
/// <inheritdoc />
5857
protected override void IniciarInterpreter()
5958
{
59+
Status = new EpsonStatusResolver();
60+
InfoImpressora = new EpsonInfoImpressoraResolver(Enconder);
61+
6062
var commandos = DefaultCommands.EscPos.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
6163
commandos[CmdEscPos.Beep] = new byte[] { CmdConst.ESC, (byte)'B', 1, 3 };
6264

src/OpenAC.Net.EscPos/Interpreter/PosStar/PosStarInterpreter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ internal PosStarInterpreter(Encoding enconder) : base(enconder)
5757
/// <inheritdoc />
5858
protected override void IniciarInterpreter()
5959
{
60+
Status = new EpsonStatusResolver();
61+
InfoImpressora = new EpsonInfoImpressoraResolver(Enconder);
62+
6063
var commandos = DefaultCommands.EscPos.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
6164
commandos[CmdEscPos.Beep] = new byte[] { CmdConst.ESC, CmdConst.GS, CmdConst.BELL, 1, 2, 5 };
6265

src/OpenAC.Net.EscPos/Interpreter/ZJiang/ZJiangInterpreter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class ZJiangInterpreter : EscPosInterpreter
4747

4848
internal ZJiangInterpreter(Encoding enconder) : base(enconder)
4949
{
50-
Status = new EpsonStatusResolver();
5150
}
5251

5352
#endregion Constructors
@@ -57,6 +56,9 @@ internal ZJiangInterpreter(Encoding enconder) : base(enconder)
5756
/// <inheritdoc />
5857
protected override void IniciarInterpreter()
5958
{
59+
Status = new EpsonStatusResolver();
60+
InfoImpressora = new EpsonInfoImpressoraResolver(Enconder);
61+
6062
var commandos = DefaultCommands.EscPos.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
6163
commandos[CmdEscPos.CorteTotal] = new byte[] { CmdConst.GS, (byte)'V', 1 };
6264
commandos[CmdEscPos.Beep] = new byte[] { CmdConst.ESC, (byte)'B', 1, 3 };

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReadmeFile>README.md</PackageReadmeFile>
2323
<AssemblyVersion>1.0.0.0</AssemblyVersion>
2424
<FileVersion>1.0.0.0</FileVersion>
25-
<Version>1.0.0.0-beta.7</Version>
25+
<Version>1.0.0.0-beta.8</Version>
2626
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2727
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2828
<DebugType>embedded</DebugType>
@@ -40,30 +40,6 @@
4040
<DefineConstants>NET45;NETFULL</DefineConstants>
4141
</PropertyGroup>
4242

43-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net452|AnyCPU'">
44-
<OutputPath>..\..\bin\Debug\</OutputPath>
45-
<DocumentationFile>..\..\bin\Debug\net452\OpenAC.Net.EscPos.xml</DocumentationFile>
46-
<LangVersion>9</LangVersion>
47-
</PropertyGroup>
48-
49-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net452|AnyCPU'">
50-
<OutputPath>..\..\bin\Release\</OutputPath>
51-
<DocumentationFile>..\..\bin\Release\net452\OpenAC.Net.EscPos.xml</DocumentationFile>
52-
<LangVersion>9</LangVersion>
53-
</PropertyGroup>
54-
55-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
56-
<OutputPath>..\..\bin\Debug\</OutputPath>
57-
<DocumentationFile>..\..\bin\Debug\netstandard2.0\OpenAC.Net.EscPos.xml</DocumentationFile>
58-
<LangVersion>9</LangVersion>
59-
</PropertyGroup>
60-
61-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
62-
<OutputPath>..\..\bin\Release\</OutputPath>
63-
<DocumentationFile>..\..\bin\Release\netstandard2.0\OpenAC.Net.EscPos.xml</DocumentationFile>
64-
<LangVersion>9</LangVersion>
65-
</PropertyGroup>
66-
6743
<ItemGroup>
6844
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
6945
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
@@ -75,7 +51,7 @@
7551
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7652
</PackageReference>
7753
<PackageReference Include="OpenAC.Net.Core" Version="1.5.0-preview.2" />
78-
<PackageReference Include="OpenAC.Net.Devices" Version="1.5.0-preview.3" />
54+
<PackageReference Include="OpenAC.Net.Devices" Version="1.5.0-preview.4" />
7955
</ItemGroup>
8056

8157
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">

0 commit comments

Comments
 (0)