require('mbus')
Include library before calling mbus functions
mbus.init(port, baud [, duplex])
Sets serial port and baud rate to use for all other mbus functions, must be called before any other mbus functions
Parameters:
port
serial port to use (for example, "/dev/RS232" or "/dev/ttyUSB0")baud
serial baud rate(for example, 2400)duplex
serial port duplex mode, set to "half" for RS-485 (default is "full")mbus.scan([min [, max [, retries]]])
Scans given primary address range, returns table with found devices
Parameters:
min
min scan address, defaults to 0max
max scan address, defaults to 250retries
number of extra ping retries for each device, defaults to 0mbus.getdata(addr [, frames])
Gets all data from the device with the given primary address. Returns table on success, nil plus error message on failure
Parameters:
addr
primary device addressframes
maximum number of frames that the device can reply with, defaults to 1mbus.writeaddr(old, new)
Sets new primary address. Returns true on success, nil plus error message on failure
Parameters:
old
old (current) primary addressnew
new primary addressmbus.writevif4(addr, vif, value)
Changes VIF to the given 4-byte integer value for the given primary address. Returns true on success, nil plus error message on failure
Parameters:
addr
primary device addressvif
VIF field id, usually 0x13 for counter valuevalue
4-byte valuembus.lasterror()
(Starting from v20170616) Returns a string containing the last error that occured during some mbus function calls