1# OH_Scan 2 3 4## Overview 5 6Enables applications to use CAPI to access scanners. 7 8**Since**: 12 9 10 11## Summary 12 13 14### Types 15 16| Name| Description| 17| -------- | -------- | 18| [Scan_ScannerDevice](#scan_scannerdevice) | Defines the device information of a scanner.| 19| [Scan_PictureScanProgress](#scan_picturescanprogress) | Defines the image scanning progress.| 20| [Scan_ScannerOptions](#scan_scanneroptions) | Defines the scanner options.| 21| [Scan_ScannerDiscoveryCallback](#scan_scannerdiscoverycallback) | Defines a callback to be invoked when a scanner is discovered.| 22 23 24### Enums 25 26| Name| Description| 27| -------- | -------- | 28| [Scan_ErrorCode](#scan_errorcode) | Enumerates the error codes.| 29 30 31### Functions 32 33| Name| Description| 34| -------- | -------- | 35| [OH_Scan_Init](#oh_scan_init) | Starts the scanning service, initializes the client, and establishes a connection with the scanning service.| 36| [OH_Scan_StartScannerDiscovery](#oh_scan_startscannerdiscovery) | Searches for scanners and registers a callback function to process the found scanners.| 37| [OH_Scan_OpenScanner](#oh_scan_openscanner) | Connects to a scanner.| 38| [OH_Scan_CloseScanner](#oh_scan_closescanner) | Disconnects from the scanner.| 39| [OH_Scan_GetScannerParameter](#oh_scan_getscannerparameter) | Obtains scanner settings.| 40| [OH_Scan_SetScannerParameter](#oh_scan_setscannerparameter) | Sets the option parameters of the scanner.| 41| [OH_Scan_StartScan](#oh_scan_startscan) | Starts the scanner.| 42| [OH_Scan_CancelScan](#oh_scan_cancelscan) | Cancels scanning.| 43| [OH_Scan_GetPictureScanProgress](#oh_scan_getpicturescanprogress) | Queries the image scanning progress.| 44| [OH_Scan_Exit](#oh_scan_exit) | Exits the scanning service and releases the client memory.| 45 46 47## Type Description 48 49 50### Scan_ScannerDevice 51 52**Description** 53 54Defines the device information of a scanner. 55 56**Since**: 12 57 58| Member | Description | 59| ------------ | -------- | 60| scannerId | Scanner ID.| 61| manufacturer | Manufacturer. | 62| model | Device model.| 63| discoverMode | Device discovery mode.| 64| serialNumber | Serial number. | 65 66### Scan_PictureScanProgress 67 68**Description** 69 70Defines the image scanning progress. 71 72**Since**: 12 73 74| Member | Description | 75| -------- | ----------------------- | 76| progress | Image scanning progress. The value ranges from 0 to 100.| 77| fd | Image file handle. | 78| isFinal | Whether the next image is available. | 79 80### Scan_ScannerOptions 81 82**Description** 83 84Defines the scanner options. 85 86**Since**: 12 87 88| Member | Description | 89| ------------ | ------------ | 90| titles | Option titles. | 91| descriptions | Descriptions of options.| 92| ranges | Option ranges. | 93| optionCount | Number of options. | 94 95### Scan_ScannerDiscoveryCallback 96 97**Description** 98 99Defines a callback to be invoked when a scanner is discovered. 100 101**Since**: 12 102 103| Parameter | Description | 104| ----------- | ---------- | 105| devices | Scanner.| 106| deviceCount | Number of scanners. | 107 108## Enum Description 109 110 111### Scan_ErrorCode 112 113**Description** 114 115Enumerates the error codes. 116 117**Since**: 12 118 119| Value| Description| 120| -------- | -------- | 121| SCAN_ERROR_NONE | Operation succeeded.| 122| SCAN_ERROR_NO_PERMISSION | Permission denied.| 123| SCAN_ERROR_INVALID_PARAMETER | Invalid parameter.| 124| SCAN_ERROR_GENERIC_FAILURE | Internal error.| 125| SCAN_ERROR_RPC_FAILURE | PRC communication error.| 126| SCAN_ERROR_SERVER_FAILURE | Server error.| 127| SCAN_ERROR_UNSUPPORTED | Operation is not supported.| 128| SCAN_ERROR_CANCELED | Operation canceled.| 129| SCAN_ERROR_DEVICE_BUSY | Device is busy.| 130| SCAN_ERROR_INVALID | Invalid operation.| 131| SCAN_ERROR_JAMMED | Paper jammed at the paper feeder.| 132| SCAN_ERROR_NO_DOCS | Out of paper.| 133| SCAN_ERROR_COVER_OPEN | The cover of the scanner is opened.| 134| SCAN_ERROR_IO_ERROR | Scanner I/O operation error.| 135| SCAN_ERROR_NO_MEMORY | Insufficient memory.| 136 137 138## Function Description 139 140 141### OH_Scan_Init() 142 143```cpp 144int32_t OH_Scan_Init(); 145``` 146 147**Description** 148 149Starts the scanning service, initializes the client, and establishes a connection with the scanning service. 150 151**System capability**: ohos.permission.PRINT 152 153**Since**: 12 154 155**Returns** 156 157**Scan_ERROR_NONE**: Operation is succeeded. 158 159**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 160 161**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 162 163**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 164 165### OH_Scan_StartScannerDiscovery() 166 167```cpp 168int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback); 169``` 170 171**Description** 172 173Searches for scanners and registers a callback function to process the found scanners. 174 175**System capability**: ohos.permission.PRINT 176 177**Since**: 12 178 179**Parameters** 180 181| Name | Description | 182| -------- | -------------------------- | 183| callback | Callback function for scanner discovery.| 184 185**Returns** 186 187**Scan_ERROR_NONE**: Operation is succeeded. 188 189**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 190 191**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 192 193**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 194 195### OH_Scan_OpenScanner() 196 197```cpp 198int32_t OH_Scan_OpenScanner(const char* scannerId); 199``` 200 201**Description** 202 203Connects to a scanner. 204 205**System capability**: ohos.permission.PRINT 206 207**Since**: 12 208 209**Parameters** 210 211| Name | Description | 212| --------- | ---------- | 213| scannerId | Scanner ID.| 214 215**Returns** 216 217**Scan_ERROR_NONE**: Operation is succeeded. 218 219**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 220 221**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 222 223**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 224 225**SCAN_ERROR_DEVICE_BUSY**: The scanner is busy. 226 227**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 228 229**SCAN_ERROR_IO_ERROR**: An I/O operation error occurs on the scanner. 230 231**SCAN_ERROR_NO_MEMORY**: The scanner memory is insufficient. 232 233### OH_Scan_CloseScanner() 234 235```cpp 236int32_t OH_Scan_CloseScanner(const char* scannerId); 237``` 238 239**Description** 240 241Disconnects from a scanner. 242 243**System capability**: ohos.permission.PRINT 244 245**Since**: 12 246 247**Parameters** 248 249| Name | Description | 250| --------- | ---------- | 251| scannerId | Scanner ID.| 252 253**Returns** 254 255**Scan_ERROR_NONE**: Operation is succeeded. 256 257**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 258 259**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 260 261**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 262 263**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 264 265### OH_Scan_GetScannerParameter() 266 267```cpp 268Scan_ScannerOptions* OH_Scan_GetScannerParameter(const char* scannerId, int32_t* errorCode); 269``` 270 271**Description** 272 273Obtains 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. 274 275**System capability**: ohos.permission.PRINT 276 277**Since**: 12 278 279**Parameters** 280 281| Name | Description | 282| --------- | ---------- | 283| scannerId | Scanner ID.| 284| errorCode | Error code. | 285 286**Returns** 287 288**Scan_ERROR_NONE**: Operation is succeeded. 289 290**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 291 292**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 293 294**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 295 296### OH_Scan_SetScannerParameter() 297 298```cpp 299int32_t OH_Scan_SetScannerParameter(const char* scannerId, const int32_t option, const char* value); 300``` 301 302**Description** 303 304Sets the option parameters of the scanner. The option values are obtained through the {@link OH_Scan_GetScannerParameter} API. 305 306**System capability**: ohos.permission.PRINT 307 308**Since**: 12 309 310**Parameters** 311 312| Name | Description | 313| --------- | ---------- | 314| scannerId | Scanner ID.| 315| option | Option Number. | 316| value | Option value. | 317 318**Returns** 319 320**Scan_ERROR_NONE**: Operation is succeeded. 321 322**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 323 324**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 325 326**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 327 328**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 329 330### OH_Scan_StartScan() 331 332```cpp 333int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode); 334``` 335 336**Description** 337 338Starts a scanner. 339 340**System capability**: ohos.permission.PRINT 341 342**Since**: 12 343 344**Parameters** 345 346| Name | Description | 347| --------- | ---------- | 348| scannerId | Scanner ID.| 349| batchMode | Batch processing mode.| 350 351**Returns** 352 353**Scan_ERROR_NONE**: Operation is succeeded. 354**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 355 356**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 357 358**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 359 360**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 361 362**SCAN_ERROR_JAMMED**: Paper jammed at the paper feeder. 363 364**SCAN_ERROR_NO_DOCS**: The scanner is out of paper. 365 366**SCAN_ERROR_COVER_OPEN**: The cover of the scanner is opened. 367 368**SCAN_ERROR_IO_ERROR**: An I/O operation exception occurs on the scanner. 369 370**SCAN_ERROR_NO_MEMORY**: The scanner memory is insufficient. 371 372**SCAN_ERROR_DEVICE_BUSY**: The scanner is busy. 373 374### OH_Scan_CancelScan() 375 376```cpp 377int32_t OH_Scan_CancelScan(const char* scannerId); 378``` 379 380**Description** 381 382Cancels scanning. 383 384**System capability**: ohos.permission.PRINT 385 386**Since**: 12 387 388**Parameters** 389 390| Name | Description | 391| --------- | ---------- | 392| scannerId | Scanner ID.| 393 394**Returns** 395 396**Scan_ERROR_NONE**: Operation is succeeded. 397 398**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 399 400**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 401 402**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 403 404**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 405 406### OH_Scan_GetPictureScanProgress() 407 408```cpp 409int32_t OH_Scan_GetPictureScanProgress(const char* scannerId, Scan_PictureScanProgress* prog); 410``` 411 412**Description** 413 414Queries the image scanning progress. 415 416**System capability**: ohos.permission.PRINT 417 418**Since**: 12 419 420**Parameters** 421 422| Name | Description | 423| --------- | ------------ | 424| scannerId | Scanner ID. | 425| prog | Image scanning progress.| 426 427**Returns** 428 429**Scan_ERROR_NONE**: Operation is succeeded. 430 431**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 432 433**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 434 435**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 436 437**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 438 439**SCAN_ERROR_JAMMED**: Paper jammed at the paper feeder. 440 441**SCAN_ERROR_NO_DOCS**: The scanner is out of paper. 442 443**SCAN_ERROR_COVER_OPEN**: The cover of the scanner is opened. 444 445**SCAN_ERROR_IO_ERROR**: An I/O operation exception occurs on the scanner. 446 447**SCAN_ERROR_NO_MEMORY**: The scanner memory is insufficient. 448 449**SCAN_ERROR_DEVICE_BUSY**: The scanner is busy. 450 451### OH_Scan_Exit() 452 453```cpp 454int32_t OH_Scan_Exit(); 455``` 456 457**Description** 458 459Exits the scanning service, clear the client memory, and cancel the registered scanning callback function. 460 461**System capability**: ohos.permission.PRINT 462 463**Since**: 12 464 465**Returns** 466 467**Scan_ERROR_NONE**: Operation is succeeded. 468 469**SCAN_ERROR_NO_PERMISSION**: Permission is denied. 470 471**SCAN_ERROR_RPC_FAILURE**: An RPC communication error occurs. 472 473**SCAN_ERROR_SERVER_FAILURE**: A server exception occurs. 474 475**SCAN_ERROR_INVALID_PARAMETER**: The parameter is invalid. 476