From 7778533bdf985eea6cc6c6d9d968b962065ddfb1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 3 Nov 2016 19:27:28 +0100 Subject: [PATCH] Toggle the DTR line during setup On linux, several users are reporting download problems, while on windows everything works fine. Simply toggling the DTR line appears to fix the problem. A possible explanation is that on windows, the SetCommState() function not only configures the serial protocol parameters, but also initializes the DTR and RTS lines. In the libdivecomputer implementation the default state is enabled (DTR_CONTROL_ENABLE and RTS_CONTROL_ENABLE). The result is that the DTR line gets automatically initialized to enabled, and then manually disabled again. On linux, the DTR and RTS lines are not automatically initialized during configuration, and need to be controlled explicitely. The result is that the DTR line ends up disabled without being toggled. --- src/cressi_leonardo.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index faad494..cda8a0c 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -201,13 +201,6 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha goto error_close; } - // Clear the DTR line. - status = dc_serial_set_dtr (device->port, 0); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to clear the DTR line."); - goto error_close; - } - // Set the RTS line. status = dc_serial_set_rts (device->port, 1); if (status != DC_STATUS_SUCCESS) { @@ -215,6 +208,22 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha goto error_close; } + // Set the DTR line. + status = dc_serial_set_dtr (device->port, 1); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to set the DTR line."); + goto error_close; + } + + dc_serial_sleep (device->port, 200); + + // Clear the DTR line. + status = dc_serial_set_dtr (device->port, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the DTR line."); + goto error_close; + } + dc_serial_sleep (device->port, 100); dc_serial_purge (device->port, DC_DIRECTION_ALL);