+/**
+ * Read data from interface into buffer blocking until @a lines number of \\r chars
+ * received.
+ * @param serial Previously initialized serial port structure.
+ * @param[in] lines Number of \\r-terminated lines to read (1-n).
+ * @param buf Buffer for result. Contents is NUL-terminated on success.
+ * @param[in] buflen Buffer length (>0).
+ * @retval SR_OK Lines received and ending with "OK\r" (success).
+ * @retval SR_ERR Error.
+ * @retval SR_ERR_ARG Invalid argument.
+ */
+SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char* buf, int buflen)
+{
+ int l_recv = 0;
+ int bufpos = 0;
+ int retc;
+
+ if (!serial || (lines <= 0) || !buf || (buflen <= 0))
+ return SR_ERR_ARG;
+
+ while ((l_recv < lines) && (bufpos < (buflen + 1))) {
+ retc = serial_read_blocking(serial, &buf[bufpos], 1);
+ if (retc != 1)
+ return SR_ERR;
+ if (buf[bufpos] == '\r')
+ l_recv++;
+ bufpos++;
+ }
+ buf[bufpos] = '\0';
+
+ if ((l_recv == lines) && (g_str_has_suffix(buf, "OK\r")))
+ return SR_OK;
+ else
+ return SR_ERR;
+}
+
+/** Interpret result of GETD command. */
+SR_PRIV int hcs_parse_volt_curr_mode(struct sr_dev_inst *sdi, char **tokens)