]> sigrok.org Git - libsigrok.git/blob - src/scpi.h
hameg-hmo: Remove unused SCPI command enums, sort entries.
[libsigrok.git] / src / scpi.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Bert Vermeulen <bert@biot.com>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /** @file
21   * @internal
22   */
23
24 #ifndef LIBSIGROK_SCPI_H
25 #define LIBSIGROK_SCPI_H
26
27 #include <stdint.h>
28 #include <glib.h>
29 #include <libsigrok/libsigrok.h>
30 #include "libsigrok-internal.h"
31
32 #define SCPI_CMD_IDN "*IDN?"
33 #define SCPI_CMD_OPC "*OPC?"
34
35 enum {
36         SCPI_CMD_GET_TIMEBASE = 1,
37         SCPI_CMD_SET_TIMEBASE,
38         SCPI_CMD_GET_VERTICAL_DIV,
39         SCPI_CMD_SET_VERTICAL_DIV,
40         SCPI_CMD_GET_TRIGGER_SLOPE,
41         SCPI_CMD_SET_TRIGGER_SLOPE,
42         SCPI_CMD_GET_TRIGGER_SOURCE,
43         SCPI_CMD_SET_TRIGGER_SOURCE,
44         SCPI_CMD_GET_COUPLING,
45         SCPI_CMD_SET_COUPLING,
46         SCPI_CMD_GET_HORIZ_TRIGGERPOS,
47         SCPI_CMD_SET_HORIZ_TRIGGERPOS,
48         SCPI_CMD_GET_ANALOG_CHAN_STATE,
49         SCPI_CMD_SET_ANALOG_CHAN_STATE,
50         SCPI_CMD_GET_DIG_CHAN_STATE,
51         SCPI_CMD_SET_DIG_CHAN_STATE,
52         SCPI_CMD_GET_VERTICAL_OFFSET,
53         SCPI_CMD_GET_DIG_POD_STATE,
54         SCPI_CMD_SET_DIG_POD_STATE,
55         SCPI_CMD_GET_ANALOG_DATA,
56         SCPI_CMD_GET_DIG_DATA,
57         SCPI_CMD_GET_SAMPLE_RATE,
58         SCPI_CMD_GET_SAMPLE_RATE_LIVE,
59         SCPI_CMD_GET_PROBE_UNIT,
60         SCPI_CMD_GET_DIG_POD_THRESHOLD,
61         SCPI_CMD_SET_DIG_POD_THRESHOLD,
62         SCPI_CMD_GET_DIG_POD_USER_THRESHOLD,
63         SCPI_CMD_SET_DIG_POD_USER_THRESHOLD,
64 };
65
66 enum scpi_transport_layer {
67         SCPI_TRANSPORT_LIBGPIB,
68         SCPI_TRANSPORT_SERIAL,
69         SCPI_TRANSPORT_RAW_TCP,
70         SCPI_TRANSPORT_RIGOL_TCP,
71         SCPI_TRANSPORT_USBTMC,
72         SCPI_TRANSPORT_VISA,
73         SCPI_TRANSPORT_VXI,
74 };
75
76 struct scpi_command {
77         int command;
78         const char *string;
79 };
80
81 struct sr_scpi_hw_info {
82         char *manufacturer;
83         char *model;
84         char *serial_number;
85         char *firmware_version;
86 };
87
88 struct sr_scpi_dev_inst {
89         const char *name;
90         const char *prefix;
91         enum scpi_transport_layer transport;
92         int priv_size;
93         GSList *(*scan)(struct drv_context *drvc);
94         int (*dev_inst_new)(void *priv, struct drv_context *drvc,
95                 const char *resource, char **params, const char *serialcomm);
96         int (*open)(struct sr_scpi_dev_inst *scpi);
97         int (*connection_id)(struct sr_scpi_dev_inst *scpi, char **connection_id);
98         int (*source_add)(struct sr_session *session, void *priv, int events,
99                 int timeout, sr_receive_data_callback cb, void *cb_data);
100         int (*source_remove)(struct sr_session *session, void *priv);
101         int (*send)(void *priv, const char *command);
102         int (*read_begin)(void *priv);
103         int (*read_data)(void *priv, char *buf, int maxlen);
104         int (*write_data)(void *priv, char *buf, int len);
105         int (*read_complete)(void *priv);
106         int (*close)(struct sr_scpi_dev_inst *scpi);
107         void (*free)(void *priv);
108         unsigned int read_timeout_us;
109         void *priv;
110         /* Only used for quirk workarounds, notably the Rigol DS1000 series. */
111         uint64_t firmware_version;
112         GMutex scpi_mutex;
113         char *actual_channel_name;
114 };
115
116 SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
117                 struct sr_dev_inst *(*probe_device)(struct sr_scpi_dev_inst *scpi));
118 SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
119                 const char *resource, const char *serialcomm);
120 SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
121 SR_PRIV int sr_scpi_connection_id(struct sr_scpi_dev_inst *scpi,
122                 char **connection_id);
123 SR_PRIV int sr_scpi_source_add(struct sr_session *session,
124                 struct sr_scpi_dev_inst *scpi, int events, int timeout,
125                 sr_receive_data_callback cb, void *cb_data);
126 SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
127                 struct sr_scpi_dev_inst *scpi);
128 SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
129                 const char *format, ...);
130 SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi,
131                 const char *format, va_list args);
132 SR_PRIV int sr_scpi_read_begin(struct sr_scpi_dev_inst *scpi);
133 SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen);
134 SR_PRIV int sr_scpi_write_data(struct sr_scpi_dev_inst *scpi, char *buf, int len);
135 SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi);
136 SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi);
137 SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi);
138
139 SR_PRIV int sr_scpi_read_response(struct sr_scpi_dev_inst *scpi,
140                         GString *response, gint64 abs_timeout_us);
141 SR_PRIV int sr_scpi_get_string(struct sr_scpi_dev_inst *scpi,
142                         const char *command, char **scpi_response);
143 SR_PRIV int sr_scpi_get_bool(struct sr_scpi_dev_inst *scpi,
144                         const char *command, gboolean *scpi_response);
145 SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi,
146                         const char *command, int *scpi_response);
147 SR_PRIV int sr_scpi_get_float(struct sr_scpi_dev_inst *scpi,
148                         const char *command, float *scpi_response);
149 SR_PRIV int sr_scpi_get_double(struct sr_scpi_dev_inst *scpi,
150                         const char *command, double *scpi_response);
151 SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi);
152 SR_PRIV int sr_scpi_get_floatv(struct sr_scpi_dev_inst *scpi,
153                         const char *command, GArray **scpi_response);
154 SR_PRIV int sr_scpi_get_uint8v(struct sr_scpi_dev_inst *scpi,
155                         const char *command, GArray **scpi_response);
156 SR_PRIV int sr_scpi_get_data(struct sr_scpi_dev_inst *scpi,
157                         const char *command, GString **scpi_response);
158 SR_PRIV int sr_scpi_get_block(struct sr_scpi_dev_inst *scpi,
159                         const char *command, GByteArray **scpi_response);
160 SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
161                         struct sr_scpi_hw_info **scpi_response);
162 SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);
163
164 SR_PRIV const char *sr_scpi_unquote_string(char *s);
165
166 SR_PRIV const char *sr_vendor_alias(const char *raw_vendor);
167 SR_PRIV const char *sr_scpi_cmd_get(const struct scpi_command *cmdtable,
168                 int command);
169 SR_PRIV int sr_scpi_cmd(const struct sr_dev_inst *sdi,
170                 const struct scpi_command *cmdtable,
171                 int channel_command, const char *channel_name,
172                 int command, ...);
173 SR_PRIV int sr_scpi_cmd_resp(const struct sr_dev_inst *sdi,
174                 const struct scpi_command *cmdtable,
175                 int channel_command, const char *channel_name,
176                 GVariant **gvar, const GVariantType *gvtype, int command, ...);
177
178 /*--- GPIB only functions ---------------------------------------------------*/
179
180 #ifdef HAVE_LIBGPIB
181 SR_PRIV int sr_scpi_gpib_spoll(struct sr_scpi_dev_inst *scpi, char *buf);
182 #endif
183
184 #endif