index.html:35 Failed to open input0: PhidgetError: Open timed out
Posted: Mon Jun 17, 2024 4:06 am
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...
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>