change datarate via control panel network server or javascript didn't work

Comments & issues
Supporting Windows 8 or newer
mindthegap
Phidgetsian
Posts: 6
Joined: Mon Sep 11, 2017 6:46 am

change datarate via control panel network server or javascript didn't work

Post by mindthegap »

I tried changing the data rate on a PhidgetSBC4 to which two Phidget ENC1000 quadrature encoders are connected. It doesn't work on the network server, in the control panel, or via programming.
javascript: encoder.setDataInterval(datainterval)

Where can I set this? What's wrong?

I have to Encoder, one with 10ms, the other with 250ms, and I can't change it to the same value! It's all inside a vue component, works great, without the dataInterval...

onMounted(async () => {

if (store.state.config.init1 === true || store.state.config.init2 === true) {
const conn = new phidget22.NetworkConnection(8080, store.state.config.drehradip );
try {
await conn.connect();
} catch (err) {
console.error('Error during connect', err);
process.exit(1);
}
}

if (store.state.config.init1 === true) {
const encoder1 = new phidget22.Encoder();

encoder1.setHubPort(store.state.config.port1);
encoder1.setDataInterval(store.state.config.datainterval);


// eslint-disable-next-line no-unused-vars
encoder1.onPositionChange = (positionChange, timeChange, indexTriggered) => {

if (positionChange > 0) {
props.externalfunction1();
// store.state.drill1 = store.state.drill1 + positionChange / store.state.config.drehradteiler;
store.state.drill1 = ((store.state.drill1 * (store.state.config.drehraddamping - 1)) + positionChange / store.state.config.drehradteiler) / store.state.config.drehraddamping;
// console.log("drill1", store.state.drill1);
}
};

encoder1.onAttach = () => {
console.log('Attach!');
};

encoder1.onDetach = () => {
console.log('Detach!');
};

encoder1.onError = (code, description) => {
console.log('Description: ' + description.toString());
console.log('----------');
};

try {
await encoder1.open(5000);
} catch (err) {
console.error('Error during open', err);
process.exit(1);
}
}

if (store.state.config.init2 === true) {
const encoder2 = new phidget22.Encoder();

encoder2.setHubPort(store.state.config.port2);
encoder2.setDataInterval(store.state.config.datainterval);

// eslint-disable-next-line no-unused-vars
encoder2.onPositionChange = (positionChange, timeChange, indexTriggered) => {


if (positionChange > 0) {
props.externalfunction2();
store.state.drill2 = ((store.state.drill2 * (store.state.config.drehraddamping - 1)) + positionChange / store.state.config.drehradteiler) / store.state.config.drehraddamping;
}
};

encoder2.onAttach = () => {
console.log('Attach!');
};

encoder2.onDetach = () => {
console.log('Detach!');
};

encoder2.onError = (code, description) => {
console.log('Description: ' + description.toString());
console.log('----------');
};

try {
await encoder2.open(5000);
} catch (err) {
console.error('Error during open', err);
process.exit(1);
}
}
});
User avatar
Patrick
Lead Developer
Posts: 676
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary

Re: change datarate via control panel network server or javascript didn't work

Post by Patrick »

Hi,

The Data Interval needs to be set after open has completed, or from inside the attach event.

-Patrick
mindthegap
Phidgetsian
Posts: 6
Joined: Mon Sep 11, 2017 6:46 am

Re: change datarate via control panel network server or javascript didn't work

Post by mindthegap »

what should that look like?

And shouldn't I also be able to adjust it via the control panel?
User avatar
Patrick
Lead Developer
Posts: 676
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary

Re: change datarate via control panel network server or javascript didn't work

Post by Patrick »

Hi,

Move encoder1.setDataInterval(store.state.config.datainterval); into the encoder1.onAttach event, and the same for encoder2. Also, that's an async call, so you could await it and try catch to see if it's succeeding or failing.

Are you sure that you have 2x ENC1000_0?
ENC1000_0 supports a minimum data interval of 20ms, but ENC1001_0 supports a minimum 1ms data interval (or 3ms attached to the SBC3003). If you have one running at 10ms, it's not an ENC1000_0.

I don't have any issues setting data interval on encoders attached to an SBC from the control panel (both the JavaScript control panel, and the windows control panel).

-Patrick