From a9d0784a9a62efe711b55ad074c1d1e57f5b5c8a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 23 Jul 2009 07:12:22 +0000 Subject: [PATCH] Changed the initialization sequence to allow multiple transfers. The DTR line is used to initialize or reset the communication. Toggling this line before each transfer, rather than doing it once at startup, allows to perform multiple transfers in the same session. --- src/uwatec_memomouse.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 777d3d7..accf88e 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -125,19 +125,18 @@ uwatec_memomouse_device_open (device_t **out, const char* name) return DEVICE_STATUS_IO; } - serial_sleep (200); - - serial_flush (device->port, SERIAL_QUEUE_BOTH); - - // Clear the RTS line and set the DTR line. - if (serial_set_dtr (device->port, 1) == -1 || - serial_set_rts (device->port, 0) == -1) { + // Clear the RTS and DTR lines. + if (serial_set_rts (device->port, 0) == -1 || + serial_set_dtr (device->port, 0) == -1) { WARNING ("Failed to set the DTR/RTS line."); serial_close (device->port); free (device); return DEVICE_STATUS_IO; } + // Make sure everything is in a sane state. + serial_flush (device->port, SERIAL_QUEUE_BOTH); + *out = (device_t*) device; return DEVICE_STATUS_SUCCESS; @@ -389,7 +388,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned static device_status_t -uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size) +uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size) { // Enable progress notifications. device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; @@ -491,6 +490,32 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], } +static device_status_t +uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size) +{ + // Give the interface some time to notice the DTR + // line change from a previous transfer (if any). + serial_sleep (500); + + // Set the DTR line. + if (serial_set_dtr (device->port, 1) == -1) { + WARNING ("Failed to set the RTS line."); + return DEVICE_STATUS_IO; + } + + // Start the transfer. + device_status_t rc = uwatec_memomouse_dump_internal (device, data, size); + + // Clear the DTR line again. + if (serial_set_dtr (device->port, 0) == -1) { + WARNING ("Failed to set the RTS line."); + return DEVICE_STATUS_IO; + } + + return rc; +} + + static device_status_t uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) {