code: function sendCommand(sensor, cmd)
  {
      // commands need to be terminated with a carriage return
      cmd += "\r";
      sensor.writeDataStr(cmd);
  
      var resp = "";
      while (sensor.dataAvailable(2000))
      {
          resp += sensor.readDataStr(1024);
      }
  
      if (!resp) 
      {
          console.log("Timed out waiting for response");
      }
      else
      {
          resp = sensor.stringCR2LF(resp);
          console.log("Returned (" + resp.length + " bytes):");
          console.log(resp);
      }
  }
docs: simple helper function to send a command and wait for a response