-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
321 lines (276 loc) · 8.8 KB
/
server.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
'use strict';
var edge = require('edge-js');
var express = require('express');
var bodyParser = require('body-parser');
const util = require('util');
var app = express();
var about;
var openport;
var sendcommand;
var clearbuffer;
var printerfont;
var barcode;
var printlabel;
var closeport;
var sendcommand_utf8;
var sendcommand_binary;
var windowsfont;
var nobackfeed;
var urlencodedParser = bodyParser.urlencoded({extended: false});
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static('./'));
app.listen(8888, function () {
console.log("Server Start!!");
})
app.get('/test_get', function (req, res) {
console.log('GET Function Test!!');
});
app.post('/', urlencodedParser, function (req, res) {
printfile();
res.redirect(req.get('referer'));
});
app.post('/128B', urlencodedParser, function (req, res) {
printfile128B();
res.redirect(req.get('referer'));
});
app.post('/128C', urlencodedParser, function (req, res) {
printfile128C();
res.redirect(req.get('referer'));
});
try {
openport = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'openport'
});
} catch (error) {
console.log(error);
}
try {
about = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'about'
});
} catch (error) {
console.log(error);
}
try {
sendcommand = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'sendcommand'
});
} catch (error) {
console.log(error);
}
try {
clearbuffer = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'clearbuffer'
});
} catch (error) {
console.log(error);
}
try {
printerfont = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'printerfont'
});
} catch (error) {
console.log(error);
}
try {
barcode = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'barcode'
});
} catch (error) {
console.log(error);
}
try {
printlabel = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'printlabel'
});
} catch (error) {
console.log(error);
}
try {
closeport = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'closeport'
});
} catch (error) {
console.log(error);
}
try {
nobackfeed = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'nobackfeed'
});
} catch (error) {
console.log(error);
}
try {
sendcommand_utf8 = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'sendcommand_utf8'
});
} catch (error) {
console.log(error);
}
try {
sendcommand_binary = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'sendcommand_binary'
});
} catch (error) {
console.log(error);
}
try {
windowsfont = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'windowsfont'
});
} catch (error) {
console.log(error);
}
//string to utf8
function strToUtf8Bytes(text) {
const code = encodeURIComponent(text)
const bytes = []
for (let i = 0;i < code.length;i++) {
const c = code.charAt(i)
if (c === '%') {
const hex = code.charAt(i + 1) + code.charAt(i + 2)
const hexval = parseInt(hex, 16)
bytes.push(hexval)
i += 2
} else {
bytes.push(c.charCodeAt(0))
}
}
return bytes
}
function printfile() {
// let bytes = strToUtf8Bytes('达摩克利斯之剑');
// console.log("%c printfile🚀", "color: red;font-size: 18px", bytes);
var windowsfont_variable = {
x: 20,
y: 0,
fontheight: 63,
rotation: 0,
fontstyle: 5,
fontunderline: 0,
szFaceName: 'Microsoft YaHei',
content: '此条指令用来清除打印机中的图像缓存'
// content: bytes
}
var windowsfont_unicode = {
x: 20,
y: 0,
fontheight: 63,
rotation: 0,
fontstyle: 5,
fontunderline: 0,
szFaceName: 'Microsoft YaHei',
content: '此条指令用来清除打印机中的图像缓存'
// content: bytes
}
// 测试一代码
/*for (let i = 0; i < 2; i++) {
openport('TSC TE244', true);
sendcommand(`SIZE 4.00 3.00`, true);
// sendcommand(`SIZE 2.33 1.56`, true);
sendcommand(`DIRECTION 1`, true); // 待确定
// sendcommand(`CLS`, true); // 此条指令用来清除打印机中的图像缓存
clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
sendcommand(`BARCODE 5,10,"128",50,1,0,2,2,"23030700011${i+1}"`, true);
sendcommand('PRINT 1,1', true);
// sendcommand('CLS', true); // test code 此条指令用来清除打印机中的图像缓存
// sendcommand('EOJ', true) // test code
closeport('', true);*/
// 1. printlabel/PRINT 1,1
// 2. size 精确度问题
// 3. CLS, clearbuffer问题
// 测试二代码, size 问题导致
for (let i = 0; i < 1; i++) {
openport('TSC TE244', true);
clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
// sendcommand(`CLS`, true); // 此条指令用来清除打印机中的图像缓存
// sendcommand(`SIZE 4.00 3.00`, true);
sendcommand(`DIRECTION 1`, true); // 待确定
// sendcommand(`BARCODE 5,10,"128",50,1,0,2,2,"23030700011${i+1}"`, true);
windowsfont_variable.y = 0
let height = 0
for (let j = 0; j < 5; j++) {
// windowsfont_variable.y = windowsfont_variable.y + 2
// windowsfont(`20,${windowsfont_variable.y},63,0,5,"Arial","达摩克利斯之剑"`, true);
// windowsfont(windowsfont_variable, true)
// sendcommand(`TEXT 100,${windowsfont_variable.y},"SimSun",0,18,18,"达摩克利斯之剑"`, true);
// height = height + 2
// sendcommand(`BARCODE 5,${height},"128",50,1,0,3,3,"AUDAUFADADCRQERHADADSF${i+1}"`, true);
}
sendcommand('PRINT 1,1', true); // printlabel(label_variable, true); 问题
// sendcommand('CLS', true); // test code 此条指令用来清除打印机中的图像缓存
// sendcommand('EOJ', true) // test code
// clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
closeport('', true);
}
}
function printfile128B() {
var label_variable = {quantity: '1', copy: '1'};
openport('TSC TE244', true);
clearbuffer('', true);
// sendcommand('CODEPAGE UTF-8', true);
// sendcommand('TEXT 0,50,"YZ",0,1,1,"中文测试"', true); // 可行
// sendcommand('TEXT 0,20,"arial12",0,2,2,"中文测试01AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 0,80,"arial14",0,2,2,"中文测试01AAABBB-TEST"', true); // 可行r
sendcommand('DMATRIX 10,110,400,400,"DMATRIX EXAMPLE 1"', true); // 可行
// sendcommand('TEXT 200,100,"zhongwen",0,2,2,"中文测试01234AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 200,120,"song22",0,1,1,"中文测试123AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 200,180,"song22",0,3,3,"中文测试123AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 0,100,"0",0,16,16,"hello world!"', true);
printlabel(label_variable, true);
// nobackfeed()
closeport('', true);
}
function printfile128C() {
// var windowsfont_variable = {
// x: 20,
// y: 100,
// fontheight: 64,
// rotation: 0,
// fontstyle: 3,
// fontunderline: 0,
// szFaceName: 'Arial',
// content: '达摩克利斯之剑'
// }
var font_variable = { x: '50', y: '50', fonttype: '0', rotation: '0', xmul: '1', ymul: '1', text: 'Font Test' }
var label_variable = {quantity: '1', copy: '1'};
openport('TSC TE244', true);
clearbuffer('', true);
printerfont(font_variable, true);
// windowsfont(0, 50, 64, 0, 0, 0, "Arial", "Windows Arial Font Test")
// windowsfont(windowsfont_variable);
// sendcommand(`SIZE 1.07, 1.07`, true);
// sendcommand(`SIZE 2.33, 1.54`, true);
// sendcommand(`BOX 0, 0, 480, 320, 10`, true);
// sendcommand(`BOX 0, 0, 480, 320, 20`, true);
// sendcommand(`TEXT 80,80,"0",0,12,12,""`, true);
// sendcommand(`TEXT 80,450,"0",0,12,12,"test edit"`, true);
printlabel(label_variable, true);
closeport('', true);
}