-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.js
86 lines (75 loc) · 2.03 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const SSP = require('./lib/index.js')
const channels = [{ value: 0, country_code: 'XXX' }]
const serialPortConfig = {
baudRate: 9600, // default: 9600
dataBits: 8, // default: 8
stopBits: 2, // default: 2
parity: 'none', // default: 'none'
}
const eSSP = new SSP({
id: 0x00,
timeout: 1000, // default: 3000
encryptAllCommand: true, // default: true
fixedKey: '0123456701234567', // default: '0123456701234567'
})
// eSSP.on('DATA_RECEIVED', data => {
// console.log(data)
// })
// eSSP.on('DEBUG', data => {
// console.log(data)
// })
eSSP.on('OPEN', () => {
console.log('Port opened!')
})
eSSP.on('CLOSE', () => {
console.log('Port closed!')
})
eSSP.on('READ_NOTE', result => {
console.log('READ_NOTE', result)
console.log(channels[result.channel])
if (channels[result.channel].value === 500) {
eSSP.command('REJECT_BANKNOTE')
}
})
eSSP.on('NOTE_REJECTED', result => {
console.log('NOTE_REJECTED', result)
eSSP.command('LAST_REJECT_CODE').then(result => {
console.log(result)
})
})
eSSP
.open('COM3', serialPortConfig)
.then(() => eSSP.command('SYNC'))
.then(() => eSSP.command('HOST_PROTOCOL_VERSION', { version: 6 }))
.then(() => eSSP.initEncryption())
.then(() => eSSP.command('GET_SERIAL_NUMBER'))
.then(result => {
console.log(eSSP.keys.encryptKey)
console.log('SERIAL NUMBER:', result.info.serial_number)
return
})
.then(() => eSSP.command('UNIT_DATA'))
.then(() => eSSP.command('SETUP_REQUEST'))
.then(result => {
for (let i = 0; i < result.info.channel_value.length; i++) {
channels[i + 1] = {
value: result.info.expanded_channel_value[i],
country_code: result.info.expanded_channel_country_code[i],
}
}
console.log('channels', channels)
return
})
.then(() =>
eSSP.command('SET_CHANNEL_INHIBITS', {
channels: Array(channels.length).fill(1),
}),
)
// .then(() => eSSP.command('ENABLE'))
.then(() => eSSP.enable())
.then(() => {
console.log('GO!!!')
})
.catch(error => {
console.log(error)
})