-
Notifications
You must be signed in to change notification settings - Fork 0
usb port! design
bitbegin edited this page Apr 7, 2019
·
11 revisions
预计支持2类usb port!, usb://
、hid://
。
- url:
usb://
- 设备描述:class为0xFF
- url:
hid://
- 设备描述:usb hid类型
Notes: 假设pc上接有usb://vid-pid1/serialnum1
、usb://vid-pid1/serialnum2
、usb://vid-pid2/serialnum3
devices: query usb://
= [
make object! [
port: usb://vid-pid1/serialnum1
discriptions: ...
]
make object! [
port: usb://vid-pid1/serialnum2
discriptions: ...
]
make object! [
port: usb://vid-pid2/serialnum3
discriptions: ...
]
; other devices ...
]
devices: query usb://vid-pid1
= [
make object! [
port: usb://vid-pid1/serialnum1
discriptions: ...
]
make object! [
port: usb://vid-pid1/serialnum2
discriptions: ...
]
]
devices: query usb://vid-pid1/serialnum1
= [
make object! [
port: usb://vid-pid1/serialnum1
discriptions: ...
]
]
Notes: 假设pc上接有hid://vid-pid1/serialnum1
、hid://vid-pid1/serialnum2
、hid://vid-pid2/serialnum3
devices: query hid://
= [
make object! [
port: hid://vid-pid1/serialnum1
discriptions: ... ;(include report description)
]
make object! [
port: hid://vid-pid2/serialnum3
discriptions: ... ;(include report description)
]
; other hid devices ...
]
devices: query hid://vid-pid1
= [
make object! [
port: hid://vid-pid1/serialnum1
discriptions: ... ;(include report description)
]
]
devices: query hid://vid-pid1/serialnum1
= [
make object! [
port: hid://vid-pid1/serialnum1
discriptions: ... ;(include report description)
]
]
Notes: 设备端口0控制传输,如果serialnum1不存在,使用找到的第一个设备
等价为: usb://vid-pid1/serialnum1/transfer=Control
port: open usb://vid-pid1/serialnum1
= make port! [
spec: make object! [
scheme: 'usb
user-info: none
host: "vid-pid1"
port: none
path: %/
target: %serialnum1
query: none
fragment: none
ref: usb://vid-pid1/serialnum1
]
select-pipo: func [port [port!]] [
port/state/rpipo: 0
port/state/wpipo: 0
port/state/trasfer: 'Control
]
scheme: make object! [
open: func [port [port!] /local spec][
probe "open port"
port/state/info: get-usb-info vid-pid1 none
select-pipo port
port/state/closed?: false
usb-open port
]
insert: func [
port [port!]
data [binary! string!]
][
unless port/state/closed? [
usb-write port data
]
]
copy: func [port [port!]][
unless port/state/closed? [
usb-read port
]
]
close: func [port [port!]][
unless port/state/closed? [
usb-close port
port/state/closed?: yes
port/state/info: none
port/state/sub: none
]
]
]
actor: none
awake: none
state: make object! [
state: 'init
sub: none
error: none
closed?: false
info: none
trasfer: none
rpipo: none
wpipo: none
]
data: none
]
Notes: 端口1为read端口,端口2为write端口,默认中断传输
等价为: usb://vid-pid1/serialnum1/in=01&out=02&transfer=Interrupt
port: open usb://vid-pid1/serialnum1/port=0102
= make port! [
spec: make object! [
scheme: 'usb
user-info: none
host: "vid-pid1"
port: none
path: %/serialnum1/
target: %port=0102
query: none
fragment: none
ref: usb://vid-pid1/serialnum1/port=0102
]
select-pipo: func [port [port!]] [
port/state/rpipo: 1
port/state/wpipo: 2
port/state/trasfer: 'Interrupt
]
scheme: make object! [
open: func [port [port!] /local spec][
probe "open port"
port/state/info: get-usb-info vid-pid1 none
select-pipo port
port/state/closed?: false
usb-open port
]
insert: func [
port [port!]
data [binary! string!]
][
unless port/state/closed? [
usb-write port data
]
]
copy: func [port [port!]][
unless port/state/closed? [
usb-read port
]
]
close: func [port [port!]][
unless port/state/closed? [
usb-close port
port/state/closed?: yes
port/state/info: none
port/state/sub: none
]
]
]
actor: none
awake: none
state: make object! [
state: 'init
sub: none
error: none
closed?: false
info: none
trasfer: none
rpipo: none
wpipo: none
]
data: none
]
port: open usb://vid-pid1/serialnum1
port/select-pipo: func [port [port!]][
port/state/rpipo: 2
port/state/wpipo: 3
port/state/trasfer: 'Interrupt
]
Notes: 端口1为read端口,端口2为write端口,中断传输
等价为: hid://vid-pid1/serialnum1/in=01&out=02
port!信息和上面的类似
port: open hid://vid-pid1/serialnum1
port/select-pipo: func [port [port!]][
//parse report descriptors (port/state/info)
port/state/rpipo: rpipo
port/state/wpipo: wpipo
port/state/trasfer: 'Interrupt
]