| | |
| | | getDataAcquisitionDevice() { |
| | | (async () => { |
| | | try { |
| | | // 检查是否支持 Web Serial API |
| | | if ('serial' in navigator) { |
| | | // 请求可用串口 |
| | | const ports = await navigator.serial.getPorts(); |
| | | if (ports.length > 0) { |
| | | await connect(); |
| | | // 检查页面中检测项是否包含密度 |
| | | const hasDensityItem = this.currentSample.insProduct.some(item => { |
| | | // 假设密度相关的检测项名称包含 "密度" 关键字,可按需修改 |
| | | return item.inspectionItem && item.inspectionItem.includes('密度'); |
| | | }); |
| | | if (hasDensityItem) { |
| | | // 检查是否支持 Web Serial API |
| | | if ('serial' in navigator) { |
| | | // 请求可用串口 |
| | | const ports = await navigator.serial.getPorts(); |
| | | if (ports.length > 0) { |
| | | await connect(); |
| | | } else { |
| | | console.log('没有可用的串口'); |
| | | } |
| | | } else { |
| | | console.log('没有可用的串口'); |
| | | console.log('当前浏览器不支持 Web Serial API'); |
| | | } |
| | | } else { |
| | | console.log('当前浏览器不支持 Web Serial API'); |
| | | } |
| | | } catch (error) { |
| | | console.error('检测串口时出错:', error); |