Skip to content

Reconnect automatically after the camera drops off USB - #9

Open
riversn wants to merge 1 commit into
shurkanTwo:masterfrom
riversn:fix/usb-disconnect-recovery
Open

riversn wants to merge 1 commit into
shurkanTwo:masterfrom
riversn:fix/usb-disconnect-recovery

Conversation

@riversn

@riversn riversn commented Oct 22, 2026 •

Copy link
Copy Markdown

Works together with the native driver fixes in dougforpres/SonyCamera#19.

An unattended sequence could not survive a USB drop: three native errors disabled the driver until N.I.N.A. restarted, the lost handle stayed registered in the native driver (so a later open reused a dead camera), and NINA dropped the camera from the sequence. Together with fixes in the native driver (dougforpres/SonyCamera), the plugin now recovers on its own.

SonyDriver (Sony.cs)

  • Repeated native errors drop the handle instead of stopping the executor; only a hung P/Invoke (executor timeout) still requires a restart.
  • A lost handle is closed in the native driver exactly once.
  • ReopenCamera closes the stale handle, opens the camera again and re-attaches the lens. CanReopen / IsAwaitingReopen expose the state.
  • Close timeout raised from 5 s to 30 s: the native close can wait 20 s for an operation in progress, which was being treated as a hang.

CameraDriver

  • After a failed exposure, a failed status read or a lost handle, the next exposure reopens the camera first, waiting up to 2 minutes for it to come back (retry every second) instead of failing straight away, so a short drop costs one frame rather than the rest of the sequence. Abort or Disconnect ends the wait. Connected stays true while the camera can be reopened.
  • After a reopen the requested ISO is restored once the camera reports its settings (a reopened camera reads 0 at first, and stepping from that left the wrong ISO), then verified and retried.
  • An exposure that never finishes times out (2x its length + 2 minutes).
  • Restarting while the camera still finishes a stopped exposure waits for it instead of failing every remaining frame in milliseconds.
  • AbortExposure no longer warns "Abort requested" when NINA is only cleaning up after a failed exposure.
  • Gains returns the same list instance while the ISO options are unchanged, so the Equipment > Camera "Default gain" dropdown no longer goes blank on reconnect.

FocuserDriver stays connected while the camera is being reopened.

Tests: simulator support for unplugging, reopens and unread ISO after a reopen, plus tests for each behaviour (133 passing).

Tested with an ILCE-7M3 and N.I.N.A. 3.2.0.9001: manual and natural USB drops recover without user action; a 7.7-hour run (7,790 exposures) was clean.

An unattended sequence could not survive a USB drop: three native errors
disabled the driver until N.I.N.A. restarted, the lost handle stayed
registered in the native driver (so a later open reused a dead camera), and
NINA dropped the camera from the sequence. Together with fixes in the native
driver (dougforpres/SonyCamera), the plugin now recovers on its own.

SonyDriver (Sony.cs)
- Repeated native errors drop the handle instead of stopping the executor;
  only a hung P/Invoke (executor timeout) still requires a restart.
- A lost handle is closed in the native driver exactly once.
- ReopenCamera closes the stale handle, opens the camera again and
  re-attaches the lens. CanReopen / IsAwaitingReopen expose the state.
- Close timeout raised from 5 s to 30 s: the native close can wait 20 s for
  an operation in progress, which was being treated as a hang.

CameraDriver
- After a failed exposure, a failed status read or a lost handle, the next
  exposure reopens the camera first, waiting up to 2 minutes for it to come
  back (retry every second) instead of failing straight away, so a short drop
  costs one frame rather than the rest of the sequence. Abort or Disconnect
  ends the wait. Connected stays true while the camera can be reopened.
- After a reopen the requested ISO is restored once the camera reports its
  settings (a reopened camera reads 0 at first, and stepping from that left
  the wrong ISO), then verified and retried.
- An exposure that never finishes times out (2x its length + 2 minutes).
- Restarting while the camera still finishes a stopped exposure waits for it
  instead of failing every remaining frame in milliseconds.
- AbortExposure no longer warns "Abort requested" when NINA is only cleaning
  up after a failed exposure.
- Gains returns the same list instance while the ISO options are unchanged,
  so the Equipment > Camera "Default gain" dropdown no longer goes blank on
  reconnect.

FocuserDriver stays connected while the camera is being reopened.

Tests: simulator support for unplugging, reopens and unread ISO after a
reopen, plus tests for each behaviour (133 passing).

Tested with an ILCE-7M3 and N.I.N.A. 3.2.0.9001: manual and natural USB drops
recover without user action; a 7.7-hour run (7,790 exposures) was clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant