-
Notifications
You must be signed in to change notification settings - Fork 2
/
ils-default.ts
84 lines (76 loc) · 2.11 KB
/
ils-default.ts
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
// tslint:disable-next-line: no-relative-imports
import { SSP } from "../src";
// tslint:disable: no-console
const start = async () => {
const notes: {
[key: number]: string;
} = {
1: "20ILS",
2: "50ILS",
3: "100ILS",
4: "200ILS",
} as const;
const ssp = new SSP("nv10usb", {
device: "/dev/ttyUSB0", // device address, use 'npx @serialport/list' to get a list
currencies: [1, 1, 1, 1], // currencies types acceptable
});
console.log("before open");
await ssp.open();
console.log("opened");
await ssp.enable();
console.log("enabled");
ssp.on("read_note", async (note: number) => {
if (note > 0) {
console.log("Ohhh, some cash!", notes[note]);
/**
* Change it to true to test banknote rejection
*/
const isReject50 = false;
if (isReject50 && note === 2) {
// suddenly we decided that we don't need 50 ILS
await ssp.exec("reject_banknote");
}
}
});
ssp.on("disable", () => {
console.log("disabled");
});
ssp.on("note_cleared_from_front", (note: number) => {
console.log("note_cleared_from_front", notes[note]);
});
ssp.on("note_cleared_to_cashbox", (note: number) => {
console.log("note_cleared_to_cashbox", notes[note]);
});
ssp.on("credit_note", (note: number) => {
console.log("CREDIT", notes[note]);
});
ssp.on("safe_note_jam", (note: number) => {
console.log("Jammed", notes[note]);
});
ssp.on("unsafe_note_jam", (note: number) => {
console.log("Jammed inside", notes[note]);
});
ssp.on("fraud_attempt", (note: number) => {
console.log("Fraud!", notes[note]);
});
ssp.on("stacker_full", (note: number) => {
console.log("I'm full, do something!", notes[note]);
});
ssp.on("note_rejected", (reason: number) => {
console.log("Rejected!", reason);
});
ssp.on("error", (err: Error) => {
console.error(err.message);
});
process.on("SIGINT", () => {
process.exit(0);
});
process.on("exit", () => {
void ssp.disable();
});
process.on("uncaughtException", (err: Error) => {
console.error(err);
process.exit(1);
});
};
void start();