int response_bytes_read;
};
-static int scpi_usbtmc_dev_inst_new(void *priv, const char *resource,
- char **params, const char *serialcomm)
+static GSList *scpi_usbtmc_scan(struct drv_context *drvc)
+{
+ GSList *resources = NULL;
+ GDir *dir;
+ const char *dev_name;
+ char *resource;
+
+ (void)drvc;
+
+ if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
+ if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
+ return NULL;
+ while ((dev_name = g_dir_read_name(dir))) {
+ if (strncmp(dev_name, "usbtmc", 6))
+ continue;
+ resource = g_strconcat("/dev/", dev_name, NULL);
+ resources = g_slist_append(resources, resource);
+ }
+ g_dir_close(dir);
+
+ return resources;
+}
+
+static int scpi_usbtmc_dev_inst_new(void *priv, struct drv_context *drvc,
+ const char *resource, char **params, const char *serialcomm)
{
struct usbtmc_scpi *uscpi = priv;
+ (void)drvc;
(void)params;
(void)serialcomm;
uscpi->response_length = len;
uscpi->response_bytes_read = 0;
+ sr_spew("Read %d bytes from device into buffer", len);
+
return SR_OK;
}
struct usbtmc_scpi *uscpi = priv;
int read_length;
- if (uscpi->response_length == MAX_READ_LENGTH
- && uscpi->response_bytes_read == uscpi->response_length)
- if (scpi_usbtmc_read_begin(uscpi) != SR_OK)
- return SR_ERR;
+ sr_spew("%d bytes requested", maxlen);
- if (uscpi->response_bytes_read >= uscpi->response_length)
- return SR_ERR;
+ if (uscpi->response_bytes_read == uscpi->response_length) {
+ sr_spew("Buffer is empty.");
+ if (uscpi->response_length == MAX_READ_LENGTH) {
+ sr_spew("Previous read was of maximum length, reading again.");
+ if (scpi_usbtmc_read_begin(uscpi) != SR_OK)
+ return SR_ERR;
+ } else {
+ return SR_ERR;
+ }
+ }
read_length = uscpi->response_length - uscpi->response_bytes_read;
uscpi->response_bytes_read += read_length;
+ sr_spew("Returned %d bytes from buffer, %d/%d bytes of buffer now read",
+ read_length, uscpi->response_bytes_read, uscpi->response_length);
+
return read_length;
}
.name = "USBTMC",
.prefix = "/dev/usbtmc",
.priv_size = sizeof(struct usbtmc_scpi),
+ .scan = scpi_usbtmc_scan,
.dev_inst_new = scpi_usbtmc_dev_inst_new,
.open = scpi_usbtmc_open,
.source_add = scpi_usbtmc_source_add,