Scan
>w## Notice
> * please include the header file "bwsdk_api.h" first when you want to use scanbar
`#include "bwsdk_api.h"`
### data structure
```
#define SCANBAR_RLED (0x01) ///< RED LED
#define SCANBAR_WLED (0x02) ///< WRITE LED
typedef enum
{
BARSCAN_MODE_CONTINUE = 0,
BARSCAN_MODE_ONCE = 1,
BARSCAN_MODE_MOTIONDETECT = 2,
BARSCAN_MODE_ONED_ONLY = 3,
BARSCAN_MODE_MOTIONDETECT_MINI = 4,
BARSCAN_MODE_MAX,
MERCURY_ENUM_BARSCAN_MODE_MAX = 0x7fffffff
}BARSCAN_MODE_VALUE_E;
typedef enum
{
BARSCAN_FEATURE_ALL = 0,
BARSCAN_FEATURE_PAY,
BARSCAN_FEATURE_BOX_PAY,
BARSCAN_FEATURE_MAX,
MERCURY_ENUM_FEATURE_MAX = 0x7fffffff
}BARSCAN_FEATURE_CONFIGURE_E;
/**
* @brief ScanBar parameter
*/
typedef struct {
int power_mode; ///< 0 - Abort after success, 1 - Suspend after success
int scan_mode; ///< refer BARSCAN_MODE_VALUE_E, Scan mode
int feature; ///< refer BARSCAN_FEATURE_CONFIGURE_E, Scan feature config
} scanbar_param_t;
```
>i## ScanBarSetParam
### Prototype
`void ScanBarSetParam(scanbar_param_t *param);`
### Function
* set scanbar parameter
### Parameter
|Name|Type|description|
|-|-|-|
|param|scanbar_param_t *|scanbar parameter structure|
### Retval
|Value|Type|Description|
|-|-|-|
|none|||
>i## ScanBarEnableNoticeTone
### Prototype
`void ScanBarEnableNoticeTone(int onoff);`
### Function
* set scanbar notice tone on or off
### Parameter
|Name|Type|description|
|-|-|-|
|onoff|int|1-on; 0-off|
### Retval
|Value|Type|Description|
|-|-|-|
|none|||
>i## ScanBarStart
### Prototype
`int ScanBarStart(void);`
### Function
* start scanbar
### Parameter
|Name|Type|description|
|-|-|-|
|none|||
### Retval
|Value|Type|Description|
|-|-|-|
|0|int|SUCCESS|
|-1|int|fail|
>i## ScanBarGetData
### Prototype
`int ScanBarGetData(unsigned char *pdata, int buf_sz, int tov_ms);`
### Function
* get scanbar data
### Parameter
|Name|Type|description|
|-|-|-|
|pdata|unsigned char *|scanbar data buffer|
|buf_sz|int|pdata buffer size|
|tov_ms|int|timeout time ms|
### Retval
|Value|Type|Description|
|-|-|-|
|>0|int|scanbar data length|
|=0|int|timeout|
|<0|int|error|
>i## ScanBarPause
### Prototype
`int ScanBarPause(void);`
### Function
* pause scanbar
### Parameter
|Name|Type|description|
|-|-|-|
|none|||
### Retval
|Value|Type|Description|
|-|-|-|
|=0|int|SUCCESS|
|<0|int|fail|
>i## ScanBarStop
### Prototype
`int ScanBarStop(void);`
### Function
* stop scanbar
### Parameter
|Name|Type|description|
|-|-|-|
|none|||
### Retval
|Value|Type|Description|
|-|-|-|
|=0|int|SUCCESS|
|<0|int|fail|
>i## ScanBarLightSet
### Prototype
`int ScanBarLightSet(unsigned int conf_param, unsigned int onoff);`
### Function
* set scanbar light on or off
### Parameter
|Name|Type|description|
|-|-|-|
|conf_param|unsigned int|SCANBAR_RLED, SCANBAR_WLED|
|onoff|unsigned int|1-on; 0-off|
### Retval
|Value|Type|Description|
|-|-|-|
|=0|int|SUCCESS|
|<0|int|fail|
>s## Example
```
///< set scanbar param
scanbar_param_t barcfg = {1, BARSCAN_MODE_ONCE, BARSCAN_FEATURE_ALL};
ScanBarSetParam(&barcfg);
///< set scanbar notice tone on
ScanBarEnableNoticeTone(1);
///< start scanbar
int iRet = 0;
iRet = ScanBarStart();
///< set scanbar notice tone on
int iLen = 0, iRet = 0;
unsigned char barBuff[256] = {0};
///< open scanbar
iRet = ScanBarStart();
if (iRet < 0)
{
return iRet;
}
///< turn on scanbar light
ScanBarLightSet(SCANBAR_WLED | SCANBAR_RLED, 1);
while (1)
{
iLen = ScanBarGetData(barBuff, sizeof(barBuff), 500);
///< success
if (iLen > 0)
{
break;
}
///< error
else if (iLen < 0)
{
break;
}
///< timeout
else
{
continue;
}
}
///< turn off scanbar light
ScanBarLightSet(SCANBAR_WLED | SCANBAR_RLED, 0);
///< close scanbar
ScanBarStop();
///< pause scanbar
int iRet = 0;
iRet = ScanBarPause();
///< stop scanbar
int iRet = 0;
iRet = ScanBarStop();
///< set scanbar light on
int iRet = 0;
iRet = ScanBarLightSet(SCANBAR_WLED | SCANBAR_RLED, 1);
```