libsigrok  0.4.0
sigrok hardware access and backend library
Go to the documentation of this file.
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Bert Vermeulen <>
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
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 <>.
18  */
20 /** @file
21  * @internal
22  */
27 #include <stdint.h>
28 #include <glib.h>
29 #include <libsigrok/libsigrok.h>
30 #include "libsigrok-internal.h"
32 #define SCPI_CMD_IDN "*IDN?"
33 #define SCPI_CMD_OPC "*OPC?"
35 enum {
59 };
61 struct scpi_command {
62  int command;
63  const char *string;
64 };
67  char *manufacturer;
68  char *model;
71 };
74  const char *name;
75  const char *prefix;
76  int priv_size;
77  GSList *(*scan)(struct drv_context *drvc);
78  int (*dev_inst_new)(void *priv, struct drv_context *drvc,
79  const char *resource, char **params, const char *serialcomm);
80  int (*open)(struct sr_scpi_dev_inst *scpi);
81  int (*source_add)(struct sr_session *session, void *priv, int events,
82  int timeout, sr_receive_data_callback cb, void *cb_data);
83  int (*source_remove)(struct sr_session *session, void *priv);
84  int (*send)(void *priv, const char *command);
85  int (*read_begin)(void *priv);
86  int (*read_data)(void *priv, char *buf, int maxlen);
87  int (*read_complete)(void *priv);
88  int (*close)(struct sr_scpi_dev_inst *scpi);
89  void (*free)(void *priv);
90  unsigned int read_timeout_ms;
91  void *priv;
92  /* Only used for quirk workarounds, notably the Rigol DS1000 series. */
93  uint64_t firmware_version;
94 };
96 SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
97  struct sr_dev_inst *(*probe_device)(struct sr_scpi_dev_inst *scpi));
98 SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
99  const char *resource, const char *serialcomm);
100 SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
101 SR_PRIV int sr_scpi_source_add(struct sr_session *session,
102  struct sr_scpi_dev_inst *scpi, int events, int timeout,
103  sr_receive_data_callback cb, void *cb_data);
104 SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
105  struct sr_scpi_dev_inst *scpi);
106 SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
107  const char *format, ...);
109  const char *format, va_list args);
111 SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen);
113 SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi);
114 SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi);
117  const char *command, char **scpi_response);
118 SR_PRIV int sr_scpi_get_bool(struct sr_scpi_dev_inst *scpi,
119  const char *command, gboolean *scpi_response);
120 SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi,
121  const char *command, int *scpi_response);
123  const char *command, float *scpi_response);
125  const char *command, double *scpi_response);
126 SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi);
128  const char *command, GArray **scpi_response);
130  const char *command, GArray **scpi_response);
132  struct sr_scpi_hw_info **scpi_response);
133 SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);
135 SR_PRIV const char *sr_vendor_alias(const char *raw_vendor);
136 SR_PRIV const char *scpi_cmd_get(const struct scpi_command *cmdtable, int command);
137 SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi,
138  const struct scpi_command *cmdtable, int command, ...);
139 SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi,
140  const struct scpi_command *cmdtable,
141  GVariant **gvar, const GVariantType *gvtype, int command, ...);
143 #endif
SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi, struct sr_scpi_hw_info **scpi_response)
const char * name
Definition: scpi.h:74
The public libsigrok header file to be used by frontends.
int(* read_complete)(void *priv)
Definition: scpi.h:87
SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi)
SR_PRIV int sr_scpi_source_add(struct sr_session *session, struct sr_scpi_dev_inst *scpi, int events, int timeout, sr_receive_data_callback cb, void *cb_data)
SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, const struct scpi_command *cmdtable, GVariant **gvar, const GVariantType *gvtype, int command,...)
SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen)
Opaque structure representing a libsigrok session.
Definition: libsigrok.h:454
int(* source_remove)(struct sr_session *session, void *priv)
Definition: scpi.h:83
const char * string
Definition: scpi.h:63
int(* open)(struct sr_scpi_dev_inst *scpi)
Definition: scpi.h:80
uint64_t firmware_version
Definition: scpi.h:93
int(* send)(void *priv, const char *command)
Definition: scpi.h:84
SR_PRIV int sr_scpi_source_remove(struct sr_session *session, struct sr_scpi_dev_inst *scpi)
int(* read_data)(void *priv, char *buf, int maxlen)
Definition: scpi.h:86
SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi, const char *command, int *scpi_response)
void * priv
Definition: scpi.h:91
SR_PRIV GSList * sr_scpi_scan(struct drv_context *drvc, GSList *options, struct sr_dev_inst *(*probe_device)(struct sr_scpi_dev_inst *scpi))
int(* source_add)(struct sr_session *session, void *priv, int events, int timeout, sr_receive_data_callback cb, void *cb_data)
Definition: scpi.h:81
unsigned int read_timeout_ms
Definition: scpi.h:90
char * serial_number
Definition: scpi.h:69
int(* read_begin)(void *priv)
Definition: scpi.h:85
char * firmware_version
Definition: scpi.h:70
int priv_size
Definition: scpi.h:76
SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi, const char *format,...)
SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi)
int command
Definition: scpi.h:62
int(* sr_receive_data_callback)(int fd, int revents, void *cb_data)
Type definition for callback function for data reception.
Definition: libsigrok.h:134
SR_PRIV int sr_scpi_get_uint8v(struct sr_scpi_dev_inst *scpi, const char *command, GArray **scpi_response)
SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi)
void(* free)(void *priv)
Definition: scpi.h:89
SR_PRIV const char * sr_vendor_alias(const char *raw_vendor)
SR_PRIV int sr_scpi_get_bool(struct sr_scpi_dev_inst *scpi, const char *command, gboolean *scpi_response)
SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info)
SR_PRIV int scpi_cmd(const struct sr_dev_inst *sdi, const struct scpi_command *cmdtable, int command,...)
SR_PRIV int sr_scpi_get_float(struct sr_scpi_dev_inst *scpi, const char *command, float *scpi_response)
SR_PRIV int sr_scpi_get_floatv(struct sr_scpi_dev_inst *scpi, const char *command, GArray **scpi_response)
char * manufacturer
Definition: scpi.h:67
SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi)
SR_PRIV const char * scpi_cmd_get(const struct scpi_command *cmdtable, int command)
SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi)
SR_PRIV int sr_scpi_read_begin(struct sr_scpi_dev_inst *scpi)
SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi, const char *format, va_list args)
char * model
Definition: scpi.h:68
const char * prefix
Definition: scpi.h:75
int(* dev_inst_new)(void *priv, struct drv_context *drvc, const char *resource, char **params, const char *serialcomm)
Definition: scpi.h:78
SR_PRIV struct sr_scpi_dev_inst * scpi_dev_inst_new(struct drv_context *drvc, const char *resource, const char *serialcomm)
#define SR_PRIV
Definition: libsigrok.h:128
int(* close)(struct sr_scpi_dev_inst *scpi)
Definition: scpi.h:88
SR_PRIV int sr_scpi_get_double(struct sr_scpi_dev_inst *scpi, const char *command, double *scpi_response)
SR_PRIV int sr_scpi_get_string(struct sr_scpi_dev_inst *scpi, const char *command, char **scpi_response)