2410_LSS100100/LSS100200_SW_03.0

Modbus Master Functions

Functions listed below can be used for Modbus RTU master or Modbus TCP client.


	mb:setslave(slaveid)

sets extension id to read/write data from/to


	mb:readcoils(start, count) [01]

start – address of first coil to read

count – number of coils to read


	mb:readdiscreteinputs(start, count) [02]

start – address of first discrete input to read

count – number of discrete inputs to read


	mb:readregisters(start, count) [03]

start – address of first holding register to read

count – number of holding registers to read


	mb:readinputregisters(start, count) [04]

start – address of input register to read

count – number of input registers to read

returns all values on success and nil, error description on error


	mb:writebits(start, v1, [v2, [v3, ...]]) [05]

writes values to coils from start address


	mb:writeregisters(start, v1, [v2, [v3, ...]]) [06]

writes values to registers/coils from the start address

single write will be used when only one value is supplied, multiple write otherwise

returns all of values written on success and nil, error description on error


	mb:reportslaveid()

reads extension internal data

returns values on success

returns nil, error description on error


Modbus extension functions

Receive data from master

	mb:receive()

receives data from master with 1-minute timeout

returns data as a binary string on success

returns nil, error description on error


Set modbus mapping of extension device

	mb:setmapping(coils, inputs, holding_regs, input_regs)

creates memory mapping for the registers with size specified for each type


Handle extension

	mb:handleslave()

waits for an incoming indication from master and sends a reply when necessary


Get functions

	mb:getcoils(start, count)
	mb:getdiscreteinputs(start, count)
	mb:getinputregisters(start, count)
	mb:getregisters(start, count)

gets one or many register/coil/input values from mapping from the start address

returns all values on success

returns nil, error description on error, exception code if applicable


Set functions

	mb:setcoils(start, v1, [v2, [v3, ...]])
	mb:setdiscreteinputs(start, v1, [v2, [v3, ...]])
	mb:setinputregisters(start, v1, [v2, [v3, ...]])
	mb:setregisters(start, v1, [v2, [v3, ...]])

sets value to register/coil mapping from the start address

returns true on success

returns nil, error description on error, exception code if applicable


Callback functions

	mb:setwritecoilcb(fn)
	mb:setwriteregistercb(fn)

sets a callback function for coil/register write event

callback should accept two parameters - coil/register address and value (boolean or number)

for multiple writes callback is executed for each coil/register separately

use nil to remove a callback.

QR Code is a registered trademark of DENSO WAVE INCORPORATED in Japan and other countries.

Was this helpful?