problema di timeout?
parent
e5bed926b5
commit
6a953cfcdc
|
|
@ -86,7 +86,8 @@ function s7node_from_plc(plc) {
|
|||
host: plc.ip,
|
||||
port: plc.port,
|
||||
rack: plc.rack,
|
||||
slot: plc.slot
|
||||
slot: plc.slot,
|
||||
timeout: 10000
|
||||
};
|
||||
let nuovo = new NodeS7({
|
||||
silent: false,
|
||||
|
|
@ -147,7 +148,8 @@ function s7_read_write_loop(ip, obj) {
|
|||
s7write_lock[ip] = true;
|
||||
let item = q.shift();
|
||||
if (item.action == "write") {
|
||||
obj.writeItems(item.variable, item.value, (e) => {
|
||||
let timeout_id = null;
|
||||
let callback = (e) => {
|
||||
if (e) {
|
||||
// questa scrittura è fallita
|
||||
item.reject(e);
|
||||
|
|
@ -155,13 +157,19 @@ function s7_read_write_loop(ip, obj) {
|
|||
// questa scrittura è riuscita
|
||||
item.resolve();
|
||||
}
|
||||
try {
|
||||
clearTimeout(timeout_id);
|
||||
} catch (e) { }
|
||||
s7write_lock[ip] = false;
|
||||
s7_read_write_loop(ip, obj);
|
||||
})
|
||||
};
|
||||
timeout_id = setTimeout(() => callback('timeout error'), 60000);
|
||||
obj.writeItems(item.variable, item.value, callback)
|
||||
} else if (item.action == "read") {
|
||||
obj.removeItems(undefined); // questo elimina tutte
|
||||
obj.addItems(item.variable);
|
||||
obj.readAllItems((anyBadQualities, dataObject) => {
|
||||
let timeout_id = null;
|
||||
let callback = (anyBadQualities, dataObject) => {
|
||||
if (anyBadQualities) {
|
||||
console.error("Can't read variables (" + ip + "): bad qualities", anyBadQualities)
|
||||
item.reject(anyBadQualities);
|
||||
|
|
@ -169,9 +177,14 @@ function s7_read_write_loop(ip, obj) {
|
|||
// console.log("letti", dataObject);
|
||||
item.resolve(dataObject[item.variable]);
|
||||
}
|
||||
try {
|
||||
clearTimeout(timeout_id);
|
||||
} catch (e) { }
|
||||
s7write_lock[ip] = false;
|
||||
s7_read_write_loop(ip, obj);
|
||||
})
|
||||
};
|
||||
timeout_id = setTimeout(() => callback('timeout error', null), 60000);
|
||||
obj.readAllItems(callback)
|
||||
}
|
||||
} else {
|
||||
// è già lockato o vuoto
|
||||
|
|
|
|||
Loading…
Reference in New Issue