Skip to content

Commit

Permalink
Support sending custom SCPI commands to the oscilloscope
Browse files Browse the repository at this point in the history
in the Rohde&Schwarz/Hameg driver.

When using sigrok-cli the following recent sigrok-cli
change is required:

commit e212d5381f5b178fcbb5efa745856b825f29c1fb
Date:   Sat Dec 22 14:16:22 2018 +0100
  • Loading branch information
gtrentalancia committed Jul 15, 2019
1 parent 3c5e691 commit 9da062f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/libsigrok/libsigrok.h
Original file line number Diff line number Diff line change
Expand Up @@ -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! */
};

/**
Expand Down
24 changes: 23 additions & 1 deletion src/hardware/rohde-schwarz-hameg/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/hardware/rohde-schwarz-hameg/model_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/hwdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 9da062f

Please sign in to comment.