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="BemaInfoImpressoraResolver.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+ using System ;
33+ using System . Text ;
34+ using OpenAC . Net . Core . Extensions ;
35+ using OpenAC . Net . EscPos . Commom ;
36+ using OpenAC . Net . EscPos . Interpreter . Resolver ;
37+
38+ namespace OpenAC . Net . EscPos . Interpreter . Bematech ;
39+
40+ public sealed class BemaInfoImpressoraResolver : InfoResolver < InformacoesImpressora >
41+ {
42+ public BemaInfoImpressoraResolver ( Encoding encoding ) :
43+ base ( new [ ] { new byte [ ] { CmdConst . GS , 249 , 39 , 0 } , new byte [ ] { CmdConst . GS , 249 , 39 , 3 } , new byte [ ] { CmdConst . GS , 249 , 1 } , new byte [ ] { CmdConst . GS , 249 , 39 , 49 } } ,
44+ ( dados ) =>
45+ {
46+ if ( dados . IsNullOrEmpty ( ) ) return InformacoesImpressora . Empty ;
47+ if ( dados . Length < 4 ) return InformacoesImpressora . Empty ;
48+
49+ var bitTest = new Func < int , byte , bool > ( ( value , index ) => ( ( value >> index ) & 1 ) == 1 ) ;
50+
51+ var fabricante = string . Empty ;
52+ var modelo = dados [ 0 ] . IsNullOrEmpty ( ) ? "" : encoding . GetString ( dados [ 0 ] ) . Trim ( ) . TrimStart ( '_' ) . Replace ( "\0 " , string . Empty ) ;
53+ var firmware = dados [ 1 ] . IsNullOrEmpty ( ) ? "" : encoding . GetString ( dados [ 1 ] ) . Trim ( ) . TrimStart ( '_' ) . Replace ( "\0 " , string . Empty ) ;
54+ var serial = dados [ 2 ] . IsNullOrEmpty ( ) ? "" : encoding . GetString ( dados [ 2 ] ) . Trim ( ) . TrimStart ( '_' ) . Replace ( "\0 " , string . Empty ) ;
55+ var guilhotina = ! dados [ 3 ] . IsNullOrEmpty ( ) && dados [ 3 ] . Length >= 3 && bitTest ( dados [ 3 ] [ 2 ] , 2 ) ;
56+
57+ return new InformacoesImpressora ( fabricante , modelo , firmware , serial , guilhotina ) ;
58+ } )
59+ { }
60+ }
0 commit comments