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.
This commit is contained in:
Jef Driesen 2016-11-03 19:27:28 +01:00
parent c3dc368163
commit 7778533bdf

View File

@ -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);