Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jensen
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Skye Yu
jensen
Commits
293a23bd
Commit
293a23bd
authored
Jul 31, 2025
by
carl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新增onerror方法错误提示
parent
0cf71b5f
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
877 additions
and
0 deletions
+877
-0
jensen.d.ts
jensen.d.ts
+2
-0
pnpm-lock.yaml
pnpm-lock.yaml
+839
-0
index.tsx
src/index.tsx
+27
-0
jensen.js
src/utils/jensen.js
+9
-0
No files found.
jensen.d.ts
View file @
293a23bd
...
@@ -139,6 +139,8 @@ declare class Jensen {
...
@@ -139,6 +139,8 @@ declare class Jensen {
connect
:
()
=>
Promise
<
void
>
;
connect
:
()
=>
Promise
<
void
>
;
// 事件:当连接完成时触发
// 事件:当连接完成时触发
onconnect
:
()
=>
void
;
onconnect
:
()
=>
void
;
// 事件:当连接异常时触发
onerror
:
(
e
:
Error
)
=>
void
;
// 主动断开连接(单连接时适用)
// 主动断开连接(单连接时适用)
disconnect
:
()
=>
void
;
disconnect
:
()
=>
void
;
// 事件:当连接断开时触发
// 事件:当连接断开时触发
...
...
pnpm-lock.yaml
0 → 100644
View file @
293a23bd
This diff is collapsed.
Click to expand it.
src/index.tsx
View file @
293a23bd
...
@@ -15,9 +15,16 @@ export function Home() {
...
@@ -15,9 +15,16 @@ export function Home() {
jensen
.
onconnect
=
()
=>
{
jensen
.
onconnect
=
()
=>
{
console
.
log
(
'connect successfully'
);
console
.
log
(
'connect successfully'
);
jensen
.
getDeviceInfo
().
then
((
info
)
=>
{
jensen
.
getDeviceInfo
().
then
((
info
)
=>
{
console
.
log
(
'getDeviceInfo'
,
info
);
alert
(
info
.
sn
+
' connected'
);
alert
(
info
.
sn
+
' connected'
);
}).
catch
((
e
)
=>
{
console
.
log
(
'getDeviceInfo error'
,
e
);
});
});
};
};
// jensen.onerror = (e) => {
// console.log('onerror', e);
// alert('此设备已经在其它已打开的HiNotes网页上建立连接');
// };
},
[]);
},
[]);
const
getFilePart
=
()
=>
{
const
getFilePart
=
()
=>
{
...
@@ -40,6 +47,25 @@ export function Home() {
...
@@ -40,6 +47,25 @@ export function Home() {
setDevices
(
devices
);
setDevices
(
devices
);
setGreeting
(
null
)
setGreeting
(
null
)
}
}
const
connecty
=
async
()
=>
{
const
usb
=
(
navigator
as
any
).
usb
;
let
conn
=
await
usb
.
requestDevice
({
filters
:
[{
vendorId
:
0x10d6
},
{
vendorId
:
0x3887
}]
});
if
(
conn
==
null
)
return
null
;
// if (conn.opened) throw new Error('device_already_opened');
await
conn
.
open
();
let
jensen
=
new
Jensen
(
Logger
,
conn
);
jensen
.
onerror
=
(
e
)
=>
{
console
.
log
(
'onerror'
,
e
);
alert
(
'此设备已经在其它已打开的HiNotes网页上建立连接'
);
};
await
jensen
.
initialize
();
let
dinfo
=
await
jensen
.
getDeviceInfo
();
if
(
dinfo
)
console
.
log
(
'dinfo'
,
dinfo
);
return
null
;
}
const
connect
=
async
()
=>
{
const
connect
=
async
()
=>
{
await
jensen
.
connect
();
await
jensen
.
connect
();
...
@@ -220,6 +246,7 @@ export function Home() {
...
@@ -220,6 +246,7 @@ export function Home() {
return
(
return
(
<>
<>
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'row'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
,
flexWrap
:
'wrap'
}
}
>
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'row'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
,
flexWrap
:
'wrap'
}
}
>
<
button
onClick=
{
connecty
}
>
连接新设备
</
button
>
<
button
onClick=
{
connect
}
>
连接
</
button
>
<
button
onClick=
{
connect
}
>
连接
</
button
>
<
button
onClick=
{
getFilePart
}
>
获取文件
</
button
>
<
button
onClick=
{
getFilePart
}
>
获取文件
</
button
>
<
button
onClick=
{
writeSN
}
>
SN写号
</
button
>
<
button
onClick=
{
writeSN
}
>
SN写号
</
button
>
...
...
src/utils/jensen.js
View file @
293a23bd
...
@@ -99,6 +99,7 @@ function Jensen(log, conn) {
...
@@ -99,6 +99,7 @@ function Jensen(log, conn) {
this
.
isStopConnectionCheck
=
false
;
this
.
isStopConnectionCheck
=
false
;
this
.
onconnect
=
null
;
this
.
onconnect
=
null
;
this
.
onreceive
=
null
;
this
.
onreceive
=
null
;
this
.
onerror
=
null
;
const
RECV_BUFF_SIZE
=
51200
;
const
RECV_BUFF_SIZE
=
51200
;
...
@@ -382,7 +383,11 @@ function Jensen(log, conn) {
...
@@ -382,7 +383,11 @@ function Jensen(log, conn) {
Logger
.
save
?.(
'jensen'
,
'tryReceive'
,
r
?.
data
);
Logger
.
save
?.(
'jensen'
,
'tryReceive'
,
r
?.
data
);
console
.
log
(
pid
+
' Receive'
,
r
?.
data
);
console
.
log
(
pid
+
' Receive'
,
r
?.
data
);
receive
(
r
);
receive
(
r
);
}).
catch
((
e
)
=>
{
console
.
log
(
'tryReceive error'
,
e
)
self
.
onerror
?.(
e
);
});
});
};
};
const
read_int
=
function
(
a
,
b
,
c
,
d
)
{
const
read_int
=
function
(
a
,
b
,
c
,
d
)
{
...
@@ -394,6 +399,10 @@ function Jensen(log, conn) {
...
@@ -394,6 +399,10 @@ function Jensen(log, conn) {
};
};
const
receive
=
function
(
result
)
{
const
receive
=
function
(
result
)
{
if
(
result
instanceof
Error
)
{
console
.
log
(
'receive error'
,
result
);
return
}
totalBytes
+=
result
.
data
.
byteLength
;
totalBytes
+=
result
.
data
.
byteLength
;
// 做一个回调,怎么样找到它呢?
// 做一个回调,怎么样找到它呢?
blocks
.
push
(
result
.
data
);
blocks
.
push
(
result
.
data
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment