Skip to content

Commit 6664330

Browse files
committed
Set scannerFailureTimeout to 60
1 parent 8b9f576 commit 6664330

4 files changed

Lines changed: 46 additions & 38 deletions

File tree

examples/REST/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ app.post('/createJob', async (req, res) => {
2626
let parameters = {
2727
license: "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==",
2828
device: data['scan'],
29+
scannerFailureTimeout: 60
2930
};
3031

3132
parameters.config = {
3233
IfShowUI: false,
3334
PixelType: 2,
34-
//XferCount: 1,
35-
//PageSize: 1,
36-
Resolution: 200,
35+
Resolution: 100,
3736
IfFeederEnabled: false,
3837
IfDuplexEnabled: false,
3938
};

examples/command-line/app.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function askQuestion() {
2424
rl.close();
2525
}
2626
else if (answer === '1') {
27-
docscan4nodejs.getDevices(host, docscan4nodejs.ScannerType.TWAINSCANNER | docscan4nodejs.ScannerType.TWAINX64SCANNER).then((scanners) => {
27+
docscan4nodejs.getDevices(host, docscan4nodejs.ScannerType.TWAINSCANNER | docscan4nodejs.ScannerType.TWAINX64SCANNER | docscan4nodejs.ScannerType.WIASCANNER).then((scanners) => {
2828
devices = [];
2929
for (let i = 0; i < scanners.length; i++) {
3030
devices.push(scanners[i]);
@@ -54,7 +54,8 @@ function askQuestion() {
5454
let parameters = {
5555
license: "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==",
5656
device: devices[index].device,
57-
autoRun: true
57+
autoRun: true,
58+
scannerFailureTimeout: 60
5859
};
5960

6061
parameters.config = {
@@ -63,54 +64,61 @@ function askQuestion() {
6364
//XferCount: 1,
6465
//PageSize: 1,
6566
Resolution: 200,
66-
IfFeederEnabled: true,
67+
IfFeederEnabled: false,
6768
IfDuplexEnabled: false,
6869
};
6970

7071
docscan4nodejs.createJob(host, parameters).then((job) => {
7172
try {
7273
let jobId = job.jobuid;
7374

74-
(async () => {
75-
// let status = await docscan4nodejs.checkJob(host, jobId);
76-
// console.log('Job status:', status);
75+
if (jobId) {
76+
(async () => {
77+
// let status = await docscan4nodejs.checkJob(host, jobId);
78+
// console.log('Job status:', status);
7779

78-
// let caps = await docscan4nodejs.getScannerCapabilities(host, jobId);
79-
// console.log('Capabilities:', caps);
80+
// let caps = await docscan4nodejs.getScannerCapabilities(host, jobId);
81+
// console.log('Capabilities:', caps);
8082

81-
// let updateStatus = await docscan4nodejs.updateJob(host, jobId, {
82-
// status: docscan4nodejs.JobStatus.RUNNING
83-
// });
84-
// console.log('Update status:', updateStatus);
85-
let doc = await docscan4nodejs.createDocument(host, {});
86-
// console.log('Document:', doc);
83+
// let updateStatus = await docscan4nodejs.updateJob(host, jobId, {
84+
// status: docscan4nodejs.JobStatus.RUNNING
85+
// });
86+
// console.log('Update status:', updateStatus);
87+
let doc = await docscan4nodejs.createDocument(host, {});
88+
// console.log('Document:', doc);
8789

8890

89-
let images = await docscan4nodejs.getImageFiles(host, jobId, './');
90-
for (let i = 0; i < images.length; i++) {
91-
console.log('Image ' + i + ': ' + images[i]);
92-
let info = await docscan4nodejs.getImageInfo(host, jobId);
93-
// console.log('Image info:', info);
91+
let images = await docscan4nodejs.getImageFiles(host, jobId, './');
92+
for (let i = 0; i < images.length; i++) {
93+
console.log('Image ' + i + ': ' + images[i]);
94+
let info = await docscan4nodejs.getImageInfo(host, jobId);
95+
// console.log('Image info:', info);
9496

95-
let insertPage = await docscan4nodejs.insertPage(host, doc.uid, { password: '', source: info.url });
96-
// console.log('Insert page:', insertPage);
97-
}
97+
let insertPage = await docscan4nodejs.insertPage(host, doc.uid, { password: '', source: info.url });
98+
// console.log('Insert page:', insertPage);
99+
}
98100

99101

100-
let docinfo = await docscan4nodejs.getDocumentInfo(host, doc.uid);
101-
// console.log('Document info:', docinfo);
102+
let docinfo = await docscan4nodejs.getDocumentInfo(host, doc.uid);
103+
// console.log('Document info:', docinfo);
102104

103-
// let deletePage = await docscan4nodejs.deletePage(host, doc.uid, insertPage.pages[0].uid);
104-
// console.log('Delete page:', deletePage);
105-
let docfile = await docscan4nodejs.getDocumentFile(host, doc.uid, './');
106-
console.log('Document file:', docfile);
105+
// let deletePage = await docscan4nodejs.deletePage(host, doc.uid, insertPage.pages[0].uid);
106+
// console.log('Delete page:', deletePage);
107+
let docfile = await docscan4nodejs.getDocumentFile(host, doc.uid, './');
108+
console.log('Document file:', docfile);
107109

108-
let deleteDoc = await docscan4nodejs.deleteDocument(host, doc.uid);
109-
console.log('Delete document:', deleteDoc);
110+
let deleteDoc = await docscan4nodejs.deleteDocument(host, doc.uid);
111+
console.log('Delete document:', deleteDoc);
110112

111-
await docscan4nodejs.deleteJob(host, jobId);
113+
await docscan4nodejs.deleteJob(host, jobId);
114+
askQuestion();
115+
})();
116+
}
117+
else {
118+
console.log('Job creation failed.');
112119
askQuestion();
113-
})();
120+
}
121+
114122
}
115123
catch (error) {
116124
console.error('Job creation failed:', error.message);

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ async function getScannerCapabilities(host, jobId) {
293293
// Get multiple image files
294294
async function getImageFiles(host, jobId, directory) {
295295
const images = [];
296-
console.log('Starting image download...');
297296

298297
while (true) {
299298
const filename = await getImageFile(host, jobId, directory);
@@ -351,7 +350,6 @@ async function createDocument(host, parameters) {
351350
json: true,
352351
body: parameters
353352
});
354-
console.log('Document created:', response);
355353
return response.status === 201 ? response.data : '';
356354
}
357355
catch (error) {
@@ -438,6 +436,9 @@ async function getDocumentFile(host, docId, directory) {
438436
writer.on('close', () => clearTimeout(timeout));
439437
});
440438
}
439+
else {
440+
console.error('Document fetch failed:', response.status);
441+
}
441442
}
442443
catch (error) {
443444
console.error('Document fetch failed:', error.message);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docscan4nodejs",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Node.js API for Dynamsoft Document Scanning Service. Supports TWAIN, SANE, ICA, WIA, eSCL scanners.",
55
"keywords": [
66
"Document Scanning",

0 commit comments

Comments
 (0)