2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
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/>.
25 #include "libsigrok.h"
26 #include "libsigrok-internal.h"
29 SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data)
31 struct sr_dev_inst *sdi;
32 struct dev_context *devc;
33 struct sr_datafeed_packet packet;
34 struct sr_datafeed_analog analog;
35 unsigned char buf[WAVEFORM_SIZE];
36 float data[WAVEFORM_SIZE];
42 if (!(devc = sdi->priv))
45 if (revents == G_IO_IN) {
46 len = read(fd, buf, WAVEFORM_SIZE);
47 sr_dbg("Received %d bytes.", len);
50 for (i = 0; i < len; i++)
51 data[i] = devc->scale / 25.6 * (128 - buf[i]) - devc->offset;
52 analog.probes = devc->enabled_probes;
53 analog.num_samples = len;
55 analog.mq = SR_MQ_VOLTAGE;
56 analog.unit = SR_UNIT_VOLT;
58 packet.type = SR_DF_ANALOG;
59 packet.payload = &analog;
60 sr_session_send(cb_data, &packet);
62 if (++devc->num_frames == devc->limit_frames)
63 sdi->driver->dev_acquisition_stop(sdi, cb_data);
65 rigol_ds1xx2_send_data(fd, ":WAV:DATA?\n");
71 SR_PRIV int rigol_ds1xx2_send_data(int fd, const char *format, ...)
77 va_start(args, format);
78 len = vsprintf(buf, format, args);
80 len = write(fd, buf, len);
81 sr_dbg("Sent '%s'.", buf);