paxlib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js ADDED
@@ -0,0 +1,37 @@
1
+ const TCPSocket = require("./tcp-socket");
2
+ const PAXCommands = require('./paxcommands');
3
+ const { clear } = require("console");
4
+
5
+ const client = new TCPSocket('192.168.1.74', 10009, 60000);
6
+ client.connect();
7
+
8
+ const InitCmd = PAXCommands.PAXDoCredit();
9
+ //const InitCmd = PAXCommands.PAXInitialize();
10
+
11
+ client.send(InitCmd);
12
+ console.log(`Data sent: ${InitCmd}`);
13
+
14
+ client.receive((data) => {
15
+ if (data.toString().length == 1 && data.toString().charCodeAt(0) == 6)
16
+ {
17
+ console.log(`HBT Received: ${data.toString().charCodeAt(0)}`);
18
+ }
19
+ else
20
+ {
21
+ if (data.toString().length == 1)
22
+ console.log(`Received: ${data.toString().charCodeAt(0)}`);
23
+ else
24
+ console.log(`Received: ${data}`);
25
+ if (data.indexOf(String.fromCharCode(3)) !== -1 || data.indexOf(String.fromCharCode(4)) !== -1)
26
+ client.close();
27
+ }
28
+ });
29
+
30
+ client.onTimeout(() => {
31
+ console.log('Timeout reached');
32
+ });
33
+
34
+ client.error((error) => {
35
+ console.error(`${error}`);
36
+ });
37
+
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "paxlib",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC"
11
+ }
package/pax.js ADDED
@@ -0,0 +1,482 @@
1
+ define(['jquery','jqueryBase64'],function($){
2
+
3
+ //HEX TO BASE64 =============================================================================================================================
4
+ function hexToBase64(str) {
5
+ return $.base64.btoa(String.fromCharCode.apply(null,
6
+ str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))
7
+ );
8
+ }
9
+
10
+ //BASE64 TO HEX =============================================================================================================================
11
+ function base64ToHex(str) {
12
+ for (var i = 0, bin = $.base64.atob(str), hex = []; i < bin.length; ++i) {
13
+ var tmp = bin.charCodeAt(i).toString(16);
14
+ if (tmp.length === 1) tmp = "0" + tmp;
15
+ hex[hex.length] = tmp;
16
+ }
17
+ return hex.join(" ");
18
+ }
19
+
20
+ // =============================================================================================================================
21
+ function StringToHex(response){
22
+ var responseHex = "";
23
+ for(var i=0; i<response.length; i++){
24
+ if(responseHex == "")
25
+ responseHex = response.charCodeAt(i).toString(16).length<2?'0'+response.charCodeAt(i).toString(16):response.charCodeAt(i).toString(16);
26
+ else
27
+ responseHex += response.charCodeAt(i).toString(16).length<2?" " + '0'+response.charCodeAt(i).toString(16):" " + response.charCodeAt(i).toString(16);
28
+ }
29
+ return responseHex;
30
+
31
+ }
32
+
33
+ //=============================================================================================================================
34
+
35
+ function HexToString(response){
36
+ var responseHex = "";
37
+ var arr = response.split(" ");
38
+ for(var i=0; i<arr.length; i++){
39
+ if(arr[i] == "")
40
+ continue;
41
+ responseHex += String.fromCharCode(parseInt(arr[i],16));
42
+ }
43
+ return responseHex;
44
+ }
45
+
46
+ var PAX = {
47
+ //IP of the POS
48
+ mDestinationIP : "http://127.0.0.1:10009", // - OLD "http://192.167.2.100:10009"; //http://112.199.49.146:8181
49
+
50
+ mStx : {
51
+ hex: 0x02,
52
+ code: "02"
53
+ },
54
+
55
+ mFS : {
56
+ hex : 0x1c,
57
+ code : "1c"
58
+ },
59
+
60
+ mEtx : {
61
+ hex : 0x03,
62
+ code : "03"
63
+ },
64
+
65
+ mUS : {
66
+ hex : 0x1F,
67
+ code : "1F"
68
+ },
69
+
70
+ //var _this : this;
71
+ customData : '',
72
+
73
+ timeout : {
74
+ "Initialize":120*1000,
75
+ "GetSignature":120*1000,
76
+ "DoSignature":120*1000,
77
+ "DoCredit":120*1000
78
+ },
79
+
80
+ //Set ip and port
81
+ Settings : function(ip,port){
82
+ this.mDestinationIP = "http://" + ip + ":" + port;
83
+ console.log("New service address: "+this.mDestinationIP);
84
+ },
85
+
86
+ AjaxTimeOut : function(command,timeout){
87
+ this.timeout[command]= timeout;
88
+ },
89
+
90
+ SetCustomData : function(custom_data){
91
+ this.customData = custom_data;
92
+ console.log(custom_data);
93
+ },
94
+
95
+ //Get LRC
96
+ getLRC : function(params){
97
+ var lrc = 0;
98
+ for(i=1; i< params.length; i++){
99
+ var type_of = typeof(params[i]);
100
+ if(type_of == "string"){
101
+ var element = params[i].split("");
102
+ for(ii=0; ii<element.length; ii++){
103
+ lrc ^= element[ii].charCodeAt(0);
104
+ }
105
+ }else{
106
+ lrc ^= params[i];
107
+ }
108
+ }
109
+ return (lrc>0)?String.fromCharCode(lrc):0;
110
+ },
111
+
112
+
113
+ //Connect to the server ================================================================================================
114
+
115
+ HttpCommunication : function(commandType,url,callback,timeout){
116
+ var xhr = null;
117
+ if(window.XMLHttpRequest) {
118
+ xhr = new XMLHttpRequest();
119
+ } else {
120
+ try{
121
+ xhr = new ActiveXObject('Microsoft.XMLHttp');
122
+ }catch(e){
123
+ xhr = new ActiveXObject('msxml2.xmlhttp');
124
+ }
125
+ }
126
+ //get请求
127
+
128
+ xhr.open("GET", url,true);
129
+ xhr.onreadystatechange=function(){
130
+ if(xhr.readyState==4) {
131
+ //alert(xhr.status);
132
+ if(xhr.status==200) {
133
+ var response = xhr.responseText;
134
+ console.log("Raw response: "+response);
135
+
136
+ var checkParams = StringToHex(response).split(" ").pop();
137
+ var RedundancyCheck = StringToHex(response).split(" ").pop().substring(1);
138
+
139
+ var check = PAX.getLRC(checkParams);
140
+
141
+ if(check == RedundancyCheck){
142
+ //get package detail info
143
+ var packetInfo = [];
144
+ var len = StringToHex(response).indexOf("03");
145
+ var hex = StringToHex(response).slice(0,len).split(/02|1c/);
146
+
147
+ console.log(hex);
148
+ if(commandType == "DoCredit"){
149
+ var subHex=[], subPacketInfo=[];
150
+ for(var i=0; i<hex.length; i++){
151
+ if(hex[i] != ""){
152
+ if(hex[i].indexOf("1f")>0){
153
+ subHex = hex[i].split("1f");
154
+ console.log(subHex);
155
+ subPacketInfo = [];
156
+ for(var j=0; j<subHex.length; j++){
157
+ if(subHex[j]!=''){
158
+ subPacketInfo.push(HexToString(subHex[j]));
159
+ }
160
+ }
161
+ console.log(subPacketInfo);
162
+ packetInfo.push(subPacketInfo);
163
+ }else{
164
+ packetInfo[i] = HexToString(hex[i]);
165
+ }
166
+ }
167
+ }
168
+
169
+ }else{
170
+ for(var i=0; i<hex.length; i++){
171
+ if(hex[i] != ""){
172
+ packetInfo[i] = HexToString(hex[i]);
173
+ }
174
+ }
175
+ }
176
+
177
+ console.log("Separate package info: ");
178
+ console.log(packetInfo);
179
+ callback(packetInfo);
180
+ }
181
+ } else {
182
+ if(fail) {
183
+ fail(xhr.status);
184
+ }
185
+ }
186
+ }
187
+ };
188
+ xhr.send(null);
189
+ },
190
+
191
+ //=============================================================================================================================
192
+
193
+ Initialize : function(initialInfo,callback){
194
+ var params = [this.mStx.hex,initialInfo.command,this.mFS.hex, initialInfo.version, this.mEtx.hex];
195
+ //[02]A08[1c]1.28[1c]0[1c]90000[03]
196
+ //var params = [0x02,"A08",0x1c,"1.28",0x1c, "0", 0x1c,"90000",0x03];
197
+ var lrc = this.getLRC(params);
198
+ var command_hex = base64ToHex($.base64.btoa(initialInfo.command));
199
+ var version_hex = base64ToHex($.base64.btoa(initialInfo.version));
200
+ //var elements = [this.mStx, command_hex, this.mFS, version_hex, this.mEtx, base64ToHex($.base64.btoa(lrc))];
201
+ var elements = [this.mStx.code, command_hex, this.mFS.code, version_hex, this.mEtx.code, base64ToHex($.base64.btoa(lrc))];
202
+
203
+ var final_string = elements.join(" ");
204
+ //console.log("final_string: " + final_string);
205
+
206
+ var final_b64 = hexToBase64(final_string);
207
+ console.log("LRC: " + lrc);
208
+ console.log("Base64: " + final_b64);
209
+ var url = this.mDestinationIP + '?' + final_b64;
210
+ console.log("URL: " + url);
211
+
212
+ this.HttpCommunication('Initialize',url,function(response){
213
+ callback(response);
214
+ },PAX.timeout.Initialize);
215
+
216
+ },
217
+
218
+ //=============================================================================================================================
219
+ //GET SIGNATURE
220
+ GetSignature : function(getSignatureInfo,callback){
221
+
222
+ var params = [this.mStx.hex,getSignatureInfo.command,this.mFS.hex,getSignatureInfo.version,this.mFS.hex, getSignatureInfo.offset, this.mFS.hex,getSignatureInfo.requestlength,this.mEtx.hex];
223
+ var lrc = this.getLRC(params);
224
+
225
+ //prepare for base64 encoding.
226
+ var command_hex = base64ToHex($.base64.btoa(getSignatureInfo.command));
227
+ var version_hex = base64ToHex($.base64.btoa(getSignatureInfo.version));
228
+ var offset_hex = base64ToHex($.base64.btoa(getSignatureInfo.offset));
229
+ var requestlength_hex = base64ToHex($.base64.btoa(getSignatureInfo.requestlength));
230
+ //var elements = [this.mStx.code, command_hex, this.mFS.code, version_hex, this.mFS.code, offset_hex, this.mFS.code, requestlength_hex, this.mEtx.code, base64ToHex($.base64.btoa(lrc))];
231
+ var elements = [this.mStx.code];
232
+ elements.push(command_hex);
233
+ elements.push(this.mFS.code);
234
+ elements.push(version_hex);
235
+ elements.push(this.mFS.code);
236
+ if(offset_hex != ''){
237
+ elements.push(offset_hex);
238
+ }
239
+ elements.push(this.mFS.code);
240
+ if(requestlength_hex != ''){
241
+ elements.push(requestlength_hex);
242
+ }
243
+ elements.push(this.mEtx.code);
244
+ elements.push(base64ToHex($.base64.btoa(lrc)));
245
+
246
+ var final_string = elements.join(" ");
247
+ var final_b64 = hexToBase64(final_string);
248
+ console.log("LRC: " + lrc);
249
+ console.log("Base64: " + final_b64);
250
+ var url = this.mDestinationIP + '?' + final_b64;
251
+ console.log("URL: " + url);
252
+
253
+ this.HttpCommunication('GetSignature',url,function(response){
254
+ callback(response);
255
+ },PAX.timeout.GetSignature);
256
+
257
+ },
258
+
259
+ //=============================================================================================================================
260
+ //DO SIGNATURE
261
+ DoSignature : function(doSignatureInfo,callback){
262
+ var params = [this.mStx.hex,doSignatureInfo.command, this.mFS.hex, doSignatureInfo.version, this.mFS.hex, doSignatureInfo.uploadFlag, this.mFS.hex,doSignatureInfo.hostReferenceNumber, this.mFS.hex, doSignatureInfo.edcType, this.mFS.hex, doSignatureInfo.timeout, this.mEtx.hex];
263
+ var lrc = this.getLRC(params);
264
+
265
+ //prepare for base64 encoding.
266
+ var command_hex = base64ToHex($.base64.btoa(doSignatureInfo.command));
267
+ var version_hex = base64ToHex($.base64.btoa(doSignatureInfo.version));
268
+ var uploadFlag_hex = base64ToHex($.base64.btoa(doSignatureInfo.uploadFlag));
269
+ var hostReferenceNumber_hex = base64ToHex($.base64.btoa(doSignatureInfo.hostReferenceNumber));
270
+ var edcType_hex = base64ToHex($.base64.btoa(doSignatureInfo.edcType));
271
+ var timeout_hex = base64ToHex($.base64.btoa(doSignatureInfo.timeout));
272
+ var elements = [this.mStx.code];
273
+ elements.push(command_hex);
274
+ elements.push(this.mFS.code);
275
+ elements.push(version_hex);
276
+ elements.push(this.mFS.code);
277
+ if(uploadFlag_hex != ''){
278
+ elements.push(uploadFlag_hex);
279
+ }
280
+ elements.push(this.mFS.code);
281
+ if(hostReferenceNumber_hex != ''){
282
+ elements.push(hostReferenceNumber_hex);
283
+ }
284
+ elements.push(this.mFS.code);
285
+ if(edcType_hex != ''){
286
+ elements.push(edcType_hex);
287
+ }
288
+ elements.push(this.mFS.code);
289
+ if(timeout_hex != ''){
290
+ elements.push(timeout_hex);
291
+ }
292
+ elements.push(this.mEtx.code);
293
+ elements.push(base64ToHex($.base64.btoa(lrc)));
294
+
295
+ var final_string = elements.join(" ");
296
+ var final_b64 = hexToBase64(final_string);
297
+ console.log("LRC: " + lrc);
298
+ console.log("Base64: " + final_b64);
299
+ var url = this.mDestinationIP + '?' + final_b64;
300
+ console.log("URL: " + url);
301
+
302
+ this.HttpCommunication('DoSignature',url,function(response){
303
+ callback(response);
304
+ },PAX.timeout.DoSignature);
305
+
306
+ },
307
+
308
+
309
+ PushParams : function(params,type,objectInfo){
310
+ var empty = 0;
311
+ var arr = [];
312
+ arr = arr.concat(params);
313
+ for(name in objectInfo){
314
+ if(objectInfo[name] == '' && type!="additionalInformation")
315
+ {
316
+ arr.push(this.mUS.hex);
317
+ continue;
318
+ }
319
+
320
+ if(type == "additionalInformation"){
321
+ if(objectInfo[name] == ''){
322
+ continue;
323
+ }
324
+ empty++;
325
+ arr.push(name+"="+objectInfo[name].toString());
326
+ }else{
327
+ empty++;
328
+ arr.push(objectInfo[name].toString());
329
+ }
330
+ arr.push(this.mUS.hex);
331
+ }
332
+ arr.pop();
333
+ if(empty==0 && type!="additionalInformation"){
334
+ arr = params;
335
+ }
336
+ if(empty==0 && type=="additionalInformation"){
337
+ arr.push(this.mFS.hex);
338
+ }
339
+ //console.log(params);
340
+ return arr;
341
+ },
342
+ AddBase64 : function(elements,type,objectInfo){
343
+ //console.log(objectInfo);
344
+ var empty = 0;
345
+ var arr = [];
346
+ arr = arr.concat(elements);
347
+ for(name in objectInfo){
348
+ if(objectInfo[name] == '' && type!="additionalInformation")
349
+ {
350
+ arr.push(this.mUS.code);
351
+ continue;
352
+ }
353
+ if(type == "additionalInformation"){
354
+ if(objectInfo[name] == '')
355
+ continue;
356
+ empty++;
357
+ arr.push(base64ToHex($.base64.btoa(name+"="+objectInfo[name].toString())));
358
+ }else{
359
+ empty++;
360
+ arr.push(base64ToHex($.base64.btoa(objectInfo[name].toString())));
361
+ }
362
+ arr.push(this.mUS.code);
363
+ }
364
+ arr.pop();
365
+ if(empty==0 && type!="additionalInformation"){
366
+ arr = elements;
367
+ }
368
+ if(empty==0 && type=="additionalInformation"){
369
+ arr.push(this.mFS.code);
370
+ }
371
+ //console.log(arr);
372
+ return arr;
373
+ },
374
+
375
+ //=============================================================================================================================
376
+ //DO Credit
377
+ DoCredit : function(doCreditInfo,callback){
378
+ var amountInformation,accountInformation,traceInformation,avsInformation,cashierInformation,commercialInformation,motoEcommerce,additionalInformation;
379
+ var params = [this.mStx.hex,doCreditInfo.command, this.mFS.hex, doCreditInfo.version];
380
+ params.push(this.mFS.hex);
381
+ if(doCreditInfo.transactionType != ''){
382
+ params.push(doCreditInfo.transactionType);
383
+ }
384
+ params.push(this.mFS.hex);
385
+ params = this.PushParams(params,"amountInformation",doCreditInfo.amountInformation);
386
+
387
+ params.push(this.mFS.hex);
388
+ params = this.PushParams(params,"accountInformation",doCreditInfo.accountInformation);
389
+
390
+ params.push(this.mFS.hex);
391
+ params = this.PushParams(params,"traceInformation",doCreditInfo.traceInformation);
392
+
393
+ params.push(this.mFS.hex);
394
+ params = this.PushParams(params,"avsInformation",doCreditInfo.avsInformation);
395
+
396
+ params.push(this.mFS.hex);
397
+ params = this.PushParams(params,"cashierInformation",doCreditInfo.cashierInformation);
398
+
399
+ params.push(this.mFS.hex);
400
+ params = this.PushParams(params,"commercialInformation",doCreditInfo.commercialInformation);
401
+
402
+ params.push(this.mFS.hex);
403
+ params = this.PushParams(params,"motoEcommerce",doCreditInfo.motoEcommerce);
404
+
405
+ params.push(this.mFS.hex);
406
+ params = this.PushParams(params,"additionalInformation",doCreditInfo.additionalInformation);
407
+
408
+ params.push(this.mEtx.hex);
409
+
410
+ var lrc = this.getLRC(params);
411
+
412
+ console.log(params);
413
+
414
+ //prepare for base64 encoding.
415
+ var command_hex = base64ToHex($.base64.btoa(doCreditInfo.command));
416
+ var version_hex = base64ToHex($.base64.btoa(doCreditInfo.version));
417
+ var transactionType_hex = base64ToHex($.base64.btoa(doCreditInfo.transactionType));
418
+ var amountInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.amountInformation));
419
+ var accountInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.accountInformation));
420
+ var traceInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.traceInformation));
421
+ var avsInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.avsInformation));
422
+ var cashierInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.cashierInformation));
423
+ var commercialInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.commercialInformation));
424
+ var motoEcommerce_hex = base64ToHex($.base64.btoa(doCreditInfo.motoEcommerce));
425
+ var additionalInformation_hex = base64ToHex($.base64.btoa(doCreditInfo.additionalInformation));
426
+
427
+ //var elements = [this.mStx.code, command_hex, this.mFS.code, version_hex, this.mFS.code, uploadFlag_hex, this.mFS.code, timeout, this.mEtx.code, base64ToHex($.base64.btoa(lrc))];
428
+ var elements = [this.mStx.code];
429
+ elements.push(command_hex);
430
+ elements.push(this.mFS.code);
431
+ elements.push(version_hex);
432
+ elements.push(this.mFS.code);
433
+
434
+ if(transactionType_hex != ''){
435
+ elements.push(transactionType_hex);
436
+ }
437
+ elements.push(this.mFS.code);
438
+
439
+ elements = this.AddBase64(elements,"amountInformation",doCreditInfo.amountInformation);
440
+ elements.push(this.mFS.code);
441
+ elements = this.AddBase64(elements,"accountInformation",doCreditInfo.accountInformation);
442
+ elements.push(this.mFS.code);
443
+ elements = this.AddBase64(elements,"traceInformation",doCreditInfo.traceInformation);
444
+ elements.push(this.mFS.code);
445
+ elements = this.AddBase64(elements,"avsInformation",doCreditInfo.avsInformation);
446
+ elements.push(this.mFS.code);
447
+ elements = this.AddBase64(elements,"cashierInformation",doCreditInfo.cashierInformation);
448
+ elements.push(this.mFS.code);
449
+ elements = this.AddBase64(elements,"commercialInformation",doCreditInfo.commercialInformation);
450
+ elements.push(this.mFS.code);
451
+ elements = this.AddBase64(elements,"motoEcommerce",doCreditInfo.motoEcommerce);
452
+ elements.push(this.mFS.code);
453
+ elements = this.AddBase64(elements,"additionalInformation",doCreditInfo.additionalInformation);
454
+
455
+ elements.push(this.mEtx.code);
456
+ elements.push(base64ToHex($.base64.btoa(lrc)));
457
+ console.log("elements");
458
+ console.log(elements);
459
+
460
+ var final_string = elements.join(" ");
461
+ var final_b64 = hexToBase64(final_string);
462
+ console.log("LRC: " + lrc);
463
+ console.log("Base64: " + final_b64);
464
+
465
+ // if(customData != ''){
466
+ // final_b64 = hexToBase64(final_string+"&custom_data=<PAX>"+customData+"</PAX>");
467
+ // }
468
+
469
+
470
+ var url = this.mDestinationIP + '?' + final_b64;
471
+ console.log("URL: " + url);
472
+
473
+ this.HttpCommunication('DoCredit',url,function(response){
474
+ callback(response);
475
+ },PAX.timeout.DoCredit);
476
+ }
477
+ };
478
+
479
+ return PAX;
480
+ });
481
+
482
+
package/paxcommands.js ADDED
@@ -0,0 +1,134 @@
1
+ const Codes = require("./paxconstants")
2
+
3
+ //=============================================================================================
4
+
5
+ class PAXCommands {
6
+
7
+ static PAXInitialize(){
8
+ //[STX]A00[FS]1.28[ETX]K
9
+ let cmd = String.fromCharCode(2);
10
+ cmd += "A00" + Codes.FS; // FS
11
+ cmd += "1.28";
12
+ let lrc = PAXCommands.calculateLRC(cmd);
13
+ cmd += String.fromCharCode(3);
14
+ cmd += lrc;
15
+ return cmd;
16
+ }
17
+
18
+ //----------------------------------------------------------------------------------------
19
+ static PAXDoCredit(){
20
+ //T00[FS]1.31[FS]01[FS]1.25[FS][FS]123456[FS][FS][FS][FS][FS]ENTRYMODEBITMAP=01111111
21
+
22
+ let cmd = String.fromCharCode(2);
23
+ cmd += "T00" + Codes.FS + "1.31" + Codes.FS + "01" + Codes.FS + "1.25";
24
+ cmd += Codes.FS + Codes.FS + "123456" + Codes.FS + Codes.FS; // FS
25
+ cmd += Codes.FS + Codes.FS + Codes.FS + "ENTRYMODEBITMAP=01111111";
26
+ let lrc = PAXCommands.calculateLRC(cmd);
27
+ cmd += String.fromCharCode(3);
28
+ cmd += lrc;
29
+ return cmd;
30
+ }
31
+ //----------------------------------------------------------------------------------------
32
+ static DoDebit(){
33
+
34
+ }
35
+ //----------------------------------------------------------------------------------------
36
+ static DoSign(){
37
+
38
+ }
39
+ //----------------------------------------------------------------------------------------
40
+ static Reboot(){
41
+
42
+ }
43
+ //----------------------------------------------------------------------------------------
44
+ static CloseBatch(){
45
+
46
+ }
47
+ //----------------------------------------------------------------------------------------
48
+ static GetTranction(){
49
+
50
+ }
51
+ //----------------------------------------------------------------------------------------
52
+ static GetFaildReport(){
53
+
54
+ }
55
+ //----------------------------------------------------------------------------------------
56
+ static GetTranctionDetals(){
57
+
58
+ }
59
+ //----------------------------------------------------------------------------------------
60
+ static ClearBatch(){
61
+
62
+ }
63
+ //----------------------------------------------------------------------------------------
64
+ static DoCNP(){
65
+
66
+ }
67
+ //----------------------------------------------------------------------------------------
68
+ static DoAdjust(){
69
+
70
+ }
71
+ //----------------------------------------------------------------------------------------
72
+ static DoEBT(){
73
+
74
+ }
75
+ //----------------------------------------------------------------------------------------
76
+ static ShowMessage(){
77
+
78
+ }
79
+ //----------------------------------------------------------------------------------------
80
+ static ShowDialog(){
81
+
82
+ }
83
+ //----------------------------------------------------------------------------------------
84
+ static ClearMessage(){
85
+
86
+ }
87
+ //----------------------------------------------------------------------------------------
88
+ static GetSignature(){
89
+
90
+ }
91
+ //----------------------------------------------------------------------------------------
92
+ static CardInsertDetection(){
93
+
94
+ }
95
+ //----------------------------------------------------------------------------------------
96
+ static RemoveCard(){
97
+
98
+ }
99
+ //----------------------------------------------------------------------------------------
100
+ static Cancel(){
101
+
102
+ }
103
+ //----------------------------------------------------------------------------------------
104
+ static Reset(){
105
+
106
+ }
107
+ //----------------------------------------------------------------------------------------
108
+ static ShowMessageLabel(){
109
+
110
+ }
111
+ //----------------------------------------------------------------------------------------
112
+ static InputTexBox(){
113
+
114
+ }
115
+ //----------------------------------------------------------------------------------------
116
+ static CheckCardType(){
117
+
118
+ }
119
+ //----------------------------------------------------------------------------------------
120
+ static calculateLRC (str) {
121
+ var bytes = [];
122
+ var lrc = 0;
123
+ for (var i = 0; i < str.length; i++) {
124
+ bytes.push(str.charCodeAt(i));
125
+ }
126
+ for (var i = 0; i < str.length; i++) {
127
+ lrc ^= bytes[i];
128
+ }
129
+ return String.fromCharCode(lrc);
130
+ }
131
+ };
132
+ //========================================================================================
133
+
134
+ module.exports = PAXCommands;
@@ -0,0 +1,21 @@
1
+ // PAXConstants.js
2
+
3
+ const GS = String.fromCharCode(29);
4
+ const FS = String.fromCharCode(28);
5
+ const US = String.fromCharCode(31);;
6
+ const ACK = String.fromCharCode(6);;
7
+ const HBT = String.fromCharCode(17);;
8
+ const STX = String.fromCharCode(2);;
9
+ const ETX = String.fromCharCode(3);;
10
+ const EOT = String.fromCharCode(4);;
11
+
12
+ module.exports = {
13
+ FS,
14
+ GS,
15
+ US,
16
+ ACK,
17
+ HBT,
18
+ STX,
19
+ ETX,
20
+ EOT
21
+ };
package/serialport.js ADDED
@@ -0,0 +1,41 @@
1
+ const SerialPort = require("serialport");
2
+
3
+ class WeighingScale {
4
+ constructor(portName, baudRate) {
5
+ this.port = new SerialPort(portName, {
6
+ baudRate: baudRate
7
+ });
8
+ }
9
+
10
+ // Function to send data to the serial port
11
+ sendData(data) {
12
+ this.port.write(data, (err) => {
13
+ if (err) {
14
+ return console.log("Error on write: ", err.message);
15
+ }
16
+ console.log(`Data sent: ${data}`);
17
+ });
18
+ }
19
+
20
+ // Listen for data from the serial port
21
+ listen() {
22
+ this.port.on("data", (data) => {
23
+ console.log(`Data received: ${data}`);
24
+ });
25
+ }
26
+
27
+ // Open the serial port
28
+ open() {
29
+ this.port.open((err) => {
30
+ if (err) {
31
+ return console.log("Error opening port: ", err.message);
32
+ }
33
+ console.log(`Serial port ${this.port.path} opened`);
34
+
35
+ // Send the 'W' command to the serial port
36
+ this.sendData(Buffer.from([87]));
37
+ });
38
+ }
39
+ }
40
+
41
+ module.exports = WeighingScale;
package/tcp-socket.js ADDED
@@ -0,0 +1,49 @@
1
+ const net = require('net');
2
+
3
+ //=====================================================================================================
4
+
5
+ class TCPSocket {
6
+ constructor(host, port, timeout=120000) {
7
+ this.host = host;
8
+ this.port = port;
9
+ this.timeout = timeout;
10
+ this.socket = new net.Socket();
11
+ }
12
+
13
+ connect() {
14
+ this.socket.connect(this.port, this.host, () => {
15
+ console.log(`Connected to ${this.host}:${this.port}`);
16
+ this.socket.setTimeout(this.timeout);
17
+ });
18
+ }
19
+
20
+ send(data) {
21
+ this.socket.write(data);
22
+ }
23
+
24
+ receive(callback) {
25
+ this.socket.on('data', (data) => {
26
+ callback(data.toString());
27
+ });
28
+ }
29
+
30
+ onTimeout(callback) {
31
+ this.socket.on('timeout', () => {
32
+ callback();
33
+ });
34
+ }
35
+
36
+ error(callback) {
37
+ this.socket.on('error', (error) => {
38
+ callback(error);
39
+ });
40
+ }
41
+
42
+ close() {
43
+ this.socket.end();
44
+ }
45
+ }
46
+
47
+ //=====================================================================================================
48
+
49
+ module.exports = TCPSocket;