Two Camera options control how Darkgrade Slate talks to the camera under every method: transactionPolicy sets its patience, and logger shows you the conversation.
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? has the detail.
How long one send or receive phase may take.
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.
How many times a standard PTP operation answered DeviceBusy is tried again. 0 turns retries off; the most is 32.
The wait before the first retry. Each further retry doubles it: 50, 100, 200, 400, 800 ms.
Retries stop once this much time has passed since the first attempt. The last wait is shortened to fit.
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.
Your own recovery, run in place of the automatic USB reset. See Your own recovery.
The defaults are exported as DEFAULT_TRANSACTION_POLICY, with the type TransactionPolicy:
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.
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.
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
automaticUSBResetisfalse: every later command fails withPTPRecoveryRequiredErroruntil youdisconnect()andconnect(), or callrecover(). - PTP/IP: there is no class reset.
IPTransportalso has atimeoutof its own (15 s by default), and closes the connection when it runs out. Either way, connect again. See Wi-Fi with PTP/IP.
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.
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,transactionIdandcause. - 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()andconnect().
Logging
The logger is off by default: it draws nothing and leaves console alone. Turn on what you need:
Draws every transaction in the terminal as it happens: the operation, its parameters, the data and the response. Node.js only.
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.
Shows each entry's detail in the terminal. false shows one line per entry.
How many transactions are kept in memory. Older ones are dropped, with any data they carried.
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.
For a record of what a failed call sent, rather than a live display, see the callId that telemetry 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.