1+ /**
2+ * bv-full.js
3+ *
4+ * @author Desionlab <fenixphp@gmail.com>
5+ * @copyright 2017 - 2018 Desionlab
6+ * @license MIT
7+ *
8+ * Library for working with "CashCode" Bill Validator devices from Node.js app.
9+ */
10+
11+ /* */
12+ const { CCNet } = require ( './../../Source' ) ;
13+
14+ /* */
15+ let device = new CCNet . BillValidator ( 'COM6' ) ;
16+
17+ /* */
18+ let counter = 0 ;
19+
20+ /* */
21+ async function init ( ) {
22+ /* */
23+ device . on ( 'status' , function ( status ) {
24+ //console.log('on:status', status);
25+ } ) ;
26+
27+ /* ----------------------------------------------------------------------- */
28+
29+ /* */
30+ device . on ( 'power-up' , function ( ) {
31+ console . log ( 'on:power-up' ) ;
32+ } ) ;
33+
34+ /* */
35+ device . on ( 'power-up-with-bill' , function ( ) {
36+ console . log ( 'on:power-up-with-bill' ) ;
37+ } ) ;
38+
39+ /* */
40+ device . on ( 'power-up-with-bill-in-stacker' , function ( ) {
41+ console . log ( 'on:power-up-with-bill-in-stacker' ) ;
42+ } ) ;
43+
44+ /* ----------------------------------------------------------------------- */
45+
46+ /* */
47+ device . on ( 'initialize' , function ( ) {
48+ console . log ( 'on:initialize' ) ;
49+ } ) ;
50+
51+ /* */
52+ device . on ( 'disabled' , function ( ) {
53+ console . log ( 'on:disabled' ) ;
54+ } ) ;
55+
56+ /* */
57+ device . on ( 'holding' , function ( ) {
58+ console . log ( 'on:holding' ) ;
59+ } ) ;
60+
61+ /* ----------------------------------------------------------------------- */
62+
63+ /* */
64+ device . on ( 'cassette-full' , function ( ) {
65+ console . log ( 'on:cassette-full' ) ;
66+ } ) ;
67+
68+ /* */
69+ device . on ( 'cassette-out-of-position' , function ( ) {
70+ console . log ( 'on:cassette-out-of-position' ) ;
71+ } ) ;
72+
73+ /* ----------------------------------------------------------------------- */
74+
75+ /* */
76+ device . on ( 'jammed' , function ( ) {
77+ console . log ( 'on:jammed' ) ;
78+ } ) ;
79+
80+ /* */
81+ device . on ( 'cassette-jammed' , function ( ) {
82+ console . log ( 'on:cassette-jammed' ) ;
83+ } ) ;
84+
85+ /* */
86+ device . on ( 'cheated' , function ( ) {
87+ console . log ( 'on:cheated' ) ;
88+ } ) ;
89+
90+ /* */
91+ device . on ( 'pause' , function ( ) {
92+ console . log ( 'on:pause' ) ;
93+ } ) ;
94+
95+ /* ----------------------------------------------------------------------- */
96+
97+ /* */
98+ device . on ( 'idling' , async function ( ) {
99+ /* */
100+ console . log ( 'on:idling' ) ;
101+
102+ /* */
103+ if ( counter >= 2 ) {
104+ await device . end ( ) ;
105+
106+ setTimeout ( async function ( ) {
107+ counter = 0 ;
108+ await device . begin ( ) ;
109+ } , ( 60 * 1000 ) * 5 ) ;
110+ }
111+ } ) ;
112+
113+ /* */
114+ device . on ( 'accepting' , function ( ) {
115+ console . log ( 'on:accepting' ) ;
116+ } ) ;
117+
118+ /* */
119+ device . on ( 'escrow' , async function ( bill ) {
120+ /* */
121+ console . log ( 'on:escrow:' , bill ) ;
122+
123+ if ( bill . amount == 50 ) {
124+ /* */
125+ await device . retrieve ( ) ;
126+ } else {
127+ /* */
128+ await device . stack ( ) ;
129+
130+ /* */
131+ counter ++ ;
132+ }
133+ } ) ;
134+
135+ /* */
136+ device . on ( 'stacking' , function ( ) {
137+ console . log ( 'on:stacking' ) ;
138+ } ) ;
139+
140+ /* */
141+ device . on ( 'stacked' , function ( bill ) {
142+ console . log ( 'on:stacked:' , bill ) ;
143+ } ) ;
144+
145+ /* */
146+ device . on ( 'returning' , function ( ) {
147+ console . log ( 'on:returning' ) ;
148+ } ) ;
149+
150+ /* */
151+ device . on ( 'returned' , function ( bill ) {
152+ console . log ( 'on:returned:' , bill ) ;
153+ } ) ;
154+
155+ /* ----------------------------------------------------------------------- */
156+
157+ /* */
158+ await device . connect ( ) ;
159+
160+ /* ----------------------------------------------------------------------- */
161+
162+ console . log ( device . info ) ;
163+ console . log ( device . billTable ) ;
164+
165+ /* ----------------------------------------------------------------------- */
166+
167+ /* */
168+ //await device.begin();
169+
170+ /* */
171+ //await device.close();
172+ }
173+
174+ init ( )
175+ . then ( function ( ) {
176+ console . log ( 'Ok.' ) ;
177+ } )
178+ . catch ( function ( error ) {
179+ console . error ( error ) ;
180+ } ) ;
181+
182+ /* End of file bv-full.js */
0 commit comments