simple helper function to send a command and wait for a response
544001
function sendCommand(sensor, cmd, callback)
{
    // commands need to be terminated with a carriage return
    cmd += "\r";
    sensor.writeDataStr(cmd);

    // wait up to 1 second
    if (sensor.dataAvailable(1000))
    {
	console.log("Returned: " + sensor.readDataStr(1024));
    }
    else
	console.log("Timed out waiting for response");

    if (callback)
	callback();
}
1070107
def send(self, command, sender, target, args, kwargs):
        
        command = get_command(command)
        data = {'command': command.__name__,
                'id': create_aid(),
                'sender': actor_identity(sender),
                'target': actor_identity(target),
                'args': args if args is not None else (),
                'kwargs': kwargs if kwargs is not None else {}}

        waiter = self._loop.create_future()
        ack = None
        if command.ack:
            ack = create_aid()
            data['ack'] = ack
            self.pending_responses[ack] = waiter

        try:
            self.write(data)
        except Exception as exc:
            waiter.set_exception(exc)
            if ack:
                self.pending_responses.pop(ack, None)
        else:
            if not ack:
                waiter.set_result(None)
        return waiter
1277865
function _send(cmd, callback) {
      cmd_callback = callback;
      if(connected) {
        client.write(cmd + '\n');
      } else {
        connect();
      }
    }
1063102
def send_command(self, cmd, priority=False):
        
        if priority:
            self._pending.insert(0, cmd)
        else:
            self._pending.append(cmd)
        self._pending_size += len(cmd)

        if self._pending_size > DEFAULT_PENDING_SIZE:
            yield self._flush_pending()
407260
def send_all wait = true
      cmd_envia

      if wait
        wait_for last_label
        return false if @response_cmd.eql? 'NOOK'
        return "#{@response_args[0]}.#{@response_args[1]}".to_f
      end
    end
772897
def send(self, cmd):
        
        self._bridge.send(cmd, wait=self.wait, reps=self.reps)
20413
def send_simple_command(self, cmd):
        """"""
        pkt = MqttPkt()
        
        pkt.command = cmd
        pkt.remaining_length = 0
        
        ret = pkt.alloc()
        if ret != NC.ERR_SUCCESS:
            return ret
        
        return self.packet_queue(pkt)
633544
def wait(self, timeout):
        ''''''
        logger.debug('Waiting for %fs', timeout)
        return self._event.wait(timeout)
1098656
function() {
		if(!_self.waitingForResponse && _self.queue.length) {
			_self.waitingForResponse = true;
			var cmd = _self.queue.shift();

			if(_self.conn) {
				_self.conn.removeAllListeners('data');
				_self.conn.addListener('data', function(data) {
					Debug.log('response:');
					Debug.log(data);
					cmd.responseHandler.call(cmd, data);
				});
			}
			Debug.log('request:');
			Debug.log(cmd.command());
			process.nextTick(function() {
				_self.conn.write(cmd.command());
			});
		}
	}
734429
function responseHandler (res, next) {
  return function (err, message) {
    if (err || !message) {
      next(err);
    } else {
      res.send(message);
    }
  }
}
674221
function sendCommand(js,cb){
    if(!js) return stream.log('send command got no command!',js);
    var id = ++stream.inc;
    if(!js.id) js.id = 0;// default input id.

    var start = Date.now();
    var timeCallback = function(err,js){
      js.basetime = Date.now()-start;// decorate performance time.
      if(cb) cb(err,js)
    }

    if(js.timeout == undefined) js.timeout = 10000;
    else if(js.timeout < 0) {
      js.timeout = 60000;// 60 seconds max timeout
    } else if(js.timeout > 60000){
      js.timeout = 60000; 
    }
    
    var timeout = js.timeout;
    setTimeout(function(){
      if(stream.callbacks[id]) {
        // make reply js
        js.type = "reply";
        js.err = "base timeout in "+timeout+" ms";
        js.timeout = timeout;
        js.timeerror = true;
        js.from = js.to;
        delete js.to;
        timeCallback(true,js);
      }
    },timeout);

    stream.callbacks[id] = {id:js.id,cb:timeCallback};
    js.id = id;

    if(stream.inc > maxId) stream.inc = 1;

    js.type = "command";
    toBoard.write(js);
  
    return js;
  }
917849
function execute(cmd, args, cb) {
  if(typeof args === 'function') {
    cb = args;
    args = null;
  }
  var arr = [cmd].concat(args || []);
  if(typeof cb === 'function') {
    this.once('reply', cb);
  }

  // sending over tcp
  if(this.tcp) {
    this.encoder.write(arr);
  // connected to a server within this process
  }else{
    this.socket.write(arr);
  }
}
599624
function echoRequest(body, reply) {
  console.log("agent receive: echo,   " + JS(body))
  console.log("agent reply:   echo,   " + JS(body))
  reply(null, body)

  console.log("agent emit:    echoed, " + JS(body))
  Agent.emit("echoed", body)
}
1268761
def send_command(self, data, read_delay=None):
        """"""
        self._write(data)
        if read_delay:
            time.sleep(read_delay)
        return self._read()
1063348
def wait_response(self):
        ''''''
        responses = self.read()
        while not responses:
            responses = self.read()
        return responses
701356
def send_command_return(self, command, *arguments):
        
        return self.api.send_command_return(self, command, *arguments)
233574
def fetch(self, command):
        
        logging.debug('SENT: %s: %s' % (self.host, command))
        self.write('%s\n' % command)
        while 1:
            buffer = self.read_until('\n').strip()
            if len(buffer):
                break
        status, length = map(int, buffer.split())
        content = ''
        assert status == 200, 'Bad response code: {status} {text} ({command})'.format(status=status, text=self.read_until('\n').strip(), command=command)
        while len(content) < length:
            content += self.read_until('\n')
        logging.debug('RECV: %s: %dB %s' % (status,length,content[:30]))
        self.read_eager()
        return (status, length), content