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