Skip to content

Commit 6de40b3

Browse files
committed
Support inputting template file: node test.js -t template.txt -f test.jpg
1 parent 3c45c2b commit 6de40b3

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

examples/command-line/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ if (args.includes('-f')) {
109109
if (args.includes('-t')) {
110110
let tIndex = args.indexOf('-t');
111111
if (args[tIndex + 1]) {
112-
template = fs.readFileSync(args[tIndex + 1])
112+
templatefile = fs.readFileSync(args[tIndex + 1])
113+
dbr.setParameters(templatefile);
113114
}
114115
else {
115116
console.log('Please add a template file.');

src/config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
var license = '';
1+
var license = 'LICENSE-KEY';
22

33
if (process.platform === 'win32') {
44
console.log('Windows');
5-
license = 't0068NQAAACqUjZa21C+W7fRdPkf2FRFRr+QpfVC2tDsl/8t25TzYCNxl5s0OkuwFgEMGNfN95Z0HYQ55ROi1px9JqVAP7/c=';
65
}
76
else if(process.platform === 'linux') {
87
console.log('Linux');
9-
license = 't0068NQAAAIY/7KegDlZn7YiPdAj0cbA11n2CwuCEWnk2KYla55ozdfmoasjRIpHhl0EUZmko/zxfxFLH3FpLw694uihoCVM=';
108
}
119
else if(process.platform === 'darwin') {
1210
console.log('macOS');
13-
license = 't0068NQAAAIY/7KegDlZn7YiPdAj0cbA11n2CwuCEWnk2KYla55ozdfmoasjRIpHhl0EUZmko/zxfxFLH3FpLw694uihoCVM=';
1411
}
1512
else {
1613
console.log('Unknown Operating System');
@@ -38,5 +35,6 @@ module.exports = {
3835
decodeYUYVAsync: dbr.decodeYUYVAsync,
3936
formats: formats,
4037
initLicense: dbr.initLicense,
41-
barcodeTypes: barcodeTypes
38+
barcodeTypes: barcodeTypes,
39+
setParameters: dbr.setParameters
4240
};

src/dbr.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using namespace v8;
88

99
#define DBR_NO_MEMORY 0
1010
#define DBR_SUCCESS 1
11+
#define DEFAULT_MEMORY_SIZE 4096
1112

1213
// barcode reader handler
1314
void* hBarcode = NULL;
@@ -389,6 +390,28 @@ void DecodeBase64Async(const FunctionCallbackInfo<Value>& args) {
389390
uv_queue_work(uv_default_loop(), &worker->request, (uv_work_cb)DetectionWorking, (uv_after_work_cb)DetectionDone);
390391
}
391392

393+
/*
394+
* setParameters(json)
395+
*/
396+
void SetParameters(const FunctionCallbackInfo<Value>& args) {
397+
if (!createDBR()) {return;}
398+
399+
Isolate* isolate = Isolate::GetCurrent();
400+
HandleScope scope(isolate);
401+
402+
// Get arguments
403+
String::Utf8Value params(args[0]->ToString()); // json string
404+
char *json = *params;
405+
406+
// Update template setting
407+
char errorMessage[DEFAULT_MEMORY_SIZE];
408+
int ret = DBR_InitRuntimeSettingsWithString(hBarcode, json, CM_OVERWRITE, errorMessage, 256);
409+
if (ret)
410+
{
411+
printf("Returned value: %d, error message: %s\n", ret, errorMessage);
412+
}
413+
}
414+
392415
void Init(Handle<Object> exports) {
393416
NODE_SET_METHOD(exports, "create", Create);
394417
NODE_SET_METHOD(exports, "destroy", Destroy);
@@ -397,6 +420,7 @@ void Init(Handle<Object> exports) {
397420
NODE_SET_METHOD(exports, "initLicense", InitLicense);
398421
NODE_SET_METHOD(exports, "decodeFileAsync", DecodeFileAsync);
399422
NODE_SET_METHOD(exports, "decodeBase64Async", DecodeBase64Async);
423+
NODE_SET_METHOD(exports, "setParameters", SetParameters);
400424
}
401425

402426
NODE_MODULE(dbr, Init)

0 commit comments

Comments
 (0)