|
|
@@ -0,0 +1,41 @@
|
|
|
+// import { getDeviceList } from 'usb';
|
|
|
+const { WebUSB } = require('usb')
|
|
|
+// const devices = getDeviceList();
|
|
|
+// console.log(666,devices);
|
|
|
+const customWebUSB = new WebUSB({
|
|
|
+ // Bypass checking for authorised devices
|
|
|
+ allowAllDevices: true
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+customWebUSB.getDevices().then(res => {
|
|
|
+ for (const device of res) {
|
|
|
+ if (device.productName.includes('G923')) {
|
|
|
+ device.open()
|
|
|
+ // console.log(1,device);
|
|
|
+
|
|
|
+ // device.selectConfiguration(1).then(red=>{
|
|
|
+ // console.log(5,red);
|
|
|
+ // })
|
|
|
+
|
|
|
+ const interface = device.device.interfaces[2];
|
|
|
+ interface.claim();
|
|
|
+
|
|
|
+ console.log(2,interface);
|
|
|
+ // console.log(6, interface); // WebUSB device
|
|
|
+ const endpointIn = interface.endpoints.find((ep) => ep.direction === 'in');
|
|
|
+ endpointIn.on('data', (data) => {
|
|
|
+ console.log('Received data:', data);
|
|
|
+ });
|
|
|
+
|
|
|
+ endpointIn.on('error', (err) => {
|
|
|
+ console.error('USB endpoint error:', err);
|
|
|
+ device.close()
|
|
|
+ });
|
|
|
+ console.log(3,endpointIn.startPoll);
|
|
|
+ endpointIn.startPoll(500); // 调整间隔时间以适应设备通信速率
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+
|