openharmony 鸿蒙 capi-ohscan-h

2026-08-25 浏览 (1)

ohscan.h

Overview

Declares APIs for discovering and connecting to scanners, scanning pictures, querying the scan progress, and setting parameters for scanning.

File to include: <BasicServicesKit/ohscan.h>

Library: libohscan.so

System capability: SystemCapability.Print.PrintFramework

Since: 12

Related module: OH_Scan

Summary

Structs

Nametypedef KeywordDescription
Scan_ScannerDeviceScan_ScannerDeviceDefines scanner information.
Scan_PictureScanProgressScan_PictureScanProgressDefines the progress of scanning a picture by the scanner.
Scan_ScannerOptionsScan_ScannerOptionsDefines all parameter options of a scanner.

Enums

Nametypedef KeywordDescription
Scan_ErrorCodeScan_ErrorCodeEnumerates the error codes.

Functions

Nametypedef KeywordDescription
typedef void (*Scan_ScannerDiscoveryCallback)(Scan_ScannerDevice** devices, int32_t deviceCount)Scan_ScannerDiscoveryCallbackDiscovers scanners. The memory pointed to by the pointer registered via OH_Scan_StartScannerDiscovery will be released when the callback function ends.
int32_t OH_Scan_Init()-Initiates the scan service, initializes the scan client, and connects the client to the scan service.
int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)-Starts scanner discovery and registers a callback used to process the discovered scanners.
int32_t OH_Scan_OpenScanner(const char* scannerId)-Opens a scanner.
int32_t OH_Scan_CloseScanner(const char* scannerId)-Closes a connected scanner.
Scan_ScannerOptions* OH_Scan_GetScannerParameter(const char* scannerId, int32_t* errorCode)-Obtains the scanner setting options. The memory to which the returned struct pointer points is automatically released when OH_Scan_Exit is called. Only one copy of each scanner model is stored in the memory.
int32_t OH_Scan_SetScannerParameter(const char* scannerId, const int32_t option, const char* value)-Sets the option parameters of a scanner. The option values are obtained through the OH_Scan_GetScannerParameter API.
int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode)-Starts scanning.
int32_t OH_Scan_CancelScan(const char* scannerId)-Cancels scanning.
int32_t OH_Scan_GetPictureScanProgress(const char* scannerId, Scan_PictureScanProgress* prog)-Obtains the progress of scanning a picture by the scanner. A non-null value must be passed. The scan progress will be written into the struct pointed to by the pointer.
int32_t OH_Scan_Exit()-Exits the scan service, releases the memory of the scan framework, and deregisters the scanner discovery callback.

Enum Description

Scan_ErrorCode

enum Scan_ErrorCode

Description

Enumerates the error codes.

Since: 12

Enum ItemDescription
SCAN_ERROR_NONE = 0Operation successful.
SCAN_ERROR_NO_PERMISSION = 201Permission verification failed.
SCAN_ERROR_INVALID_PARAMETER = 401Invalid parameter. For example, the pointer or string is null.
SCAN_ERROR_GENERIC_FAILURE = 24300101Internal error.
SCAN_ERROR_RPC_FAILURE = 24300102RPC communication error.
SCAN_ERROR_SERVER_FAILURE = 24300103Server error.
SCAN_ERROR_UNSUPPORTED = 24300104Unsupported operation.
SCAN_ERROR_CANCELED = 24300105Operation canceled.
SCAN_ERROR_DEVICE_BUSY = 24300106Device busy.
SCAN_ERROR_INVALID = 24300107Invalid data (for example, no device is available when the scanner is started).
SCAN_ERROR_JAMMED = 24300108Paper jam in feeder.
SCAN_ERROR_NO_DOCS = 24300109Out of paper.
SCAN_ERROR_COVER_OPEN = 24300110Scanner cover open.
SCAN_ERROR_IO_ERROR = 24300111Scanner I/O error.
SCAN_ERROR_NO_MEMORY = 24300112Insufficient memory.

Function Description

Scan_ScannerDiscoveryCallback()

typedef void (*Scan_ScannerDiscoveryCallback)(Scan_ScannerDevice** devices, int32_t deviceCount)

Description

Discovers scanners. The memory pointed to by the pointer registered via OH_Scan_StartScannerDiscovery will be released when the callback function ends.

Since: 12

Parameters

NameDescription
Scan_ScannerDevice** devicesDouble pointer to the list of all discovered scanners.
int32_t deviceCountNumber of scanners discovered.

OH_Scan_Init()

int32_t OH_Scan_Init()

Description

Initiates the scan service, initializes the scan client, and connects the client to the scan service.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.

OH_Scan_StartScannerDiscovery()

int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)

Description

Starts scanner discovery and registers a callback used to process the discovered scanners.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
Scan_ScannerDiscoveryCallback callbackScan_ScannerDiscoveryCallback used to discover scanners.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.

OH_Scan_OpenScanner()

int32_t OH_Scan_OpenScanner(const char* scannerId)

Description

Opens a scanner.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_DEVICE_BUSY: device busy.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.
SCAN_ERROR_IO_ERROR: scanner I/O error.
SCAN_ERROR_NO_MEMORY: insufficient memory.

OH_Scan_CloseScanner()

int32_t OH_Scan_CloseScanner(const char* scannerId)

Description

Closes a connected scanner.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.

OH_Scan_GetScannerParameter()

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

Description

Obtains the scanner setting options. The memory to which the returned struct pointer points is automatically released when OH_Scan_Exit is called. Only one copy of each scanner model is stored in the memory.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.
int32_t* errorCodePointer to the error code. If the operation is successful, SCAN_ERROR_NONE is returned; otherwise, a specific error code is returned. For details, see Print_ErrorCode.

Returns

TypeDescription
Scan_ScannerOptions*SCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.

OH_Scan_SetScannerParameter()

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

Description

Sets the option parameters of a scanner. The option values are obtained through the OH_Scan_GetScannerParameter API.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.
const int32_t optionID of the option to be set. The value, obtained from Scan_ScannerOptions, ranges from 0 to optionCount – 1.
const char* valuePointer to the option value to be set. The valid value is obtained from ranges of Scan_ScannerOptions.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.

OH_Scan_StartScan()

int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode)

Description

Starts scanning.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.
bool batchModeWhether to start the scanner in batch processing mode.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_JAMMED: paper jam in feeder.
SCAN_ERROR_NO_DOCS: out of paper.
SCAN_ERROR_COVER_OPEN: scanner cover open.
SCAN_ERROR_IO_ERROR: scanner I/O error.
SCAN_ERROR_NO_MEMORY: insufficient memory.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.
SCAN_ERROR_DEVICE_BUSY: device busy.

OH_Scan_CancelScan()

int32_t OH_Scan_CancelScan(const char* scannerId)

Description

Cancels scanning.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.

OH_Scan_GetPictureScanProgress()

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

Description

Obtains the progress of scanning a picture by the scanner. A non-null value must be passed. The scan progress will be written into the struct pointed to by the pointer.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Parameters

NameDescription
const char* scannerIdPointer to the scanner ID.
Scan_PictureScanProgress* progPointer to Scan_PictureScanProgress. The value cannot be empty.

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_INVALID_PARAMETER: invalid parameter.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.
SCAN_ERROR_JAMMED: paper jam in feeder.
SCAN_ERROR_NO_DOCS: out of paper.
SCAN_ERROR_COVER_OPEN: scanner cover open.
SCAN_ERROR_IO_ERROR: scanner I/O error.
SCAN_ERROR_NO_MEMORY: insufficient memory.
SCAN_ERROR_DEVICE_BUSY: device busy.

OH_Scan_Exit()

int32_t OH_Scan_Exit()

Description

Exits the scan service, releases the memory of the scan framework, and deregisters the scanner discovery callback.

System capability: SystemCapability.Print.PrintFramework

Required permissions: ohos.permission.PRINT

Since: 12

Returns

TypeDescription
int32_tSCAN_ERROR_NONE: operation successful.
SCAN_ERROR_NO_PERMISSION: permission denied.
SCAN_ERROR_RPC_FAILURE: RPC communication error.
SCAN_ERROR_SERVER_FAILURE: server error.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-zlib

openharmony 鸿蒙 capi-oh-scan-scan-picturescanprogress

openharmony 鸿蒙 js-apis-screen-lock

openharmony 鸿蒙 capi-os-account-common-h

openharmony 鸿蒙 js-apis-screen-lock-sys

openharmony 鸿蒙 capi-oh-print-print-propertylist

openharmony 鸿蒙 capi-oh-scan

openharmony 鸿蒙 js-apis-system-device

openharmony 鸿蒙 errorcode-intelligentVoice

openharmony 鸿蒙 js-apis-request-sys

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