Yoctopuce Yocto-RS485-V2 Mode D'emploi page 135

Table des Matières

Publicité

}
}
console.log('Using device '
serialPort
= YSerialPort.FirstSerialPort();
rl
= readline.createInterface({
input: process.stdin,
output:
process.stdout
});
console.log('Please enter the MODBUS slave address
console.log('Slave:');
rl.on('line', handleInput);
}
async function handleInput(chunk) {
var
val
= parseInt(chunk);
switch (g_step) {
case 1:
if
(val
console.log("invalid slave
} else {
target.slave
g_step++;
console.log("Slave = "
console.log("Please select a Coil No (>=1), Input Bit No
console.log("
console.log("No:
}
break;
case 2:
if
(val
console.log("invalid register
} else {
target.reg
await printModbusValue(target.slave, target.reg);
g_step++;
console.log("Press ENTER to read again, Q to
if
}
}
break;
case 3:
if (chunk.charAt(0) ==
await YAPI.FreeAPI();
rl.close();
break;
}
if (chunk.charAt(0) !=
10000) {
if
val);
} else {
}
}
await printModbusValue(target.slave, target.reg);
console.log("Press R to read again, Q to
if
((target.reg
console.log(" or enter a new
}
console.log(":
break;
default:
console.log('data: '
}
}
async function printModbusValue(slave, reg) {
var val;
console.log("reg="
if
(reg
>= 40001) {
val
= (await serialPort.modbusReadRegisters(slave,
} else if
(reg
val
= (await serialPort.modbusReadInputRegisters(slave,
} else if
(reg
val
= (await serialPort.modbusReadInputBits(slave,
} else {
www.yoctopuce.com
+ serial);
<
1
||
val
> 255) {
= val;
+ target.slave);
Register No (>=30001) or Input Register No
");
<
1
||
val
>=
50000
= val;
((target.reg
% 30000) < 10000) {
console.log(" or enter a new
'q'
|| chunk.charAt(0) == 'Q') {
'r'
&& chunk.charAt(0) !=
(target.reg
>= 30001) {
await serialPort.modbusWriteRegister(target.slave,
await serialPort.modbusWriteBit(target.slave,
% 30000) < 10000) {
");
+ chunk);
+
reg
+
" slave="
>= 30001) {
>= 10001) {
16. Utilisation du Yocto-RS485-V2 en JavaScript / EcmaScript
(1...255)');
number");
||
(val
% 10000) == 0) {
number");
value:");
quit");
value");
+ slave);
reg
reg
(>=10001+),");
(>=40001)");
quit:");
'R'
&&
(target.reg
% 30000) <
target.reg
target.reg
- 1, val);
- 40001, 1))[0];
reg
- 30001, 1))[0];
- 10001, 1))[0];
- 30001,
127

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-rs232

Table des Matières