<< modbus_writeBits modbus modbus_writeRegs >>

modbus >> modbus > modbus_writeReg

modbus_writeReg

write many bits

Calling Sequence

res = modbus_writeReg(mbc, addr, data)
[res, ierr] = modbus_writeReg(mbc, addr, data)

Arguments

mbc

The Modbus connection created with modbus_newTcp or modbus_newRtu.

addr

The address on device where bits should be write from.

data

Double scalar to write considered as unsigned short.

res

The number of written bits. -1 if an error occured

ierr

Erreur number.

Description

This function writes the status of holding registers from data at the address addr of the remote device

The function uses the Modbus function code 0x10 (preset multiple registers).

When called with one output argument, a Scilab error will occur when the writing fails. When called with two output arguments, no Scilab error will occur but ierr will contain the internal modbus error number.

Examples

mbc = modbus_newTcp("127.0.0.1", 502);
modbus_connect(mbc);
data = 0;
res = modbus_writeReg(mbc, 0, data);
rData = modbus_readReg(mbc, 0, res)
data == rData
modbus_close(mbc)
modbus_free(mbc)

Report an issue
<< modbus_writeBits modbus modbus_writeRegs >>