lib/serial/globaldeviceloader.js
function(callback) {
    globalSerialDeviceLoader.lookup(function(err) {
      if (err && !err.name) {
        err = new Error(err);
      }
      if (err && callback) { return callback(err); }

      async.forEach(subscribers, function(s, callback) {
        if (s && s.oldDevices.length !== s.newDevices.length) {
          var devs = [];
          if (s.oldDevices.length > s.newDevices.length) {
            devs = _.difference(s.oldDevices, s.newDevices);
            _.each(devs, function(d) {
              if (s.log) s.log('unplug device with id ' + device.id);
              if (d.close) {
                d.close();
              }
              s.emit('unplug', d);
            });
          } else {
            devs = _.difference(s.newDevices, s.oldDevices);
            _.each(devs, function(d) {
              if (s.log) s.log('plug device with id ' + device.id);
              s.emit('plug', d);
            });
          }

          s.oldDevices = s.newDevices;
        }

        callback(null);
      }, function(err) {
        if (err && !err.name) {
          err = new Error(err);
        }
        if (callback) { return callback(err); }
      });

    });
  }
function(callback) {
    globalSerialDeviceLoader.lookup(function(err) {
      if (err && !err.name) {
        err = new Error(err);
      }
      if (err && callback) { return callback(err); }

      async.forEach(subscribers, function(s, callback) {
        if (s && s.oldDevices.length !== s.newDevices.length) {
          var devs = [];
          if (s.oldDevices.length > s.newDevices.length) {
            devs = _.difference(s.oldDevices, s.newDevices);
            _.each(devs, function(d) {
              if (s.log) s.log('unplug device with id ' + device.id);
              if (d.close) {
                d.close();
              }
              s.emit('unplug', d);
            });
          } else {
            devs = _.difference(s.newDevices, s.oldDevices);
            _.each(devs, function(d) {
              if (s.log) s.log('plug device with id ' + device.id);
              s.emit('plug', d);
            });
          }

          s.oldDevices = s.newDevices;
        }

        callback(null);
      }, function(err) {
        if (err && !err.name) {
          err = new Error(err);
        }
        if (callback) { return callback(err); }
      });

    });
  }
function ( callback ) { globalSerialDeviceLoader . lookup ( function ( err ) { if ( err && ! err . name ) { err = new Error ( err ) ; } if ( err && callback ) { return callback ( err ) ; } async . forEach ( subscribers , function ( s , callback ) { if ( s && s . oldDevices . length !== s . newDevices . length ) { var devs = [ ] ; if ( s . oldDevices . length > s . newDevices . length ) { devs = _ . difference ( s . oldDevices , s . newDevices ) ; _ . each ( devs , function ( d ) { if ( s . log ) s . log ( 'unplug device with id ' + device . id ) ; if ( d . close ) { d . close ( ) ; } s . emit ( 'unplug' , d ) ; } ) ; } else { devs = _ . difference ( s . newDevices , s . oldDevices ) ; _ . each ( devs , function ( d ) { if ( s . log ) s . log ( 'plug device with id ' + device . id ) ; s . emit ( 'plug' , d ) ; } ) ; } s . oldDevices = s . newDevices ; } callback ( null ) ; } , function ( err ) { if ( err && ! err . name ) { err = new Error ( err ) ; } if ( callback ) { return callback ( err ) ; } } ) ; } ) ; }
Calls lookup function with optional callback
and emits 'plug' for new attached devices
and 'unplug' for removed devices.
@param  {Function} callback The function, that will be called when finished triggering. [optional]
`function(err){}`
Calls lookup function with optional callback and emits plug for new attached devices and unplug for removed devices .