index.html:35 Failed to open input0: PhidgetError: Open timed out

Supporting Browser-based Javascript and Node.js
Post Reply
alistair.monaghan
Phidgetsian
Posts: 11
Joined: Tue Mar 05, 2019 3:36 am
Contact:

index.html:35 Failed to open input0: PhidgetError: Open timed out

Post by alistair.monaghan »

Hi there - I'm using a Phidget Interfacekit 8/8/8 - some light sensors on channels 0 and 1 in Digital inputs and two red lights on Digital outputs on channels 0 and 1. I'm trying to play an audio file and flash a light when the light sensor is triggered. I'm getting a consistent error on multiple machines and I'm stumped - any help would be appreciated.

Failed to open input0: PhidgetError: Open timed out

Here is my code...

Code: Select all

<!DOCTYPE html>
<html>
<head>
    <title>Phidget Control</title>
    <script src="js/phidget22.js"></script>
</head>
<body>

<audio id="audio" src="audio/store-scanner-beep-90395.mp3"></audio>

<script>
    window.onload = function () {
        // Initialize the Phidget22 library
        phidget22 = window.phidget22;

        //phidget22.setLogLevel(phidget22.LogLevel.PHIDGET_LOG_INFO);

        // Create Phidget22 DigitalInput and DigitalOutput objects
        var input0 = new phidget22.DigitalInput();
        var output0 = new phidget22.DigitalOutput();

        // Set the channels for the inputs and outputs
        input0.setChannel(0);
        output0.setChannel(0);

        // Set device serial number if needed (otherwise, omit this line)
        input0.setDeviceSerialNumber(677653);
        output0.setDeviceSerialNumber(677653);

        // Open the connections
        console.log("Opening DigitalInput 0...");
        input0.open(10000).then(function () {
            console.log("DigitalInput 0 opened successfully");
        }).catch(function (err) {
            console.error('Failed to open input0: ', err);
        });

        console.log("Opening DigitalOutput 0...");
        output0.open(10000).then(function () {
            console.log("DigitalOutput 0 opened successfully");
        }).catch(function (err) {
            console.error('Failed to open output0: ', err);
        });

        // Add a state change handler to input0
        input0.onStateChange = function (state) {
            if (state) {
                // Play the audio file
                document.getElementById('audio').play();

                // Flash the light
                flashLight(output0);
            }
        };

        // Function to flash the light
        function flashLight(output) {
            output.setState(true); // Turn on the light
            setTimeout(function () {
                output.setState(false); // Turn off the light after 500ms
            }, 500);
        }
    };
</script>

</body>
</html>
User avatar
Patrick
Lead Developer
Posts: 623
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: index.html:35 Failed to open input0: PhidgetError: Open timed out

Post by Patrick »

Do you have the network server running? Can you open the Phidget remotely from the control panel?

-Patrick
alistair.monaghan
Phidgetsian
Posts: 11
Joined: Tue Mar 05, 2019 3:36 am
Contact:

Re: index.html:35 Failed to open input0: PhidgetError: Open timed out

Post by alistair.monaghan »

I managed to sort this out...I think it was an underpowered USB port, thanks for replying though.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests