bobvanderlinden / node-machinetalk

A client-side Node API for remotely controlling/monitoring Machinekit instances through Machinetalk
GNU Lesser General Public License v3.0
2 stars 4 forks source link

Minimal example has too much code #8

Open bobvanderlinden opened 8 years ago

bobvanderlinden commented 8 years ago

At the moment only low-level clients are available. This results in waiting for a specific service in the MachineTalkBrowser, connecting with the client that fits the specific service and subscribing to a particular topic. This makes the examples somewhat large. That can be simplified.

A client that incorporates waiting for a specific machine in the browser, wait for the required services to come up and create the appropriate clients fro those services in the same machine.

Rudimentary proposal:

// Define what machine we are interested in and which services we want to use.
var machine = new MachineClient(['status.motion','command']);
machine.status.on('motion', function(motionStatus) {
    ...
});
machine.on('connect', function() {
    // The machine with ID was discovered and connected.
    machine.command.emcAxisHome(0);
});

var browser = new MachineTalkBrowser();
machine.discoverConnect(browser, 'ID');
browser.start();
// or
machine.connect({
    status: 'tcp://debian.local:1234',
    command: 'tcp://debian.local:1235'
});