/*
send command to GPSd and wait for response
350650
private <T extends IGPSObject> T syncCommand(final String command, final Class<T> responseClass) throws IOException {
		synchronized (this.asyncMutex) {
			if (out != null) {
				this.out.write(command + "\n");
				this.out.flush();
			}
			if (responseClass == WatchObject.class) {
				lastWatch = command;
			}
			while (true) {
				// wait for awaited message
				// FIXME possible infinite loop if expected result arrives but new result overrides expected result before getting to this point.
				final IGPSObject result = this.waitForResult();
				if ((result == null) || result.getClass().equals(responseClass)) {
					return responseClass.cast(result);
				}
			}
		}
	}
688547
def _sendDDEcommand(self, cmd, timeout=None):
        """"""
        reply = self.conversation.Request(cmd, timeout)
        if self.pyver > 2:
            reply = reply.decode('ascii').rstrip()
        return reply
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
749912
function (zaproxy, statusFn, callback) {
    var wait = function () {
      statusFn(function (err, body) {
        if (err) {
          callback(err);
          return;
        }
        if (body.status < 100) {
          grunt.log.write('.');
          setTimeout(function () {
            wait(callback);
          }, 1000);
        } else {
          callback(null, body);
        }
      });
    };
    wait();
  }
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());
			});
		}
	}
756
def _sendStatCmd(self,  cmd):
        
        try:
            self._conn.write("%s\r\n" % cmd)
            regex = re.compile('^(END|ERROR)\r\n', re.MULTILINE)
            (idx, mobj, text) = self._conn.expect([regex,], self._timeout) #@UnusedVariable
        except:
            raise Exception("Communication with %s failed" % self._instanceName)
        if mobj is not None:
            if mobj.group(1) == 'END':
                return text.splitlines()[:-1]
            elif mobj.group(1) == 'ERROR':
                raise Exception("Protocol error in communication with %s."
                                % self._instanceName)
        else:
            raise Exception("Connection with %s timed out." % self._instanceName)
1303790
function reply(req, res, timeout) {
  var _timer;

  if(timeout) {
    //console.dir(timeout);
    //console.error(Date.now());
    _timer = setTimeout(this.onTimeout, timeout);
    this._busy = true;
  }

  function onClose(code, signal) {
    //console.dir('close called: ' + signal);
    //console.dir(code);
    //console.dir(signal);
    this.ps.removeAllListeners();
    clearTimeout(_timer);
    this.ps = null;
    this._busy = false;
    this._written = false;
    var msg, err = new StoreError(
      null, 'script execution process exited with code: %s', code || 0);
    if(signal === 'SIGQUIT') {
      msg = 'error running script (call to %s): '
      msg += '@user_script: script killed by user with SCRIPT KILL';
      err = new StoreError(null, msg, this._script || 'user_script');
    }
    res.send(err);
  }

  function onMessage(msg) {
    var cmd, args;

    //console.dir(msg);

    // getting the current script name
    if(msg.event === 'eval') {
      this._script = msg.data;
      return;

    // calling out to execute a command
    }else if(msg.event === 'call') {
      req.cmd = msg.cmd;
      req.args = msg.args;

      //console.dir('got call event');

      var exec = this._commands[req.cmd];
      if(exec && exec.definition && exec.definition.write) {
        this._written = true;
        //console.dir('marking command as writing data...');
      }

      function onCommand(err, reply) {
        // restore req and res
        req.cmd = cmd;
        req.args = args;
        req.script = false;
        delete res.cb;

        var data = err ? err.message : reply;
        if(reply instanceof Buffer) reply = reply.toString();
        this.ps.send(
          {event: msg.event, err: (err instanceof Error), data: data});
      }

      req.script = true;

      res.cb = onCommand.bind(this);
      this.emit('command', req, res);
      //this.ps.once('message', onMessage.bind(this));
      return;
    }

    // ps may be null if script was killed
    if(this.ps) {
      this.ps.removeAllListeners();
    }

    clearTimeout(_timer);

    // sending data back to the client
    this._busy = false;
    this._written = false;
    var data = msg.data;
    if(msg.err) return res.send(new Error(data));
    if(msg.str) data = new String(data);
    return res.send(null, data);
  }

  this.ps.on('message', onMessage.bind(this));
  this.ps.once('close', onClose.bind(this));
}
721198
function(src, dest){
      if(fs.existsSync(dest)){
        this.waitForResponse(src, dest); 
      }else{
        this.copy(src, dest); 
        this.triggerNext(); 
      }
    }
1311968
function BatchResponseCB (data) {
    switch (data.status ) {
        case -1: console.log (" SMS -%d- Fail to Send SMS", data.smsid);
            break;
        case -2: console.log (" SMS -%d- Timeout waiting acknowledgement", data.smsid);
            break;
        case 1: console.log (" SMS -%d- Message Sent", data.smsid);
            break;
        case 2: console.log (" SMS -%d- Acknowledgement=[%s]", data.smsid, data.msg.ack);
            break;
        default:
    }
    // quit except if we wait for ack [leave some time to DB to close operation]
    if (data.status === 0) {
        console.log ('Last SMS from batch processed');
        setTimeout(process.exit, 1000);
    }
}
1083826
async def send_command(self, command):
        """"""
        _LOGGER.debug("Sending command to projector %s", command)
        if self.__checkLock():
            return False
        self.__setLock(command)
        response = await self.send_request(
            timeout=self.__get_timeout(command),
            params=EPSON_KEY_COMMANDS[command],
            type='directsend',
            command=command)
        return response
1004187
function waitForString(page, ph, str, callback) {
    var elapsed = 0;
    var currentDom = '';
    var timeout = false;

    async.until(
        function () {
            timeout = elapsed > constants.WAIT_TIMEOUT;
            return currentDom.indexOf(str) > -1 || timeout;
        },

        function (callback) {
            setTimeout(function () {
                getData.takeSnapshot(page, ph, function (error, page, ph, dom) {
                    if (error) {
                        callback(error);
                        return;
                    }
                    currentDom = dom;
                    elapsed += constants.POLL_INTERVAL;
                    callback();
                })
            }, constants.POLL_INTERVAL);
        },

        function (error) {
            if (error) {
                callback(error, page, ph);
                return;
            }
            if (timeout) {
                callback('Timeout while waiting for string', page, ph);
                return;
            }
            callback(null, page, ph);
        }
    );
}
215603
function(callback){
      var msg = ubeacon.getCommandString( false, ubeacon.uartCmd.led, new Buffer('03','hex') , false );
      ubeacon.sendMeshRemoteManagementMessage( program.destinationAddress, msg.toString(), null);
      setTimeout(callback, 2000);
    }
56755
function runCommand(output, cache, cmdIndex) {
				var cmd = batch.commands[cmdIndex];
				if (cmd) {
					if (cacheContent.length !== 0 && isCachedCommand(cmd)) {
						logger.warning
							.data({ cmd: cmd.cmdName })
							.log('Re-sending cached command response');

						output += (output ? ',' : '[') + cacheContent.shift();
						return setImmediate(runCommand, output, cache, cmdIndex + 1);
					}

					return that.executeCommand(cmd, session, metaData, function (error, response) {
						if (error) {
							// should never happen
							return cb(error);
						}

						if (headerEvents && headerEvents.length) {
							response.myEvents = response.myEvents || [];
							response.myEvents = headerEvents.concat(response.myEvents);
							headerEvents = null;
						}

						const serializedResponse = serializeCommandResult(response);
						output += (output ? ',' : '[') + serializedResponse;

						if (isCachedCommand(cmd)) {
							cache += (cache ? ',' : '[') + JSON.stringify(serializedResponse);
						}

						setImmediate(runCommand, output, cache, cmdIndex + 1);
					});
				}

				// close the output JSON array

				output += ']';

				if (cache === '') {
					cache = '[]';
				} else {
					cache += ']';
				}

				// turn results array into a reportable response (possibly gzipped)

				var options = {
					mimetype: CONTENT_TYPE_JSON
				};

				if (!shouldCompress(output, acceptedEncodings)) {
					return respond(options, output, cache);
				}

				return compress(output, function (error, compressed) {
					if (error) {
						// error during compression, send the original
						respond(options, output, cache);
					} else {
						options.encoding = 'gzip';

						respond(options, compressed, cache);
					}
				});
			}
1366781
def send(self, cmd, timeout, wait_for_string, password):
        """"""
        return self.target_device.send(cmd, timeout=timeout, wait_for_string=wait_for_string, password=password)
1318818
def send_wait(self,text):
	""""""
	self.send(text)
	time.sleep(len(text)*PiLite.COLS_PER_CHAR*self.speed/1000.0)
1326600
function waitForStartup(err, pid) {
        if (err) {
            throw new Error('Couldn\'t start ' + bin);
        }

        if (pid || child.exitCode !== null) {
            child.emit('started');
        } else {
            setTimeout(function () {
                pidof(bin, waitForStartup);
            }, 100);
        }
    }
586121
function sendCommand(command, mac, params, callback, scope) {

        var commandParts = [];
        // check for callback instead of params
        if (typeof params == 'function') {
            callback = params;
            params = '';
            scope = callback;
        }

        var completeCommand = '';

        completeCommand += command.request;
        commandParts.push(command.request);
        if (mac) {
            commandParts.push(mac);
            completeCommand += mac;
        }

        if (params) {
            commandParts.push(params);
            completeCommand += params;
        }

        var crcChecksum = crc.crc16(completeCommand).toString(16).toUpperCase();

        if (crcChecksum.length < 2) {
            crcChecksum = "000" + crcChecksum;
        }
        else if (crcChecksum.length < 3) {
            crcChecksum = "00" + crcChecksum;
        }
        else if (crcChecksum.length < 4) {
            crcChecksum = "0" + crcChecksum;
        }

        commandParts.push(crcChecksum);
        completeCommand = protocolCommands.frames.start + commandParts.join("") + protocolCommands.frames.end;

        commandStack.push({mac: mac,command: command, ack:'', callback: callback, scope: scope});

        if (options.log > 0) {
            console.log('---');
            console.log(command.color + "SEND " , command.name + ":\t" +  commandParts.join("\t") + colors.reset); 
        }

        sp.write(completeCommand);

        // we use a counter to know how many ack we are up in compared to commands
        ackCounter -= 1;

        return completeCommand;
    }