harmony 鸿蒙OH_Scan

2025-06-12 浏览 (1)

OH_Scan

Overview

Enables applications to use CAPI to access scanners.

Since: 12

Summary

Types

NameDescription
Scan_ScannerDeviceDefines the device information of a scanner.
Scan_PictureScanProgressDefines the image scanning progress.
Scan_ScannerOptionsDefines the scanner options.
Scan_ScannerDiscoveryCallbackDefines a callback to be invoked when a scanner is discovered.

Enums

NameDescription
Scan_ErrorCodeEnumerates the error codes.

Functions

NameDescription
OH_Scan_InitStarts the scanning service, initializes the client, and establishes a connection with the scanning service.
OH_Scan_StartScannerDiscoverySearches for scanners and registers a callback function to process the found scanners.
OH_Scan_OpenScannerConnects to a scanner.
OH_Scan_CloseScannerDisconnects from the scanner.
OH_Scan_GetScannerParameterObtains scanner settings.
OH_Scan_SetScannerParameterSets the option parameters of the scanner.
OH_Scan_StartScanStarts the scanner.
OH_Scan_CancelScanCancels scanning.
OH_Scan_GetPictureScanProgressQueries the image scanning progress.
OH_Scan_ExitExits the scanning service and releases the client memory.

Type Description

Scan_ScannerDevice

Description

Defines the device information of a scanner.

Since: 12

MemberDescription
scannerIdScanner ID.
manufacturerManufacturer.
modelDevice model.
discoverModeDevice discovery mode.
serialNumberSerial number.

Scan_PictureScanProgress

Description

Defines the image scanning progress.

Since: 12

MemberDescription
progressImage scanning progress. The value ranges from 0 to 100.
fdImage file handle.
isFinalWhether the next image is available.

Scan_ScannerOptions

Description

Defines the scanner options.

Since: 12

MemberDescription
titlesOption titles.
descriptionsDescriptions of options.
rangesOption ranges.
optionCountNumber of options.

Scan_ScannerDiscoveryCallback

Description

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

Since: 12

ParameterDescription
devicesScanner.
deviceCountNumber of scanners.

Enum Description

Scan_ErrorCode

Description

Enumerates the error codes.

Since: 12

ValueDescription
SCAN_ERROR_NONEOperation succeeded.
SCAN_ERROR_NO_PERMISSIONPermission denied.
SCAN_ERROR_INVALID_PARAMETERInvalid parameter.
SCAN_ERROR_GENERIC_FAILUREInternal error.
SCAN_ERROR_RPC_FAILUREPRC communication error.
SCAN_ERROR_SERVER_FAILUREServer error.
SCAN_ERROR_UNSUPPORTEDOperation is not supported.
SCAN_ERROR_CANCELEDOperation canceled.
SCAN_ERROR_DEVICE_BUSYDevice is busy.
SCAN_ERROR_INVALIDInvalid operation.
SCAN_ERROR_JAMMEDPaper jammed at the paper feeder.
SCAN_ERROR_NO_DOCSOut of paper.
SCAN_ERROR_COVER_OPENThe cover of the scanner is opened.
SCAN_ERROR_IO_ERRORScanner I/O operation error.
SCAN_ERROR_NO_MEMORYInsufficient 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

NameDescription
callbackCallback 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

NameDescription
scannerIdScanner 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

NameDescription
scannerIdScanner 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

NameDescription
scannerIdScanner ID.
errorCodeError 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

NameDescription
scannerIdScanner ID.
optionOption Number.
valueOption 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

NameDescription
scannerIdScanner ID.
batchModeBatch 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

NameDescription
scannerIdScanner 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

NameDescription
scannerIdScanner ID.
progImage 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

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/ZjNS8A