Hey Alexis, I am VERY new to this dev, but I have been digging about because I needed a VXI based "event" (intr_srq) so I have looked at this code a bit.Here is my layman read of the code and how the "timeout" value passed is handled. Normally the sr_scpi_source_add takes an "events" (nearly always G_IO_IN) and a timeout, and a callback/cb_data.This call makes a call to a "operations" pointer, scpi->source_add. So this ends up in one of the various SCPI transport layers * USB * VXI / VISA (via rpc, or librevisa) * Serial (uart support) * TCP (raw TCP port; aka SCPI-Raw by Agilent, SOCKET server for Tektronix) * and so on ( See: https://github.com/droghio/sigrok/blob/master/src/scpi/scpi.c#L423 ) For most protocols this ends up really just boiling down to being a counter that then timesout after the passed in "timeout" value mentioned above, which means you effectively end up polling on the transport layer. For USB its different, see below. https://github.com/droghio/sigrok/blob/master/src/scpi/scpi_usbtmc_libusb.c#L416 SR_PRIV const struct sr_scpi_dev_inst scpi_usbtmc_libusb_dev = { .. .source_add = scpi_usbtmc_libusb_source_add, ..}; static int scpi_usbtmc_libusb_source_add( ... return usb_source_add(session, uscpi->ctx, timeout, cb, cb_data);... }
https://github.com/merbanan/libsigrok/blob/master/src/usb.c static GSource *usb_source_new ... upollfds = libusb_get_pollfds(usb_ctx); SR_PRIV int usb_source_add( ... source = usb_source_new(session, ctx->libusb_ctx, timeout); ... ret = sr_session_source_add_internal(session, ctx->libusb_ctx, source); ...} So now for usb it seems you would wait on control pipe (fd0) and then timerfd or async io transfer timeout.( libusb: Polling and timing ). So once some USB activity happens, or the USB stack times out then you will come back to the call back. Cheers, Luc On Wednesday, October 20, 2021, 07:44:14 AM GMT+9, Alexis Murzeau <amub...@gmail.com> wrote: Hi, I'm trying to implement a hardware driver for keysight 3000-series oscilloscopes, but I'm struggling to understand how things work. I'm using SCPI over USB to communicate with it. I've seen that most drivers use sr_scpi_source_add function with a "receive" callback, but when is it called ? If I do a command that return something, like this: `sr_scpi_get_int(sdi->conn, "*ESR?", &tmp)`, Will this both return the value in `tmp` and also trigger the `receive` callback ? I don't know well SCPI, but I'm not aware of any asynchronous notification mechanism, the only way to receive values is using commands ending with `?`, right ? Thanks! -- Alexis Murzeau PGP: B7E6 0EBB 9293 7B06 BDBC 2787 E7BD 1904 F480 937F | _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel
_______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel