更换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 name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -72,24 +72,56 @@ function loadDll() {
|
||||
lib = koffi.load(dllPath);
|
||||
|
||||
// 尝试使用 stdcall 约定,这对于 Windows 32位 DLL 很常见
|
||||
// koffi 中指定 stdcall 约定需要在函数名前加 __stdcall,但不能作为字符串拼接在类型里
|
||||
// 正确语法是 lib.stdcall('函数名', '返回类型', ['参数类型'...]) 或者在字符串定义中使用特定格式
|
||||
// 根据 koffi 文档,字符串定义格式为: "ReturnType __stdcall FunctionName(Args...)"
|
||||
// koffi 2.x 版本中,stdcall 约定需要在函数名前加 __stdcall
|
||||
// 如果字符串解析失败,可以尝试使用 lib.stdcall() 方法
|
||||
|
||||
return {
|
||||
Syn_FindUSBReader: lib.func("int __stdcall Syn_FindUSBReader()"),
|
||||
Syn_USBOpenPort: lib.func("int __stdcall Syn_USBOpenPort(int)"),
|
||||
Syn_USBClosePort: lib.func("int __stdcall Syn_USBClosePort(int)"),
|
||||
Syn_USBStartFindIDCard: lib.func(
|
||||
"int __stdcall Syn_USBStartFindIDCard(int, uint8*, int)"
|
||||
),
|
||||
Syn_USBSelectIDCard: lib.func(
|
||||
"int __stdcall Syn_USBSelectIDCard(int, uint8*, int)"
|
||||
),
|
||||
Syn_ReadMsg: lib.func(
|
||||
"int __stdcall Syn_ReadMsg(int, int, _Out_ IDCardData*)"
|
||||
),
|
||||
// 辅助函数:尝试加载函数,支持原名和修饰名
|
||||
const loadFunc = (name, alias, ret, args) => {
|
||||
try {
|
||||
return lib.stdcall(name, ret, args);
|
||||
} catch (e) {
|
||||
try {
|
||||
return lib.stdcall(alias, ret, args);
|
||||
} catch (e2) {
|
||||
throw new Error(
|
||||
`Cannot find function '${name}' or '${alias}' in DLL`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
parentPort.postMessage({
|
||||
type: "error",
|
||||
@@ -110,19 +142,35 @@ async function startListen() {
|
||||
}
|
||||
|
||||
try {
|
||||
let port = api.Syn_FindUSBReader();
|
||||
if (port <= 0) port = 1001;
|
||||
// 尝试打开端口,优先尝试 1001 (USB)
|
||||
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) {
|
||||
parentPort.postMessage({
|
||||
type: "error",
|
||||
payload: `Open port ${port} failed: ${openRes}`,
|
||||
payload: `Open port failed (tried 1001-1016)`,
|
||||
});
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
parentPort.postMessage({
|
||||
type: "log",
|
||||
payload: `Port ${port} opened successfully`,
|
||||
});
|
||||
|
||||
const iin = Buffer.alloc(4);
|
||||
const sn = Buffer.alloc(8);
|
||||
// IDCardData 结构体大小计算: 32+6+20+18+72+38+32+18+18+38+255 = 547 字节
|
||||
@@ -130,9 +178,9 @@ async function startListen() {
|
||||
|
||||
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 输出对象
|
||||
@@ -152,6 +200,10 @@ async function startListen() {
|
||||
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 });
|
||||
|
||||
// 读到卡后暂停一下,避免重复读取太快
|
||||
@@ -162,7 +214,7 @@ async function startListen() {
|
||||
}
|
||||
}
|
||||
|
||||
api.Syn_USBClosePort(port);
|
||||
api.Syn_ClosePort(port);
|
||||
} catch (err) {
|
||||
parentPort.postMessage({
|
||||
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;
|
||||
console.log("[idcard-data]", payload);
|
||||
window.electronAPI.log("info", `[idcard-data] received`);
|
||||
window.electronAPI.log(
|
||||
"info",
|
||||
`Read IDCard success: ${payload.name} ${payload.id_card_no}`
|
||||
);
|
||||
// 成功:清理定时器,停止监听,跳转并传递身份证号
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current);
|
||||
|
||||
Reference in New Issue
Block a user