diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 8d8bb62..6d07c0d 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -894,21 +894,37 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream goto error_free; } - // Give the interface 100 ms to settle and draw power up. + // Set the DTR line. + status = dc_iostream_set_dtr (device->iostream, 1); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to set the DTR line."); + goto error_free; + } + + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. dc_iostream_sleep (device->iostream, 100); - // Set the DTR/RTS lines. - status = dc_iostream_set_dtr(device->iostream, 1); + // Set the RTS line. + status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to set the DTR line."); - return status; - } - status = dc_iostream_set_rts(device->iostream, 1); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to set the DTR line."); - return status; + ERROR (context, "Failed to set the RTS line."); + goto error_free; } + // Give the interface 100 ms to settle and draw power up. + dc_iostream_sleep (device->iostream, 100); + // Make sure everything is in a sane state. dc_iostream_purge (device->iostream, DC_DIRECTION_ALL); diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index de70c7b..a6038d8 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -272,6 +272,20 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, dc_iostrea goto error_free; } + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. + dc_iostream_sleep (device->iostream, 100); + // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index d3387f2..cefeb7b 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -442,6 +442,20 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, dc_iostream goto error_free; } + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. + dc_iostream_sleep (device->iostream, 100); + // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) {