zusbdll 0.0.4 → 0.0.5
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/index.js +50 -49
- package/lib/SG_API.dll +0 -0
- package/lib/SG_SKF.dll +0 -0
- package/lib/Test_SG.exe +0 -0
- package/lib/scenario.json +20 -0
- package/lib/sglibusb.dll +0 -0
- package/lib/test.c +74 -0
- package/lib/ucrtbased.dll +0 -0
- package/lib/vcruntime140.dll +0 -0
- package/lib/vcruntime140d.dll +0 -0
- package/package.json +1 -1
- package/test.js +13 -12
package/index.js
CHANGED
|
@@ -15,23 +15,23 @@ const DEFAULT_SEARCH_PATHS = ["."];
|
|
|
15
15
|
|
|
16
16
|
// 计算文件的MD5值
|
|
17
17
|
function calculateMD5(filePath) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const hash = crypto.createHash('md5');
|
|
20
|
+
const stream = fs.createReadStream(filePath);
|
|
21
|
+
|
|
22
|
+
stream.on('data', (data) => {
|
|
23
|
+
hash.update(data);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
stream.on('end', () => {
|
|
27
|
+
const md5sum = hash.digest('hex');
|
|
28
|
+
resolve(md5sum);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
stream.on('error', (err) => {
|
|
32
|
+
reject(err);
|
|
33
|
+
});
|
|
33
34
|
});
|
|
34
|
-
});
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function normaliseArgs(args) {
|
|
@@ -310,7 +310,7 @@ function runExecutable(args) {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
|
|
313
|
-
async function executeZusbdll(control) {
|
|
313
|
+
async function executeZusbdll(control) {
|
|
314
314
|
if (process.platform !== "win32") {
|
|
315
315
|
throw new Error("zusbdll requires Windows to execute zdll.exe (win-x86 target).");
|
|
316
316
|
}
|
|
@@ -342,7 +342,7 @@ async function executeZusbdll(control) {
|
|
|
342
342
|
// console.log(`zdll.exe 执行完成,退出代码: ${result.code}`);
|
|
343
343
|
// console.log(`stdout: ${result.stdout}`);
|
|
344
344
|
// console.log(`stderr: ${result.stderr}`);
|
|
345
|
-
|
|
345
|
+
|
|
346
346
|
const parsed = parseOutput(result.stdout);
|
|
347
347
|
|
|
348
348
|
const output = {
|
|
@@ -381,23 +381,17 @@ async function executeZusbdll(control) {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
async function autoRun() {
|
|
384
|
-
let res={
|
|
385
|
-
code:1,
|
|
386
|
-
data:null,
|
|
387
|
-
msg:'error'
|
|
384
|
+
let res = {
|
|
385
|
+
code: 1,
|
|
386
|
+
data: null,
|
|
387
|
+
msg: 'error'
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
// 添加路径信息到返回结果
|
|
391
391
|
const dllPath = path.join(__dirname, "lib", "SG.dll");
|
|
392
392
|
const scenarioPath = path.join(__dirname, "lib", "scenario.json");
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
dllPath: dllPath,
|
|
396
|
-
scenarioPath: scenarioPath,
|
|
397
|
-
executableDir: EXECUTABLE_DIR,
|
|
398
|
-
executablePath: EXECUTABLE_PATH,
|
|
399
|
-
workingDir: __dirname
|
|
400
|
-
};
|
|
393
|
+
|
|
394
|
+
|
|
401
395
|
|
|
402
396
|
try {
|
|
403
397
|
// const scenarioPath = path.join(__dirname, "lib", "scenario.json");
|
|
@@ -407,21 +401,21 @@ async function autoRun() {
|
|
|
407
401
|
let parsedResults;
|
|
408
402
|
try {
|
|
409
403
|
parsedResults = JSON.parse(result.stdout);
|
|
410
|
-
res.code=0;
|
|
411
|
-
res.data=parsedResults;
|
|
412
|
-
res.msg='success'
|
|
404
|
+
res.code = 0;
|
|
405
|
+
res.data = parsedResults;
|
|
406
|
+
res.msg = 'success'
|
|
413
407
|
} catch (parseErr) {
|
|
414
408
|
// console.log("解析结果失败:", parseErr.message);
|
|
415
|
-
res.data=parseErr;
|
|
416
|
-
res.msg=parseErr.message;
|
|
409
|
+
res.data = parseErr;
|
|
410
|
+
res.msg = parseErr.message;
|
|
417
411
|
return res;
|
|
418
412
|
}
|
|
419
413
|
}
|
|
420
414
|
catch (err) {
|
|
421
415
|
// console.log("测试失败!", err.message);
|
|
422
|
-
|
|
423
|
-
res.data=err;
|
|
424
|
-
res.msg=err.message;
|
|
416
|
+
console.log("错误详情:", err);
|
|
417
|
+
res.data = err;
|
|
418
|
+
res.msg = err.message;
|
|
425
419
|
// 添加操作系统信息
|
|
426
420
|
res.system = {
|
|
427
421
|
platform: process.platform,
|
|
@@ -432,27 +426,34 @@ async function autoRun() {
|
|
|
432
426
|
hostname: os.hostname(),
|
|
433
427
|
userInfo: os.userInfo ? os.userInfo() : undefined
|
|
434
428
|
};
|
|
429
|
+
res.paths = {
|
|
430
|
+
dllPath: dllPath,
|
|
431
|
+
scenarioPath: scenarioPath,
|
|
432
|
+
executableDir: EXECUTABLE_DIR,
|
|
433
|
+
executablePath: EXECUTABLE_PATH,
|
|
434
|
+
workingDir: __dirname
|
|
435
|
+
};
|
|
435
436
|
}
|
|
436
437
|
return res
|
|
437
438
|
}
|
|
438
439
|
|
|
439
440
|
async function autoMD5() {
|
|
440
|
-
|
|
441
|
-
code:1,
|
|
442
|
-
data:null,
|
|
443
|
-
msg:'error'
|
|
441
|
+
let res = {
|
|
442
|
+
code: 1,
|
|
443
|
+
data: null,
|
|
444
|
+
msg: 'error'
|
|
444
445
|
}
|
|
445
446
|
try {
|
|
446
447
|
const dllpath = path.join(__dirname, "lib", "SG.dll");
|
|
447
|
-
let md5v=await calculateMD5(dllpath)
|
|
448
|
-
res.code=0;
|
|
449
|
-
res.data=md5v;
|
|
450
|
-
res.msg='success';
|
|
448
|
+
let md5v = await calculateMD5(dllpath)
|
|
449
|
+
res.code = 0;
|
|
450
|
+
res.data = md5v;
|
|
451
|
+
res.msg = 'success';
|
|
451
452
|
} catch (err) {
|
|
452
|
-
res.data=err;
|
|
453
|
-
res.msg=err.message;
|
|
453
|
+
res.data = err;
|
|
454
|
+
res.msg = err.message;
|
|
454
455
|
}
|
|
455
|
-
|
|
456
|
+
return res
|
|
456
457
|
}
|
|
457
458
|
|
|
458
459
|
module.exports = executeZusbdll;
|
package/lib/SG_API.dll
CHANGED
|
Binary file
|
package/lib/SG_SKF.dll
CHANGED
|
Binary file
|
package/lib/Test_SG.exe
CHANGED
|
File without changes
|
package/lib/scenario.json
CHANGED
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
],
|
|
27
27
|
"returns": "int"
|
|
28
28
|
},
|
|
29
|
+
{
|
|
30
|
+
"type": "call",
|
|
31
|
+
"alias": "SG",
|
|
32
|
+
"function": "login",
|
|
33
|
+
"args": [
|
|
34
|
+
"int=2",
|
|
35
|
+
"stringbuilder[32]="
|
|
36
|
+
],
|
|
37
|
+
"returns": "int"
|
|
38
|
+
},
|
|
29
39
|
{
|
|
30
40
|
"type": "call",
|
|
31
41
|
"alias": "SG",
|
|
@@ -46,6 +56,16 @@
|
|
|
46
56
|
],
|
|
47
57
|
"returns": "int"
|
|
48
58
|
},
|
|
59
|
+
{
|
|
60
|
+
"type": "call",
|
|
61
|
+
"alias": "SG",
|
|
62
|
+
"function": "login",
|
|
63
|
+
"args": [
|
|
64
|
+
"int=5",
|
|
65
|
+
"stringbuilder[32]="
|
|
66
|
+
],
|
|
67
|
+
"returns": "int"
|
|
68
|
+
},
|
|
49
69
|
{
|
|
50
70
|
"type": "unload",
|
|
51
71
|
"alias": "SG"
|
package/lib/sglibusb.dll
ADDED
|
Binary file
|
package/lib/test.c
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#include "SG.h"
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
int main()
|
|
7
|
+
{
|
|
8
|
+
BOOL ret = 0;
|
|
9
|
+
char error[32] = {0};
|
|
10
|
+
|
|
11
|
+
ret = login(0, error);
|
|
12
|
+
if (0 == ret)
|
|
13
|
+
{
|
|
14
|
+
printf("id(0)测试失败!error = %s.\n", error);
|
|
15
|
+
}
|
|
16
|
+
else
|
|
17
|
+
{
|
|
18
|
+
printf("id(0)测试成功!\n");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ret = login(1, error);
|
|
22
|
+
if (0 == ret)
|
|
23
|
+
{
|
|
24
|
+
printf("id(1)测试失败!error = %s.\n", error);
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
{
|
|
28
|
+
printf("id(1)测试成功!\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ret = login(2, error);
|
|
32
|
+
if (0 == ret)
|
|
33
|
+
{
|
|
34
|
+
printf("id(2)测试失败!error = %s.\n", error);
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
{
|
|
38
|
+
printf("id(2)测试成功!\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ret = login(3, error);
|
|
42
|
+
if (0 == ret)
|
|
43
|
+
{
|
|
44
|
+
printf("id(3)测试失败!error = %s.\n", error);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
printf("id(3)测试成功!\n");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
ret = login(4, error);
|
|
52
|
+
if (0 == ret)
|
|
53
|
+
{
|
|
54
|
+
printf("id(4)测试失败!error = %s.\n", error);
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
{
|
|
58
|
+
printf("id(4)测试成功!\n");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ret = login(5, error);
|
|
62
|
+
if (0 == ret)
|
|
63
|
+
{
|
|
64
|
+
printf("id(5)测试失败!error = %s.\n", error);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{
|
|
68
|
+
printf("id(5)测试成功!\n");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
system("pause");
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const {executeZusbdll,autoRun,autoMD5} = require('./index');
|
|
1
|
+
const { executeZusbdll, autoRun, autoMD5 } = require('./index');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
async function runDemo() {
|
|
5
5
|
console.log("开始测试 login 函数...");
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
try {
|
|
8
8
|
// 使用之前验证过的工作正常的场景文件
|
|
9
9
|
const scenarioPath = path.join(__dirname, "lib", "scenario.json");
|
|
10
10
|
const result = await executeZusbdll(scenarioPath);
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
// 解析返回的 JSON 数据
|
|
13
13
|
let parsedResults;
|
|
14
14
|
try {
|
|
@@ -17,19 +17,19 @@ async function runDemo() {
|
|
|
17
17
|
console.log("解析结果失败:", parseErr.message);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
// 遍历所有结果,找出 login 调用的结果
|
|
22
22
|
for (let i = 0; i < parsedResults.length; i++) {
|
|
23
23
|
const callResult = parsedResults[i];
|
|
24
24
|
if (callResult.command === "login") {
|
|
25
25
|
// login 函数的返回值在 returnCode 字段中
|
|
26
26
|
const success = callResult.returnCode === 1;
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
// 获取 id 值(从第一个参数中获取)
|
|
29
29
|
const id = callResult.outputs && callResult.outputs[0] ? callResult.outputs[0].value : i;
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
console.log(success ? `id(${id})测试成功!` : `id(${id})测试失败!`);
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
// 显示错误信息(如果有的话)
|
|
34
34
|
if (callResult.outputs && callResult.outputs.length > 1) {
|
|
35
35
|
const errorOutput = callResult.outputs[1];
|
|
@@ -43,7 +43,7 @@ async function runDemo() {
|
|
|
43
43
|
console.log("测试失败!", err.message);
|
|
44
44
|
console.log("错误详情:", err);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
console.log("测试完成!");
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -51,13 +51,14 @@ async function runDemo() {
|
|
|
51
51
|
if (require.main === module) {
|
|
52
52
|
// runDemo().catch(console.error);
|
|
53
53
|
}
|
|
54
|
-
(async function(){
|
|
55
|
-
|
|
54
|
+
(async function () {
|
|
55
|
+
resmd5 = await autoMD5();
|
|
56
|
+
console.log(resmd5)
|
|
57
|
+
|
|
58
|
+
try {
|
|
56
59
|
console.log('start')
|
|
57
60
|
res = await autoRun();
|
|
58
|
-
resmd5 = await autoMD5();
|
|
59
61
|
console.log(res)
|
|
60
|
-
console.log(resmd5)
|
|
61
62
|
} catch (error) {
|
|
62
63
|
console.log("错误详情:", error);
|
|
63
64
|
}
|