Skip to content

Documentation #78

@Venerons

Description

@Venerons

Where can I find documentation on how to use this module? Other than the readme, it doesn't seem to exists any kind of documentation around.

I'm trying to create a modbus tcp server to create a simulator, but I'm struggling to understand how to use this module.

Some things I need:

  • what events can/should I listen on a server connection, other than close, error and read-coils?
  • how can I read the actual request? The request object is filled with properties but there is no documentation or example on how to actually use it. Thanks to the debug I can see that the server is receiving the messages from the client, but not all seems to be catched by the read-coils event, and in general I don't understand how am I supposed to use the request object to understand the request and customize the reply.

Following my very basic server so far:

// npm modules
const modbus = require('modbus-stream');

// kill logging
process.on('SIGINT', function () {
	console.error('Process killed by SIGINT');
	process.exit();
});

// exception logging
process.on('uncaughtException', function (error) {
	console.error('Uncaught Exception thrown', error);
	process.exit(1);
});

// env variables
const SERVER_PORT = process.env.SERVER_PORT || 502;

modbus.tcp.server({ debug: 'server' }, (connection) => {
	console.log('connected');
	connection.on('close', () => {
		console.log('close');
	});
	connection.on('error', () => {
		console.log('error');
	});
	connection.on('read-coils', (request, reply) => {
		console.log('read-coils');
		reply(null, [0, 0, 0, 0, 0]);
	});
}).listen(SERVER_PORT, () => {
	console.log(`Server listening on ${SERVER_PORT}`);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions