harmony 鸿蒙OH_Scan

  • 2025-06-12
  • 浏览 (5)

OH_Scan

Overview

Enables applications to use CAPI to access scanners.

Since: 12

Summary

Types

Name Description
Scan_ScannerDevice Defines the device information of a scanner.
Scan_PictureScanProgress Defines the image scanning progress.
Scan_ScannerOptions Defines the scanner options.
Scan_ScannerDiscoveryCallback Defines a callback to be invoked when a scanner is discovered.

Enums

Name Description
Scan_ErrorCode Enumerates the error codes.

Functions

Name Description
OH_Scan_Init Starts the scanning service, initializes the client, and establishes a connection with the scanning service.
OH_Scan_StartScannerDiscovery Searches for scanners and registers a callback function to process the found scanners.
OH_Scan_OpenScanner Connects to a scanner.
OH_Scan_CloseScanner Disconnects from the scanner.
OH_Scan_GetScannerParameter Obtains scanner settings.
OH_Scan_SetScannerParameter Sets the option parameters of the scanner.
OH_Scan_StartScan Starts the scanner.
OH_Scan_CancelScan Cancels scanning.
OH_Scan_GetPictureScanProgress Queries the image scanning progress.
OH_Scan_Exit Exits the scanning service and releases the client memory.

Type Description

Scan_ScannerDevice

Description

Defines the device information of a scanner.

Since: 12

Member Description
scannerId Scanner ID.
manufacturer Manufacturer.
model Device model.
discoverMode Device discovery mode.
serialNumber Serial number.

Scan_PictureScanProgress

Description

Defines the image scanning progress.

Since: 12

Member Description
progress Image scanning progress. The value ranges from 0 to 100.
fd Image file handle.
isFinal Whether the next image is available.

Scan_ScannerOptions

Description

Defines the scanner options.

Since: 12

Member Description
titles Option titles.
descriptions Descriptions of options.
ranges Option ranges.
optionCount Number of options.

Scan_ScannerDiscoveryCallback

Description

Defines a callback to be invoked when a scanner is discovered.

Since: 12

Parameter Description
devices Scanner.
deviceCount Number of scanners.

Enum Description

Scan_ErrorCode

Description

Enumerates the error codes.

Since: 12

Value Description
SCAN_ERROR_NONE Operation succeeded.
SCAN_ERROR_NO_PERMISSION Permission denied.
SCAN_ERROR_INVALID_PARAMETER Invalid parameter.
SCAN_ERROR_GENERIC_FAILURE Internal error.
SCAN_ERROR_RPC_FAILURE PRC communication error.
SCAN_ERROR_SERVER_FAILURE Server error.
SCAN_ERROR_UNSUPPORTED Operation is not supported.
SCAN_ERROR_CANCELED Operation canceled.
SCAN_ERROR_DEVICE_BUSY Device is busy.
SCAN_ERROR_INVALID Invalid operation.
SCAN_ERROR_JAMMED Paper jammed at the paper feeder.
SCAN_ERROR_NO_DOCS Out of paper.
SCAN_ERROR_COVER_OPEN The cover of the scanner is opened.
SCAN_ERROR_IO_ERROR Scanner I/O operation error.
SCAN_ERROR_NO_MEMORY Insufficient memory.

Function Description

OH_Scan_Init()

int32_t OH_Scan_Init();

Description

Starts the scanning service, initializes the client, and establishes a connection with the scanning service.

System capability: ohos.permission.PRINT

Since: 12

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

OH_Scan_StartScannerDiscovery()

int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback);

Description

Searches for scanners and registers a callback function to process the found scanners.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
callback Callback function for scanner discovery.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

OH_Scan_OpenScanner()

int32_t OH_Scan_OpenScanner(const char* scannerId);

Description

Connects to a scanner.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_DEVICE_BUSY: The scanner is busy.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

SCAN_ERROR_IO_ERROR: An I/O operation error occurs on the scanner.

SCAN_ERROR_NO_MEMORY: The scanner memory is insufficient.

OH_Scan_CloseScanner()

int32_t OH_Scan_CloseScanner(const char* scannerId);

Description

Disconnects from a scanner.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

OH_Scan_GetScannerParameter()

Scan_ScannerOptions* OH_Scan_GetScannerParameter(const char* scannerId, int32_t* errorCode);

Description

Obtains the scanner setting options. The memory is automatically released when returned structure points to {@link OH_Scan_Exit}. Only one copy of each scanner model is stored in the memory.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.
errorCode Error code.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

OH_Scan_SetScannerParameter()

int32_t OH_Scan_SetScannerParameter(const char* scannerId, const int32_t option, const char* value);

Description

Sets the option parameters of the scanner. The option values are obtained through the {@link OH_Scan_GetScannerParameter} API.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.
option Option Number.
value Option value.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

OH_Scan_StartScan()

int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode);

Description

Starts a scanner.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.
batchMode Batch processing mode.

Returns

Scan_ERROR_NONE: Operation is succeeded. SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

SCAN_ERROR_JAMMED: Paper jammed at the paper feeder.

SCAN_ERROR_NO_DOCS: The scanner is out of paper.

SCAN_ERROR_COVER_OPEN: The cover of the scanner is opened.

SCAN_ERROR_IO_ERROR: An I/O operation exception occurs on the scanner.

SCAN_ERROR_NO_MEMORY: The scanner memory is insufficient.

SCAN_ERROR_DEVICE_BUSY: The scanner is busy.

OH_Scan_CancelScan()

int32_t OH_Scan_CancelScan(const char* scannerId);

Description

Cancels scanning.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

OH_Scan_GetPictureScanProgress()

int32_t OH_Scan_GetPictureScanProgress(const char* scannerId, Scan_PictureScanProgress* prog);

Description

Queries the image scanning progress.

System capability: ohos.permission.PRINT

Since: 12

Parameters

Name Description
scannerId Scanner ID.
prog Image scanning progress.

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

SCAN_ERROR_JAMMED: Paper jammed at the paper feeder.

SCAN_ERROR_NO_DOCS: The scanner is out of paper.

SCAN_ERROR_COVER_OPEN: The cover of the scanner is opened.

SCAN_ERROR_IO_ERROR: An I/O operation exception occurs on the scanner.

SCAN_ERROR_NO_MEMORY: The scanner memory is insufficient.

SCAN_ERROR_DEVICE_BUSY: The scanner is busy.

OH_Scan_Exit()

int32_t OH_Scan_Exit();

Description

Exits the scanning service, clear the client memory, and cancel the registered scanning callback function.

System capability: ohos.permission.PRINT

Since: 12

Returns

Scan_ERROR_NONE: Operation is succeeded.

SCAN_ERROR_NO_PERMISSION: Permission is denied.

SCAN_ERROR_RPC_FAILURE: An RPC communication error occurs.

SCAN_ERROR_SERVER_FAILURE: A server exception occurs.

SCAN_ERROR_INVALID_PARAMETER: The parameter is invalid.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit

harmony 鸿蒙DeviceInfo

harmony 鸿蒙InitSync

harmony 鸿蒙OH_Print

harmony 鸿蒙OsAccount

harmony 鸿蒙Pasteboard

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

0  赞