2

DATECS DPP-250 POS プリンターがあり、WebUSB API を使用して接続し、データを印刷しようとしています。私が抱えている問題は、印刷が機能しないことです。デバイスに接続でき、Chrome は正常に読み取りますが、印刷 ( transferOut) を送信すると、プリンターがハングします。コンソールでエラーをデバッグしようとしましたが、エラーはまったくありません。MAC OS と WinUSB ドライバー (Windows でドライバーを変更するためにZadigを使用) を使用した Windows 10 で試してみましたが、すべて同じ問題があります。

誰かが問題がどこにあるか知っていますか?

編集:

他の POS プリンター (非 Bluetooth プリンター) で試してみましたが、コードは完全に機能します。このプリンターだけの問題です。このタイプのプリンターはマイクロ USB を使用するので、それが問題なのでしょうか?

これが私が使用しているコードです

<html>
<body>
    <textarea id="printContent"></textarea>
    <input type="submit" onclick="connectAndPrint()" value="Print"/>
    <P>Type text into box and click on submit button.
    <script>
    var device;

    function setup(device) {
        return device.open()
        .then(() => device.selectConfiguration(1))
        .then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber))
    }

    function print() {
        var string = document.getElementById("printContent").value + "\n";
        var encoder = new TextEncoder();
        var data = encoder.encode(string);
        console.log(data.length);
        device.transferOut(device.configuration.interfaces[0].alternate.endpoints[0].endpointNumber, data)
        .catch(error => { console.warn(error); })
    }

    function connectAndPrint() {
        console.log(device);
        if (device == null) {
            navigator.usb.requestDevice({ filters: [{ vendorId: 5380 }, { vendorId: 65520 }] })
            .then(selectedDevice => {
                device = selectedDevice;
                console.log(device.configuration);
                return setup(device);
            })
            .then(() => print())
            .catch(error => { console.log(error); })
        }
        else
            print();
    }

    navigator.usb.getDevices()
    .then(devices => {
        if (devices.length > 0) {
            device = devices[0];
            return setup(device);
        }
    })
    .catch(error => { console.log(error); });

    </script>
</body>
</html>
4

1 に答える 1