Skip to content

SANE Device API

The SANE device API discovers SANE scanners in a Linux runtime, opens scanner sessions, reads and writes device options, manages option profiles, and submits asynchronous scan tasks. sane.* is Linux-only; non-Linux runtimes or libsane initialization failures return a SANE unavailable status. The current CZUR provider is private-sane-provider.

SANE Methods

MethodParametersResponse dataNotes
sane.statusnoneavailable, platform, supported_platforms[], sane_version, sane_major, sane_minor, reason, providerGets SANE provider availability.
sane.listrefresh?: boolean=true, include_detected?: boolean=falsedevices[], count, generation, optional detected_devices[], detected_count, providerLists openable devices; optionally returns devices detected but not openable through a SANE backend.
sane.watch_startnonewatching, generation, providerStarts device watching. It first pushes sane.device_snapshot; later changes push sane.device_changed.
sane.watch_stopnonewatching, generation, providerStops device watching for the current connection.
sane.opendevice_id?: string, device_name?: stringopened, session_id, device, providerOpens a scanner session. One of device_id or device_name is required.
sane.closesession_id: string requiredclosed, was_openedCloses a scanner session; returns device-busy while a scan task is running.
sane.get_optionssession_id: string requiredoptions[], count, providerGets normalized SANE options.
sane.set_optionssession_id: string required, options: object|array requiredapplied, requires_reload, results[], providerSets one or more SANE options.
sane.profile_listsession_id?: string, device_id?: string, device_name?: string, device_key?: stringprofiles[], count, providerLists saved SANE option profiles.
sane.profile_savename: string required, profile_id?: string, device location fields, options?: object|arraysaved, profile, providerSaves or overwrites an option profile.
sane.profile_applyprofile_id: string required, session_id?: stringapplied, profile, providerApplies a profile; when session_id is provided, profile options are written to the current device session.
sane.profile_deleteprofile_id: string requireddeleted, profile, providerDeletes a profile.
sane.scansession_id: string required, options?: object|array, output_type?: images|pdf|ofd|tiff, output_format?: string, output_path?: string, output_dir?: string, export_type?: single-page|multi-page, output?: object, pipeline?: ImageEnhancePipelineaccepted, task_id, task, providerSubmits an asynchronous scan task. One session can run only one scan task at a time.
sane.scan_gettask_id: string requiredaccepted, task_id, task, providerGets a scan task snapshot.
sane.scan_canceltask_id: string requiredaccepted, task_id, task, providerRequests cancellation for a scan task.

sane.open currently does not apply profile_id or options. To set parameters, open the session first, then call sane.set_options or sane.profile_apply with session_id.

Devices and Watching

sane.status returns current libsane initialization state on Linux; non-Linux runtimes return unavailable. supported_platforms[] is currently ["linux"].

devices[] and detected_devices[] fields:

FieldTypeNotes
device_idstringSDK internal device ID.
device_namestringSANE backend device name, usable with sane.open.
vendor / model / typestringDevice vendor, model, and type.
backendstringBackend that discovered the device.
statusstringCurrent status, usually online.
discovery_sourcestringDiscovery source, such as sane_backend.
openablebooleanWhether the device can be opened through a SANE backend.

Device watch events:

EventTriggerPayload
sane.device_snapshotPushed immediately after successful sane.watch_startgeneration, devices[], detected_devices[], detected_count, added_devices[], removed_devices[]
sane.device_changedDevice set changes while watchinggeneration, devices[], detected_devices[], detected_count, added_devices[], removed_devices[]

Options and Profiles

sane.get_options returns normalized SANE options:

FieldTypeNotes
indexnumberSANE option index, usable when setting an option.
name / title / descriptionstringOption name, title, and description.
groupstringCurrent option group.
typestringbool, int, fixed, string, button, group, or unknown.
unitstringSANE unit.
valueanyCurrent value parsed as JSON.
constraintobjectConstraint information.
readonly / settablebooleanWhether the option is read-only / settable.
automatic / inactive / advancedbooleanSANE capability flags.
requires_reloadbooleanWhether options should be reloaded after setting.

constraint fields:

FieldTypeNotes
typestringnone, range, list, or string_list.
min / max / quantnumberRange constraint.
values[]arrayEnumerated values parsed as JSON.

sane.set_options accepts two option shapes:

json
{
  "resolution": 300,
  "mode": "Color"
}
json
[
  { "key": "resolution", "value": 300 },
  { "index": 3, "value": "Color" }
]

results[] fields:

FieldTypeNotes
keystringKey provided in the set request.
indexnumberMatched option index.
statusstringapplied or rejected.
messagestringResult message.
valueanyValue used for this set attempt.
inexactbooleanWhether the SANE backend adjusted the value approximately.
requires_reloadbooleanWhether options should be reloaded.

profile fields:

FieldTypeNotes
profile_idstringProfile ID. Generated as sane-profile-N when omitted.
device_keystringDevice key from device_key, device_id, or device_name.
namestringProfile name.
optionsobjectSaved option values keyed by option key or index.
created_at / updated_atstringCreated and updated timestamps.

Scan Tasks

sane.scan first saves SANE scan output as page images, then processes final output according to output_type:

Output targetBehavior
output_type=imagesReturns scanned page images directly; output_format defaults to jpg.
output_type=pdf / ofd / tiffScans page images first, then calls file conversion after scan completion to generate the target document.
pipelineRuns image enhancement after scanned page images are available, then writes the target output. See Image API / ImageEnhancePipeline.

The output object can override top-level output parameters: type, format, path, dir, and export_type. If pipeline.target specifies a valid target, it can also override the scan output target.

The number of scanned pages is controlled by scanner options such as source: ADF-like sources scan continuously, while non-ADF sources usually scan one page. One task has an internal limit of 1000 pages.

task fields:

FieldTypeNotes
task_idstringScan task ID, such as sane-scan-1.
connection_idstringCommand WS connection ID that created the task.
session_idstringScanner session ID.
statusstringqueued, running, enhancing, converting, completed, failed, or cancelled.
phasestringCurrent phase, such as queued, applying-options, scanning, saving-page, enhancing, converting, or completed.
progressnumberProgress from 0 to 100.
page_count / current_pagenumberOutput page count and current scan page.
output_type / output_formatstringOutput target type and format.
output_dirstringOutput directory.
export_typestringsingle-page or multi-page.
output_pathstringMain output path.
output_paths[]string[]All output paths.
last_page_pathstringMost recently saved scanned page path.
assets[]arrayOutput assets registered in the local asset service, including url and download_url.
message / errorstringCurrent message and failure reason.
started_at / updated_atstringTask timestamps.
cancel_requestedbooleanWhether cancellation was requested.

Scan task event is sane.scan_changed; payload contains task_id, task, and provider.

Request Examples

Get status and list devices:

json
{ "request_id": "req-sane-status-001", "method": "sane.status", "params": {} }
{ "request_id": "req-sane-list-001", "method": "sane.list", "params": { "refresh": true, "include_detected": true } }

Open a device and set options:

json
{
  "request_id": "req-sane-open-001",
  "method": "sane.open",
  "params": {
    "device_id": "sane:scanner:001"
  }
}
json
{
  "request_id": "req-sane-set-001",
  "method": "sane.set_options",
  "params": {
    "session_id": "sane-session-1",
    "options": {
      "resolution": 300,
      "mode": "Color"
    }
  }
}

Save and apply a profile:

json
{
  "request_id": "req-sane-profile-save-001",
  "method": "sane.profile_save",
  "params": {
    "session_id": "sane-session-1",
    "device_id": "sane:scanner:001",
    "name": "Color 300dpi",
    "options": {
      "resolution": 300,
      "mode": "Color"
    }
  }
}
json
{
  "request_id": "req-sane-profile-apply-001",
  "method": "sane.profile_apply",
  "params": {
    "session_id": "sane-session-1",
    "profile_id": "sane-profile-1"
  }
}

Submit an image scan task:

json
{
  "request_id": "req-sane-scan-001",
  "method": "sane.scan",
  "params": {
    "session_id": "sane-session-1",
    "output": {
      "type": "images",
      "format": "jpg",
      "dir": "/tmp/sdk-sane-pages",
      "export_type": "single-page"
    }
  }
}

Submit a PDF scan task with image enhancement:

json
{
  "request_id": "req-sane-scan-002",
  "method": "sane.scan",
  "params": {
    "session_id": "sane-session-1",
    "output": {
      "type": "pdf",
      "path": "/tmp/sdk-sane-output/scan.pdf",
      "export_type": "multi-page"
    },
    "pipeline": {
      "version": "image.enhance.pipeline.v1",
      "steps": [
        { "type": "blank_page_detect", "params": { "action": "drop" } }
      ],
      "target": {
        "type": "pdf",
        "path": "/tmp/sdk-sane-output/scan.pdf",
        "export_type": "multi-page"
      }
    }
  }
}

Get and cancel a scan task:

json
{ "request_id": "req-sane-get-001", "method": "sane.scan_get", "params": { "task_id": "sane-scan-1" } }
{ "request_id": "req-sane-cancel-001", "method": "sane.scan_cancel", "params": { "task_id": "sane-scan-1" } }

CZUR Open Platform Documentation