diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index c41440cde..a575a1cd8 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -1264,6 +1264,13 @@ enum sr_configkey { SR_CONF_TEST_MODE, /* Update sr_key_info_config[] (hwdriver.c) upon changes! */ + + /*--- Custom command ------------------------------------------------*/ + + /** Send a custom command to the device (e.g. SCPI command). */ + SR_CONF_CUSTOM_CMD, + + /* Update sr_key_info_config[] (hwdriver.c) upon changes! */ }; /** diff --git a/src/hardware/rohde-schwarz-hameg/api.c b/src/hardware/rohde-schwarz-hameg/api.c index fa7818e05..adbb1ae26 100644 --- a/src/hardware/rohde-schwarz-hameg/api.c +++ b/src/hardware/rohde-schwarz-hameg/api.c @@ -655,7 +655,8 @@ static int config_set(uint32_t key, GVariant *data, unsigned int custom_threshold_idx, tmp_uint; char command[MAX_COMMAND_SIZE], command2[MAX_COMMAND_SIZE]; char command3[MAX_COMMAND_SIZE], command4[MAX_COMMAND_SIZE]; - char float_str[30], *tmp_str; + char float_str[30], *tmp_str, *tmp_str2; + char **commands; struct dev_context *devc; const struct scope_config *model; struct scope_state *state; @@ -680,6 +681,27 @@ static int config_set(uint32_t key, GVariant *data, update_sample_rate = FALSE; switch (key) { + case SR_CONF_CUSTOM_CMD: + tmp_str = (char *)g_variant_get_string(data, (gsize *)&idx); + if (idx > MAX_COMMAND_SIZE) { + sr_err("SCPI command is too long !"); + return SR_ERR_ARG; + } + commands = g_strsplit(tmp_str, ";", 0); + for (i = 0; commands[i]; i++) { + tmp_str2 = strchr(commands[i], '\0'); + if ((--tmp_str2)[0] == '?') { + ret = sr_scpi_get_string(sdi->conn, commands[i], &tmp_str2); + if (ret == SR_OK) + printf("'%s'\n", tmp_str2); + else + break; + } else { + ret = sr_scpi_send(sdi->conn, commands[i]); + } + } + g_strfreev(commands); + break; case SR_CONF_LIMIT_SAMPLES: devc->samples_limit = g_variant_get_uint64(data); ret = SR_OK; diff --git a/src/hardware/rohde-schwarz-hameg/model_desc.h b/src/hardware/rohde-schwarz-hameg/model_desc.h index 997e482cf..bfbfd6e86 100644 --- a/src/hardware/rohde-schwarz-hameg/model_desc.h +++ b/src/hardware/rohde-schwarz-hameg/model_desc.h @@ -408,6 +408,7 @@ static const char *rohde_schwarz_rto_scpi_dialect[] = { /* Options currently supported on the HMO2524 and HMO3000 series. */ static const uint32_t devopts_hmo300x[] = { SR_CONF_OSCILLOSCOPE, + SR_CONF_CUSTOM_CMD | SR_CONF_SET, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, @@ -472,6 +473,7 @@ static const uint32_t devopts_hmo300x[] = { /* Options currently supported on the HMO Compact, HMO1x02 and RTC1000 series. */ static const uint32_t devopts_hmocompact_hmo1x02_rtc100x[] = { SR_CONF_OSCILLOSCOPE, + SR_CONF_CUSTOM_CMD | SR_CONF_SET, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, @@ -535,6 +537,7 @@ static const uint32_t devopts_hmocompact_hmo1x02_rtc100x[] = { /* Options currently supported on the RTB200x, RTM300x and RTA400x series. */ static const uint32_t devopts_rtb200x_rtm300x_rta400x[] = { SR_CONF_OSCILLOSCOPE, + SR_CONF_CUSTOM_CMD | SR_CONF_SET, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, @@ -595,6 +598,7 @@ static const uint32_t devopts_rtb200x_rtm300x_rta400x[] = { /* Options currently supported on the RTO series. */ static const uint32_t devopts_rto[] = { SR_CONF_OSCILLOSCOPE, + SR_CONF_CUSTOM_CMD | SR_CONF_SET, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET, diff --git a/src/hwdriver.c b/src/hwdriver.c index 2592c9e2a..cb659b249 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -330,6 +330,10 @@ static struct sr_key_info sr_key_info_config[] = { {SR_CONF_TEST_MODE, SR_T_STRING, "test_mode", "Test mode", NULL}, + /* Custom command (e.g. SCPI command) */ + {SR_CONF_CUSTOM_CMD, SR_T_STRING, "command", + "Custom command", NULL}, + ALL_ZERO };