// 1. 장치 연결 async function connectKeypad() { try { const devices = await navigator.hid.requestDevice({ filters: [{ vendorId: 0xXXXX }] // 해당 키패드의 Vendor ID 기입 }); const device = devices[0]; await device.open(); return device; } catch (e) { console.error(“연결 실패:”, e); } } // 2. 패킷 전송 (C++의 writePacket 대체) async function sendCommand(device, packetData) { // packetData는 [0x03, 0xFD, …] 형태의 Uint8Array await device.sendReport(0x00, packetData); } // 3. 데이터 수신 device.addEventListener(‘inputreport’, event => { const { data, reportId } = event; // C++의 importDevicePacket 로직을 여기서 처리 console.log(“받은 패킷:”, new Uint8Array(data.buffer)); });