]> sigrok.org Git - libsigrok.git/blobdiff - hardware/serial-dmm/api.c
serial-dmm: Cosmetics, documentation fixes.
[libsigrok.git] / hardware / serial-dmm / api.c
index 6e9eaa2478cc4f19d5f7c014b2611fd263c3dd41..49e68a218c4d277eec0dfc6da4827ff07b4b5ebb 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <glib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
+#include <glib.h>
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 #include "protocol.h"
@@ -203,21 +203,12 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm)
        if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
                return NULL;
 
-       sr_info("Probing port %s.", conn);
+       sr_info("Probing serial port %s.", conn);
 
        drvc = dmms[dmm].di->priv;
        devices = NULL;
        serial_flush(serial);
 
-       /*
-        * There's no way to get an ID from the multimeter. It just sends data
-        * periodically, so the best we can do is check if the packets match
-        * the expected format.
-        */
-
-       /* Let's get a bit of data and see if we can find a packet. */
-       len = sizeof(buf);
-
        /* Request a packet if the DMM requires this. */
        if (dmms[dmm].packet_request) {
                if ((ret = dmms[dmm].packet_request(serial)) < 0) {
@@ -226,6 +217,14 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm)
                }
        }
 
+       /*
+        * There's no way to get an ID from the multimeter. It just sends data
+        * periodically (or upon request), so the best we can do is check if
+        * the packets match the expected format.
+        */
+
+       /* Let's get a bit of data and see if we can find a packet. */
+       len = sizeof(buf);
        ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size,
                                   dmms[dmm].packet_valid, 1000,
                                   dmms[dmm].baudrate);
@@ -236,8 +235,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm)
         * If we dropped more than two packets worth of data, something is
         * wrong. We shouldn't quit however, since the dropped bytes might be
         * just zeroes at the beginning of the stream. Those can occur as a
-        * combination of the nonstandard cable that ships with this device and
-        * the serial port or USB to serial adapter.
+        * combination of the nonstandard cable that ships with some devices
+        * and the serial port or USB to serial adapter.
         */
        dropped = len - dmms[dmm].packet_size;
        if (dropped > 2 * dmms[dmm].packet_size)
@@ -255,6 +254,7 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm)
        }
 
        devc->serial = serial;
+       devc->subdriver = dmm;
 
        sdi->priv = devc;
        sdi->driver = dmms[dmm].di;
@@ -446,7 +446,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 50ms, or whenever some data comes in. */
        sr_source_add(devc->serial->fd, G_IO_IN, 50,
-                     dmms[sdi->driver->subdriver].receive_data, (void *)sdi);
+                     dmms[devc->subdriver].receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -512,7 +512,6 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \
        .dev_acquisition_start = hw_dev_acquisition_start, \
        .dev_acquisition_stop = hw_dev_acquisition_stop, \
        .priv = NULL, \
-       .subdriver = ID_UPPER, \
 };
 
 DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC")