更换dll
This commit is contained in:
42
dist/assets/index-cab5b0f8.js
vendored
42
dist/assets/index-cab5b0f8.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.html
vendored
2
dist/index.html
vendored
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Electron + React App</title>
|
<title>Electron + React App</title>
|
||||||
<script type="module" crossorigin src="./assets/index-cab5b0f8.js"></script>
|
<script type="module" crossorigin src="./assets/index-cc0bc14e.js"></script>
|
||||||
<link rel="stylesheet" href="./assets/index-0c3a5195.css">
|
<link rel="stylesheet" href="./assets/index-0c3a5195.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -72,24 +72,56 @@ function loadDll() {
|
|||||||
lib = koffi.load(dllPath);
|
lib = koffi.load(dllPath);
|
||||||
|
|
||||||
// 尝试使用 stdcall 约定,这对于 Windows 32位 DLL 很常见
|
// 尝试使用 stdcall 约定,这对于 Windows 32位 DLL 很常见
|
||||||
// koffi 中指定 stdcall 约定需要在函数名前加 __stdcall,但不能作为字符串拼接在类型里
|
// koffi 2.x 版本中,stdcall 约定需要在函数名前加 __stdcall
|
||||||
// 正确语法是 lib.stdcall('函数名', '返回类型', ['参数类型'...]) 或者在字符串定义中使用特定格式
|
// 如果字符串解析失败,可以尝试使用 lib.stdcall() 方法
|
||||||
// 根据 koffi 文档,字符串定义格式为: "ReturnType __stdcall FunctionName(Args...)"
|
|
||||||
|
|
||||||
return {
|
// 辅助函数:尝试加载函数,支持原名和修饰名
|
||||||
Syn_FindUSBReader: lib.func("int __stdcall Syn_FindUSBReader()"),
|
const loadFunc = (name, alias, ret, args) => {
|
||||||
Syn_USBOpenPort: lib.func("int __stdcall Syn_USBOpenPort(int)"),
|
try {
|
||||||
Syn_USBClosePort: lib.func("int __stdcall Syn_USBClosePort(int)"),
|
return lib.stdcall(name, ret, args);
|
||||||
Syn_USBStartFindIDCard: lib.func(
|
} catch (e) {
|
||||||
"int __stdcall Syn_USBStartFindIDCard(int, uint8*, int)"
|
try {
|
||||||
),
|
return lib.stdcall(alias, ret, args);
|
||||||
Syn_USBSelectIDCard: lib.func(
|
} catch (e2) {
|
||||||
"int __stdcall Syn_USBSelectIDCard(int, uint8*, int)"
|
throw new Error(
|
||||||
),
|
`Cannot find function '${name}' or '${alias}' in DLL`
|
||||||
Syn_ReadMsg: lib.func(
|
);
|
||||||
"int __stdcall Syn_ReadMsg(int, int, _Out_ IDCardData*)"
|
}
|
||||||
),
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
Syn_OpenPort: loadFunc("Syn_OpenPort", "_Syn_OpenPort@4", "int", [
|
||||||
|
"int",
|
||||||
|
]),
|
||||||
|
Syn_ClosePort: loadFunc("Syn_ClosePort", "_Syn_ClosePort@4", "int", [
|
||||||
|
"int",
|
||||||
|
]),
|
||||||
|
Syn_StartFindIDCard: loadFunc(
|
||||||
|
"Syn_StartFindIDCard",
|
||||||
|
"_Syn_StartFindIDCard@12",
|
||||||
|
"int",
|
||||||
|
["int", "uint8*", "int"]
|
||||||
|
),
|
||||||
|
Syn_SelectIDCard: loadFunc(
|
||||||
|
"Syn_SelectIDCard",
|
||||||
|
"_Syn_SelectIDCard@12",
|
||||||
|
"int",
|
||||||
|
["int", "uint8*", "int"]
|
||||||
|
),
|
||||||
|
Syn_ReadMsg: loadFunc("Syn_ReadMsg", "_Syn_ReadMsg@12", "int", [
|
||||||
|
"int",
|
||||||
|
"int",
|
||||||
|
koffi.out(koffi.pointer(IDCardData)),
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
// 如果 lib.stdcall 也不行,尝试回退到 func 但不带 __stdcall (可能不是 stdcall 或者 koffi 版本差异)
|
||||||
|
// 但根据之前的错误,不带 __stdcall 找不到函数,带了又报类型错误,说明很可能是 stdcall 但字符串解析有问题
|
||||||
|
// 这里我们坚持用 lib.stdcall 这种显式 API 调用,它比字符串解析更稳定
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
parentPort.postMessage({
|
parentPort.postMessage({
|
||||||
type: "error",
|
type: "error",
|
||||||
@@ -110,19 +142,35 @@ async function startListen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let port = api.Syn_FindUSBReader();
|
// 尝试打开端口,优先尝试 1001 (USB)
|
||||||
if (port <= 0) port = 1001;
|
let port = 1001;
|
||||||
|
let openRes = api.Syn_OpenPort(port);
|
||||||
|
|
||||||
|
if (openRes !== 0) {
|
||||||
|
// 如果 1001 失败,尝试 1001-1016
|
||||||
|
for (let p = 1002; p <= 1016; p++) {
|
||||||
|
if (api.Syn_OpenPort(p) === 0) {
|
||||||
|
port = p;
|
||||||
|
openRes = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const openRes = api.Syn_USBOpenPort(port);
|
|
||||||
if (openRes !== 0) {
|
if (openRes !== 0) {
|
||||||
parentPort.postMessage({
|
parentPort.postMessage({
|
||||||
type: "error",
|
type: "error",
|
||||||
payload: `Open port ${port} failed: ${openRes}`,
|
payload: `Open port failed (tried 1001-1016)`,
|
||||||
});
|
});
|
||||||
running = false;
|
running = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parentPort.postMessage({
|
||||||
|
type: "log",
|
||||||
|
payload: `Port ${port} opened successfully`,
|
||||||
|
});
|
||||||
|
|
||||||
const iin = Buffer.alloc(4);
|
const iin = Buffer.alloc(4);
|
||||||
const sn = Buffer.alloc(8);
|
const sn = Buffer.alloc(8);
|
||||||
// IDCardData 结构体大小计算: 32+6+20+18+72+38+32+18+18+38+255 = 547 字节
|
// IDCardData 结构体大小计算: 32+6+20+18+72+38+32+18+18+38+255 = 547 字节
|
||||||
@@ -130,9 +178,9 @@ async function startListen() {
|
|||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
// 寻卡
|
// 寻卡
|
||||||
api.Syn_USBStartFindIDCard(port, iin, 0);
|
api.Syn_StartFindIDCard(port, iin, 0);
|
||||||
// 选卡
|
// 选卡
|
||||||
api.Syn_USBSelectIDCard(port, sn, 0);
|
api.Syn_SelectIDCard(port, sn, 0);
|
||||||
|
|
||||||
// 读卡
|
// 读卡
|
||||||
const data = {}; // koffi 输出对象
|
const data = {}; // koffi 输出对象
|
||||||
@@ -152,6 +200,10 @@ async function startListen() {
|
|||||||
photo_path: decodeGBK(Buffer.from(data.PhotoFileName)),
|
photo_path: decodeGBK(Buffer.from(data.PhotoFileName)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
parentPort.postMessage({
|
||||||
|
type: "log",
|
||||||
|
payload: `Read IDCard success: ${payload.name} ${payload.id_card_no}`,
|
||||||
|
});
|
||||||
parentPort.postMessage({ type: "data", payload });
|
parentPort.postMessage({ type: "data", payload });
|
||||||
|
|
||||||
// 读到卡后暂停一下,避免重复读取太快
|
// 读到卡后暂停一下,避免重复读取太快
|
||||||
@@ -162,7 +214,7 @@ async function startListen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api.Syn_USBClosePort(port);
|
api.Syn_ClosePort(port);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
parentPort.postMessage({
|
parentPort.postMessage({
|
||||||
type: "error",
|
type: "error",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
7
resources/xzx/Config.ini
Normal file
7
resources/xzx/Config.ini
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[ReadCardConfig]
|
||||||
|
PortType=USB
|
||||||
|
Port=1001
|
||||||
|
BaudRate=115200
|
||||||
|
AutoPrint=false
|
||||||
|
MakePhotoById=false
|
||||||
|
BandRate=115200
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -50,6 +50,10 @@ const U1: React.FC = () => {
|
|||||||
const payload = e.payload;
|
const payload = e.payload;
|
||||||
console.log("[idcard-data]", payload);
|
console.log("[idcard-data]", payload);
|
||||||
window.electronAPI.log("info", `[idcard-data] received`);
|
window.electronAPI.log("info", `[idcard-data] received`);
|
||||||
|
window.electronAPI.log(
|
||||||
|
"info",
|
||||||
|
`Read IDCard success: ${payload.name} ${payload.id_card_no}`
|
||||||
|
);
|
||||||
// 成功:清理定时器,停止监听,跳转并传递身份证号
|
// 成功:清理定时器,停止监听,跳转并传递身份证号
|
||||||
if (timerRef.current) {
|
if (timerRef.current) {
|
||||||
clearTimeout(timerRef.current);
|
clearTimeout(timerRef.current);
|
||||||
|
|||||||
Reference in New Issue
Block a user