- for (j = 0; j < model->analog_channels; j++) {
- if (cg != devc->analog_groups[j])
- continue;
- state->analog_channels[j].coupling = idx;
- g_snprintf(command, sizeof(command), "C%d:COUPLING %s",
- j + 1, (*model->coupling_options)[idx]);
- if (sr_scpi_send(sdi->conn, command) != SR_OK ||
- sr_scpi_get_opc(sdi->conn) != SR_OK)
- return SR_ERR;
- break;
- }
+ if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
+ return SR_ERR_ARG;
+ state->analog_channels[j].coupling = idx;
+ g_snprintf(command, sizeof(command), "C%d:COUPLING %s",
+ j + 1, (*model->coupling_options)[idx]);
+ if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;