* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/** @file
+ * <em>Manson HCS-3xxx Series</em> power supply driver
+ * @internal
+ */
+
#include "protocol.h"
static const int32_t hwopts[] = {
devices = NULL;
conn = NULL;
serialcomm = NULL;
+ devc = NULL;
for (l = options; l; l = l->next) {
src = l->data;
/* Get the device model. */
memset(&reply, 0, sizeof(reply));
- serial_write_blocking(serial, "GMOD\r", 5);
- serial_read_blocking(serial, &reply, 8);
+ if ((hcs_send_cmd(serial, "GMOD\r") < 0) ||
+ (hcs_read_reply(serial, 2, reply, sizeof(reply)) < 0))
+ return NULL;
tokens = g_strsplit((const gchar *)&reply, "\r", 2);
model_id = -1;
if (!strcmp(models[i].id, tokens[0]))
model_id = i;
}
+ g_strfreev(tokens);
+
if (model_id < 0) {
sr_err("Unknown model id '%s' detected, aborting.", tokens[0]);
return NULL;
}
+ /* Init device instance, etc. */
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Manson",
models[model_id].name, NULL))) {
sr_err("Failed to create device instance.");
return NULL;
}
- g_strfreev(tokens);
-
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->driver = di;
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) {
sr_err("Failed to create channel.");
- return NULL;
+ goto exit_err;
}
sdi->channels = g_slist_append(sdi->channels, ch);
sdi->priv = devc;
+ /* Get current device status. */
+ if ((hcs_send_cmd(serial, "GETD\r") < 0) ||
+ (hcs_read_reply(serial, 2, reply, sizeof(reply)) < 0))
+ return NULL;
+ tokens = g_strsplit((const gchar *)&reply, "\r", 2);
+ if (hcs_parse_volt_curr_mode(sdi, tokens) < 0)
+ goto exit_err;
+
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
sr_serial_dev_inst_free(serial);
return devices;
+
+exit_err:
+ sr_dev_inst_free(sdi);
+ if (devc)
+ g_free(devc);
+ return NULL;
}
static GSList *dev_list(void)