--- title: "Timeouts and logging" description: "Set how long Slate waits for a camera and how it retries a busy one with transactionPolicy, and watch every PTP exchange with the logger." url: https://darkgrade.com/docs/slate/guides/timeouts-and-logging last_updated: 2026-12-04 docs_index: https://darkgrade.com/docs/llms.txt --- # Timeouts and logging > Set how long Slate waits for a camera and how it retries a busy one with transactionPolicy, and watch every PTP exchange with the logger. > ## Documentation Index > Fetch the complete documentation index at: https://darkgrade.com/docs/llms.txt > Use this file to discover all available pages before exploring further. Two `Camera` options control how Darkgrade Slate talks to the camera under every method: `transactionPolicy` sets its patience, and `logger` shows you the conversation. ```typescript import { Camera } from '@darkgrade/slate' const camera = new Camera({ // Wait 10 s for each phase. The default is 30 s. transactionPolicy: { timeoutMilliseconds: 10_000 }, // Draw each exchange in the terminal. logger: { renderInTerminal: true }, }) ``` Both take a partial object: what you leave out keeps its default. ## Transaction policy A *transaction* is one PTP exchange: a command, optional data, and the camera's response. Every `Camera` method is made of them, and the policy applies to each one. [What is PTP?](https://darkgrade.com/docs/slate/getting_started/what-is-ptp.md#transactions) has the detail. **`timeoutMilliseconds`** · `number` · default `30000` How long one send or receive phase may take. **`minimumThroughputBytesPerSecond`** · `number` · default `2097152` Large transfers get extra time at this rate (2 MiB/s) on top of the timeout, so a big download is not cut off while it is still moving. **`deviceBusyRetries`** · `number` · default `6` How many times a standard PTP operation answered [DeviceBusy](https://darkgrade.com/docs/slate/ptp-reference/response-definitions.md#devicebusy-0x2019) is tried again. `0` turns retries off; the most is `32`. **`deviceBusyBackoffMilliseconds`** · `number` · default `50` The wait before the first retry. Each further retry doubles it: 50, 100, 200, 400, 800 ms. **`deviceBusyBudgetMilliseconds`** · `number` · default `2000` Retries stop once this much time has passed since the first attempt. The last wait is shortened to fit. **`automaticUSBReset`** · `boolean` · default `true` After a timeout or a malformed reply on USB, Slate resets the connection and reopens the session before the next command. See [After a timeout](#after-a-timeout). **`recoverTransport`** · `(failure) => Promise` Your own recovery, run in place of the automatic USB reset. See [Your own recovery](#your-own-recovery). The defaults are exported as `DEFAULT_TRANSACTION_POLICY`, with the type [`TransactionPolicy`](https://darkgrade.com/docs/slate/reference/types-workflow.md#transactionpolicy): ```typescript import { Camera, DEFAULT_TRANSACTION_POLICY } from '@darkgrade/slate' const { timeoutMilliseconds } = DEFAULT_TRANSACTION_POLICY const camera = new Camera({ transactionPolicy: { timeoutMilliseconds: timeoutMilliseconds * 2, deviceBusyRetries: 0, // report a busy camera at once }, }) ``` An invalid value (a timeout that is not a positive integer, more than 32 retries) throws when the `Camera` is constructed. > [!NOTE] > > Busy retries only repeat a command the camera refused to start. A command that was sent and not confirmed is never resent: it becomes `CameraOutcomeUnknownError`. See [Errors and recovery](https://darkgrade.com/docs/slate/guides/errors.md). ### After a timeout A timeout can leave a half-finished exchange on the cable, and the next command would read its leftovers. - **USB, `automaticUSBReset: true`** (the default): before the next command, Slate sends the USB still-image class Device Reset, waits for the abandoned transfer to settle and reopens the session. - **If that reset fails, or `automaticUSBReset` is `false`**: every later command fails with [`PTPRecoveryRequiredError`](https://darkgrade.com/docs/slate/reference/errors.md#ptprecoveryrequirederror) until you `disconnect()` and `connect()`, or call [`recover()`](https://darkgrade.com/docs/functionality/connection.md#recover-a-stuck-camera). - **PTP/IP**: there is no class reset. `IPTransport` also has a `timeout` of its own (15 s by default), and closes the connection when it runs out. Either way, connect again. See [Wi-Fi with PTP/IP](https://darkgrade.com/docs/slate/getting_started/ptp-ip.md#limits). ### Your own recovery Set `recoverTransport` when a reset must respect something Slate can't see, such as a recording in progress on a rig, or a lease another process holds. It replaces the automatic reset. ```typescript import { Camera } from '@darkgrade/slate' const camera = new Camera({ transactionPolicy: { recoverTransport: async failure => { console.warn(`Recovering after ${failure.operation}`) // Settle the connection here. }, }, }) ``` - The callback receives the failed transaction's `operation`, `transactionId` and `cause`. - It must finish any outstanding transport I/O before it resolves, and it must not call methods of the same `Camera`. - While it is pending, and if it throws, further commands fail with `PTPRecoveryRequiredError`. - Slate does not reopen the session after your callback. If your recovery ended the session, call `disconnect()` and `connect()`. ## Logging The logger is off by default: it draws nothing and leaves `console` alone. Turn on what you need: **`renderInTerminal`** · `boolean` · default `false` Draws every transaction in the terminal as it happens: the operation, its parameters, the data and the response. Node.js only. **`captureConsole`** · `boolean` · default `false` Routes `console.log`, `console.info`, `console.warn` and `console.error` into the logger's display, so your own output does not tear it. Node.js only. **`expanded`** · `boolean` · default `true` Shows each entry's detail in the terminal. `false` shows one line per entry. **`maxTransactions`** · `number` · default `1000` How many transactions are kept in memory. Older ones are dropped, with any data they carried. ```typescript import { Camera } from '@darkgrade/slate' const camera = new Camera({ logger: { renderInTerminal: true, captureConsole: true, expanded: false, }, }) await camera.connect() await camera.getCapabilities() // each exchange appears as it happens await camera.disconnect() ``` The defaults are exported as `defaultLoggerConfig`, with the type [`LoggerConfig`](https://darkgrade.com/docs/slate/reference/types-workflow.md#loggerconfig). > [!TIP] > > For a record of what a failed call sent, rather than a live display, see the `callId` that [telemetry](https://darkgrade.com/docs/slate/guides/telemetry.md) attaches to each `Camera` call and the commands behind it. ## Other options `keepAlive`, `usb`, `transport`, `vendorId` and `firstContact` are the remaining `Camera` options: see the [constructor](https://darkgrade.com/docs/slate/getting_started/camera.md#constructor).