Module: drivers/gateways/modbus

This driver is a Modbus TCP master (client). Modbus addresses are numbered memory registers stored on the Modbus TCP slave (server). The master can read or write those registers. There is no notion of events with the Modbus protocol. Hence, the addresses can be cyclically read to detect changes. Note that this driver only implements the access to modbus holding registers. Modbus discrete outputs / coils, discrete inputs, and input registers is not yet supported.

Gateway parameters

The gateway parameters are defined in the gateway json (refer to core/gateways module)

{
	"id" : 1,
	"name"  : "modbus - modbus rtu 192.168.1.13", //here the modbus slave is a gateway from modbus rtu to modbus tcp slave.
	"description" : "...", 
	"activ" : 1,
	"driver": "modbus", //is linked to driver code (modbus.js) implementing the driver functions.
	"json"  : { 				// used to store driver parameters.
		"host":"192.168.1.13",  // hostname / ip address of the modbus TCP slave (server). 
		"port":502,				// port of the modbus TCP slave. 
		"unitId":1,				// Modbus unit id.
		"readLoopDelay":60000 	// here registered addresses are refreshed every minute.
	},
	"private_json" : {...} 		//can be used by anyone to store custom informations independent from the driver itself.
}


Address format

The format of the address is %M[register number]. e.g. %M100 designs the register number 100 of the slave device. The driver is used by the core/gateways module. Its methods should not be used directly by custom applications.

Address parameters

The main parameter is the data type, i.e. the way the number is encoded at the binary level. If the encoding requires more than 16 bits, then the address expands over multiple registers. e.g. address %M100 of type int32BE uses registers 100 to 101.

{
	id: 23080,	 //database id, 
	alias: ' ... ', // an unique alias can be used to access the address (instead of using the id 23056).
	name: '%M100',	// name/identifier of the address on the KNX bus. Here it is a physical address
	...
	json: {
		datatype: 'int16BE'  //integer stored over 16 bits in big endian order(the first bit of the register counting from the left is the stronger).
			// different possible binary encodings :
			// 'int16BE' 
			// 'int16BE'
			// 'int16LE'
			// 'uint16BE'
			// 'uint16LE'
			// 'int8'	  
			// 'uint8'	  
			// 'int32BE'
			// 'int32LE'
			// 'uint32BE'
			// 'uint32LE'
			// 'floatBE'
			// 'floatLE'
			// 'doubleBE'
			// 'doubleLE'
			// 'bcd8'		
			// 'bcd16BE' 
			// 'bcd16LE'
			// 'bcd32BE' 
			// 'bcd32LE'
			// 'bit'	
	}
}


Use cases


gateways.writeValue('%M100', 10, function(err){
	// writes 10 on register 100. If the slave does not accept the write, the error is returned.
}) 

gateways.readValue('%M100', function(err,value){
	// normalement value is 10 if the above writeValue succeed.
})

gateways.on('newValue %M100', function(newValue, newRawStringValue, date){ 
	// Fires when the register values changes. 
	// The registers are periodically read by the driver, in order to detect and emit changes.
})