2 * This file is part of the libsigrok project.
4 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, int command, ...)
27 struct dev_context *devc;
28 struct sr_scpi_dev_inst *scpi;
35 for (i = 0; i < devc->device->num_commands; i++) {
36 if (devc->device->commands[i].command == command) {
37 cmd = devc->device->commands[i].string;
42 /* Device does not implement this command, that's OK. */
43 return SR_OK_CONTINUE;
47 va_start(args, command);
48 ret = sr_scpi_send_variadic(scpi, cmd, args);
54 SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data)
56 struct dev_context *devc;
57 struct sr_datafeed_packet packet;
58 struct sr_datafeed_analog analog;
59 const struct sr_dev_inst *sdi;
60 struct sr_scpi_dev_inst *scpi;
70 if (!(devc = sdi->priv))
73 if (devc->state == STATE_STOP)
78 /* Retrieve requested value for this state. */
79 if (sr_scpi_get_float(scpi, NULL, &f) == SR_OK) {
80 packet.type = SR_DF_ANALOG;
81 packet.payload = &analog;
82 analog.channels = g_slist_append(NULL, devc->cur_channel);
83 analog.num_samples = 1;
84 if (devc->state == STATE_VOLTAGE) {
85 analog.mq = SR_MQ_VOLTAGE;
86 analog.unit = SR_UNIT_VOLT;
88 analog.mq = SR_MQ_CURRENT;
89 analog.unit = SR_UNIT_AMPERE;
91 analog.mqflags = SR_MQFLAG_DC;
93 sr_session_send(sdi, &packet);
94 g_slist_free(analog.channels);
97 if (devc->state == STATE_VOLTAGE) {
98 /* Just got voltage, request current for this channel. */
99 devc->state = STATE_CURRENT;
100 scpi_cmd(sdi, SCPI_CMD_GET_MEAS_CURRENT, devc->cur_channel->name);
101 } else if (devc->state == STATE_CURRENT) {
103 * Done with voltage and current for this channel, switch to
104 * the next enabled channel.
107 l = g_slist_find(sdi->channels, devc->cur_channel);
109 devc->cur_channel = l->next->data;
111 devc->cur_channel = sdi->channels->data;
112 } while (!devc->cur_channel->enabled);
114 /* Request voltage. */
115 devc->state = STATE_VOLTAGE;
116 scpi_cmd(sdi, SCPI_CMD_GET_MEAS_VOLTAGE, devc->cur_channel->name);