调整代码逻辑
This commit is contained in:
parent
f6776c4df8
commit
9363327807
|
@ -7,12 +7,118 @@
|
||||||
#include "huagao/hgscanner_error.h"
|
#include "huagao/hgscanner_error.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int str_to_wchar(std::string str, wchar_t* s, size_t* strlen)
|
||||||
|
{
|
||||||
|
if (str.empty())
|
||||||
|
return ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
|
||||||
|
size_t size = str.length();
|
||||||
|
int len = 0;
|
||||||
|
len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
|
||||||
|
if (*strlen < len)
|
||||||
|
{
|
||||||
|
*strlen = len;
|
||||||
|
return ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, s, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int get_json_config_file()
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
char exePath[256];
|
||||||
|
char* buf = NULL;
|
||||||
|
GetModuleFileNameA(NULL, exePath, 255);
|
||||||
|
(strrchr(exePath, '\\'))[1] = 0; //去掉执行的文件名。
|
||||||
|
|
||||||
|
strcat(exePath, "DLLs\\G302.hsc");
|
||||||
|
FILE* fp = fopen(exePath, "rb");
|
||||||
|
if (fp == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
len = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
buf = new char[len];
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(buf, 0, len);
|
||||||
|
fread(buf, len, 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
std::cout << buf << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::wstring set_test_name_;
|
||||||
class test
|
class test
|
||||||
{
|
{
|
||||||
ui_helper* helper_;
|
ui_helper* helper_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
|
||||||
|
{
|
||||||
|
if (!hdev && !param)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ui_helper* h= (ui_helper*)param;
|
||||||
|
switch (code)
|
||||||
|
{
|
||||||
|
case SANE_EVENT_WORKING:
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SANE_EVENT_SCAN_FINISHED:
|
||||||
|
{
|
||||||
|
std::wstring wstr = L"";
|
||||||
|
size_t len = 0;
|
||||||
|
bool type = false;
|
||||||
|
int ret = str_to_wchar((char*)data, (wchar_t*)wstr.c_str(),&len);
|
||||||
|
if (ret == ERROR_INSUFFICIENT_BUFFER)
|
||||||
|
ret = str_to_wchar((char*)data, (wchar_t*)wstr.c_str(), &len);
|
||||||
|
if (ret == ERROR_INSUFFICIENT_BUFFER)
|
||||||
|
{
|
||||||
|
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)wstr.c_str(), type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_TITLE_SKEW_DETECTION) == 0)
|
||||||
|
{
|
||||||
|
type = strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_PAPER_SKEW) == 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)wstr.c_str(), type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SANE_EVENT_STATUS:
|
||||||
|
{
|
||||||
|
//std::string ret_call_ = (char*)data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SANE_EVENT_ERROR:
|
||||||
|
{
|
||||||
|
//ret_call_ = (char*)data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SANE_EVENT_IMAGE_OK:
|
||||||
|
{
|
||||||
|
//SANE_Image* sane_img = (SANE_Image*)data;
|
||||||
|
//have_img_ = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
test(ui_helper* helper) :helper_(helper)
|
test(ui_helper* helper) :helper_(helper)
|
||||||
{
|
{
|
||||||
|
helper->register_sane_callback(sane_ex_callback, NULL);
|
||||||
init_test_map_();
|
init_test_map_();
|
||||||
}
|
}
|
||||||
~test()
|
~test()
|
||||||
|
@ -20,70 +126,56 @@ public:
|
||||||
|
|
||||||
struct ptrcmp
|
struct ptrcmp
|
||||||
{
|
{
|
||||||
bool operator()(const wchar_t* name1, const wchar_t* name2)const
|
bool operator()(const wchar_t* TITLE1, const wchar_t* TITLE2)const
|
||||||
{
|
{
|
||||||
return wcscmp(name1, name2) < 0;
|
return wcscmp(TITLE1, TITLE2) < 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::map<std::wstring, int(test::*)()> test_map_;
|
std::map<std::wstring, int(test::*)()> test_map_;
|
||||||
void init_test_map_()
|
void init_test_map_()
|
||||||
{
|
{
|
||||||
test_map_[HGPDTTOOLDB_NAME_DIAL_SWITCH] = &test::test_dial_switch;
|
test_map_[HGPDTTOOLDB_TITLE_DIAL_SWITCH] = &test::test_dial_switch;
|
||||||
test_map_[HGPDTTOOLDB_NAME_ROCKER_SWITCH] = &test::test_pocker_switch;
|
test_map_[HGPDTTOOLDB_TITLE_ROCKER_SWITCH] = &test::test_pocker_switch;
|
||||||
test_map_[HGPDTTOOLDB_NAME_BOOT_STATUS] = &test::test_boot_status;
|
test_map_[HGPDTTOOLDB_TITLE_BOOT_STATUS] = &test::test_boot_status;
|
||||||
test_map_[HGPDTTOOLDB_NAME_LCD_DISPLAY] = &test::test_lcd_display;
|
test_map_[HGPDTTOOLDB_TITLE_LCD_DISPLAY] = &test::test_lcd_display;
|
||||||
test_map_[HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH] = &test::tset_clear_paper_path;
|
test_map_[HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH] = &test::tset_clear_paper_path;
|
||||||
test_map_[HGPDTTOOLDB_NAME_KEY_FUNCTION] = &test::test_key_funtion;
|
test_map_[HGPDTTOOLDB_TITLE_KEY_FUNCTION] = &test::test_key_funtion;
|
||||||
test_map_[HGPDTTOOLDB_NAME_COUNTING_MODE] = &test::test_count_mode;
|
test_map_[HGPDTTOOLDB_TITLE_COUNTING_MODE] = &test::test_count_mode;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SKEW_DETECTION] = &test::test_skew_detection;
|
test_map_[HGPDTTOOLDB_TITLE_SKEW_DETECTION] = &test::test_skew_detection;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SEPARATER_MOTOR] = &test::test_separater_motor;
|
test_map_[HGPDTTOOLDB_TITLE_SEPARATER_MOTOR] = &test::test_separater_motor;
|
||||||
test_map_[HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE] = &test::test_cis__original_image;
|
test_map_[HGPDTTOOLDB_TITLE_CIS_ORIGINAL_IMAGE] = &test::test_cis__original_image;
|
||||||
test_map_[HGPDTTOOLDB_NAME_HOST_FAN] = &test::test_host_fan;
|
test_map_[HGPDTTOOLDB_TITLE_HOST_FAN] = &test::test_host_fan;
|
||||||
test_map_[HGPDTTOOLDB_NAME_ULTRASONIC_MODULE] = &test::test_ultrasonic_module;
|
test_map_[HGPDTTOOLDB_TITLE_ULTRASONIC_MODULE] = &test::test_ultrasonic_module;
|
||||||
test_map_[HGPDTTOOLDB_NAME_LED_LIGHT] = &test::test_led_light;
|
test_map_[HGPDTTOOLDB_TITLE_LED_LIGHT] = &test::test_led_light;
|
||||||
test_map_[HGPDTTOOLDB_NAME_RESET] = &test::test_reset;
|
test_map_[HGPDTTOOLDB_TITLE_RESET] = &test::test_reset;
|
||||||
test_map_[HGPDTTOOLDB_NAME_PAPER_FEED] = &test::test_paper_feed;
|
test_map_[HGPDTTOOLDB_TITLE_PAPER_FEED] = &test::test_paper_feed;
|
||||||
test_map_[HGPDTTOOLDB_NAME_COVER_SENSOR] = &test::test_cover_sensor;
|
test_map_[HGPDTTOOLDB_TITLE_COVER_SENSOR] = &test::test_cover_sensor;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SCANNING_SENSOR] = &test::test_scanning_sensor;
|
test_map_[HGPDTTOOLDB_TITLE_SCANNING_SENSOR] = &test::test_scanning_sensor;
|
||||||
test_map_[HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE] = &test::test_configure_speed_mode;
|
test_map_[HGPDTTOOLDB_TITLE_CONFIGURE_SPEED_MODE] = &test::test_configure_speed_mode;
|
||||||
test_map_[HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER] = &test::test_place_correction_paper;
|
test_map_[HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER] = &test::test_place_correction_paper;
|
||||||
test_map_[HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD] = &test::test_auto_flat_field;
|
test_map_[HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD] = &test::test_auto_flat_field;
|
||||||
test_map_[HGPDTTOOLDB_NAME_REBOOT_DEVICE] = &test::test_reboot_device;
|
test_map_[HGPDTTOOLDB_TITLE_REBOOT_DEVICE] = &test::test_reboot_device;
|
||||||
test_map_[HGPDTTOOLDB_NAME_IMAGE_QUALITY] = &test::test_image_quality;
|
test_map_[HGPDTTOOLDB_TITLE_IMAGE_QUALITY] = &test::test_image_quality;
|
||||||
test_map_[HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY] = &test::test_colorcard_imageing_quality;
|
test_map_[HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY] = &test::test_colorcard_imageing_quality;
|
||||||
test_map_[HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY] = &test::test_colorcard_bias_imageing_quality;
|
test_map_[HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY] = &test::test_colorcard_bias_imageing_quality;
|
||||||
test_map_[HGPDTTOOLDB_NAME_CLARITY_QUALITY] = &test::test_clarity_quality;
|
test_map_[HGPDTTOOLDB_TITLE_CLARITY_QUALITY] = &test::test_clarity_quality;
|
||||||
test_map_[HGPDTTOOLDB_NAME_DISTORTION] = &test::test_distortion;
|
test_map_[HGPDTTOOLDB_TITLE_DISTORTION] = &test::test_distortion;
|
||||||
test_map_[HGPDTTOOLDB_NAME_DORMANCY] = &test::test_dormancy;
|
test_map_[HGPDTTOOLDB_TITLE_DORMANCY] = &test::test_dormancy;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SKEW_GEAR] = &test::test_skew_gear;
|
test_map_[HGPDTTOOLDB_TITLE_SKEW_GEAR] = &test::test_skew_gear;
|
||||||
test_map_[HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH] = &test::test_paper_separation_strength;
|
test_map_[HGPDTTOOLDB_TITLE_PAPER_SEPARATION_STRENGTH] = &test::test_paper_separation_strength;
|
||||||
test_map_[HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION] = &test::test_mech_paper_feeding_inclination;
|
test_map_[HGPDTTOOLDB_TITLE_MECH_PAPER_FEEDING_INCLINATION] = &test::test_mech_paper_feeding_inclination;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_1] = &test::test_single_page_test_1;
|
test_map_[HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_1] = &test::test_single_page_test_1;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_2] = &test::test_single_page_test_2;
|
test_map_[HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_2] = &test::test_single_page_test_2;
|
||||||
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST_3] = &test::test_single_page_test_3;
|
test_map_[HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_3] = &test::test_single_page_test_3;
|
||||||
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST] = &test::test_pressuer_test;
|
test_map_[HGPDTTOOLDB_TITLE_PRESSUER_TEST] = &test::test_pressuer_test;
|
||||||
test_map_[HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT] = &test::test_clear_roller_count;
|
test_map_[HGPDTTOOLDB_TITLE_CLEAR_ROLLER_COUNT] = &test::test_clear_roller_count;
|
||||||
}
|
}
|
||||||
int set_test(const wchar_t* str)
|
int set_test(const wchar_t* str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
return SCANNER_ERR_NO_DATA;
|
return SCANNER_ERR_NO_DATA;
|
||||||
|
set_test_name_ = str;
|
||||||
ui_helper::test_event test_ev_;
|
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
std::wstring s = str;
|
|
||||||
//int count = test_map_.count(str) > 0;
|
|
||||||
wchar_t* start = (wchar_t*)L"START TEST ";
|
|
||||||
wchar_t* stop = (wchar_t*)L"STOP TEST ";
|
|
||||||
wchar_t ss[10];
|
|
||||||
wcscpy(ss,str);
|
|
||||||
/*if (!count)
|
|
||||||
{
|
|
||||||
ret = SCANNER_ERR_NO_DATA;
|
|
||||||
return ret;
|
|
||||||
}*/
|
|
||||||
//wcscat(start,str);
|
|
||||||
//helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, start, NULL);
|
|
||||||
|
|
||||||
auto it = test_map_.find(str);
|
auto it = test_map_.find(str);
|
||||||
if (it != test_map_.end())
|
if (it != test_map_.end())
|
||||||
|
@ -92,15 +184,12 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_OK;
|
helper_->test_callback(str, ui_helper::TEST_EVENT_NOT_FIND_TEST, NULL, false);
|
||||||
}
|
}
|
||||||
if (ret != SCANNER_ERR_OK)
|
if (ret != SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, NULL, ret);
|
helper_->test_callback(str, ui_helper::TEST_EVENT_IO_FAIL, NULL, ret);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
helper_->test_callback(str, ui_helper::TEST_EVENT_TIPS, stop, ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -130,12 +219,12 @@ public:
|
||||||
/* 清理纸道功能确认 */
|
/* 清理纸道功能确认 */
|
||||||
int tset_clear_paper_path()
|
int tset_clear_paper_path()
|
||||||
{
|
{
|
||||||
ui_helper::test_event test_ev_ = ui_helper::TEST_EVENT_RESULT;
|
|
||||||
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, NULL, NULL);
|
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, NULL, NULL);
|
||||||
if (ret != SCANNER_ERR_OK)
|
if (ret != SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ret);
|
return ret;
|
||||||
}
|
}
|
||||||
|
helper_->test_callback(HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH, ui_helper::TEST_EVENT_RESULT, NULL, true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/* 按键功能检测 */
|
/* 按键功能检测 */
|
||||||
|
@ -147,42 +236,38 @@ public:
|
||||||
int test_count_mode()
|
int test_count_mode()
|
||||||
{
|
{
|
||||||
|
|
||||||
ui_helper::test_event test_ev_= ui_helper::TEST_EVENT_RESULT;
|
ui_helper::test_event test_ev_ = ui_helper::TEST_EVENT_RESULT;
|
||||||
SANE_Bool ismode = false;
|
SANE_Bool ismode = false;
|
||||||
unsigned int len = sizeof(SANE_Bool);
|
unsigned int len = sizeof(SANE_Bool);
|
||||||
|
|
||||||
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, &ismode, &len);
|
int ret = helper_->io_control(IO_CTRL_CODE_GET_IS_MODE, &ismode, &len);
|
||||||
if (ret != SCANNER_ERR_OK)
|
if (ret != SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ret);
|
helper_->test_callback(HGPDTTOOLDB_TITLE_COUNTING_MODE, test_ev_, NULL, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
helper_->test_callback(HGPDTTOOLDB_NAME_DIAL_SWITCH, test_ev_, NULL, ismode);
|
helper_->test_callback(HGPDTTOOLDB_TITLE_COUNTING_MODE, test_ev_, NULL, ismode);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/* 歪斜检测 */
|
/* 歪斜检测 */
|
||||||
int test_skew_detection()
|
int test_skew_detection()
|
||||||
{
|
{
|
||||||
|
SANE_Bool type = true;
|
||||||
ui_helper::test_event test_ev_ = ui_helper::TEST_EVENT_RESULT;
|
|
||||||
SANE_Bool ismode = true;
|
|
||||||
unsigned int len = sizeof(SANE_Bool);
|
unsigned int len = sizeof(SANE_Bool);
|
||||||
|
int checknum = 1;
|
||||||
|
|
||||||
int ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK, &ismode, &len);
|
int ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK, &type, &len);
|
||||||
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
return ret;
|
||||||
|
ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK_VAL, &checknum, &len);
|
||||||
if (ret != SCANNER_ERR_OK)
|
if (ret != SCANNER_ERR_OK)
|
||||||
{
|
|
||||||
helper_->test_callback(HGPDTTOOLDB_NAME_SKEW_DETECTION, test_ev_, NULL, ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
int i = 5;
|
|
||||||
ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK_VAL, &i, &len);
|
|
||||||
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
|
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
|
||||||
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
helper_->test_callback(HGPDTTOOLDB_NAME_SKEW_DETECTION, test_ev_, NULL, ismode);
|
|
||||||
return ret;
|
return ret;
|
||||||
return SCANNER_ERR_OK;
|
|
||||||
}
|
}
|
||||||
/* 分纸电机检测 */
|
/* 分纸电机检测 */
|
||||||
int test_separater_motor()
|
int test_separater_motor()
|
||||||
|
@ -215,12 +300,12 @@ public:
|
||||||
return SCANNER_ERR_OK;
|
return SCANNER_ERR_OK;
|
||||||
}
|
}
|
||||||
/* 走纸检查 */
|
/* 走纸检查 */
|
||||||
int test_paper_feed()
|
int test_paper_feed() //使用单张扫描测试
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_OK;
|
return SCANNER_ERR_OK;
|
||||||
}
|
}
|
||||||
/* 开盖传感器检查 */
|
/* 开盖传感器检查 */
|
||||||
int test_cover_sensor()
|
int test_cover_sensor() //int端点返回 使用单张扫描测试
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_OK;
|
return SCANNER_ERR_OK;
|
||||||
}
|
}
|
||||||
|
@ -324,116 +409,40 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//test
|
//test
|
||||||
static std::string jsontext1("{\"1\":{\"name\":\"test-8\",\"ver\":1}}");
|
static std::string jsontext1("{\"1\":{\"TITLE\":\"test-8\",\"ver\":1}}");
|
||||||
std::string ret_call_= "";
|
|
||||||
bool have_img_ = false;
|
bool have_img_ = false;
|
||||||
int sane_ex_callback1(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
|
#define TEST_PTR(ptr) ((test*)ptr)
|
||||||
|
DECL_API(int) func_test_init(void** hanld, ui_helper* helper)
|
||||||
{
|
{
|
||||||
switch (code)
|
if (helper)
|
||||||
{
|
{
|
||||||
case SANE_EVENT_WORKING:
|
test* ts = new test(helper);
|
||||||
{
|
*hanld = (void*)ts;
|
||||||
ret_call_ = (char*)data;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case SANE_EVENT_SCAN_FINISHED:
|
|
||||||
{
|
|
||||||
ret_call_ = (char*)data;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SANE_EVENT_STATUS:
|
|
||||||
{
|
|
||||||
ret_call_ = (char*)data;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SANE_EVENT_ERROR:
|
|
||||||
{
|
|
||||||
ret_call_ = (char*)data;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SANE_EVENT_IMAGE_OK:
|
|
||||||
{
|
|
||||||
SANE_Image* sane_img = (SANE_Image*)data;
|
|
||||||
have_img_ = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int str_to_wchar(std::string str, wchar_t* s, size_t* strlen)
|
|
||||||
{
|
|
||||||
if (str.empty())
|
|
||||||
return ERROR_INSUFFICIENT_BUFFER;
|
|
||||||
|
|
||||||
size_t size = str.length();
|
|
||||||
int len = 0;
|
|
||||||
len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
|
|
||||||
if (*strlen < len)
|
|
||||||
{
|
|
||||||
*strlen = len;
|
|
||||||
return ERROR_INSUFFICIENT_BUFFER;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, s, len);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_json_config_file()
|
|
||||||
{
|
|
||||||
int len = 0;
|
|
||||||
char exePath[256];
|
|
||||||
char* buf = NULL;
|
|
||||||
GetModuleFileNameA(NULL, exePath, 255);
|
|
||||||
(strrchr(exePath, '\\'))[1] = 0; //去掉执行的文件名。
|
|
||||||
|
|
||||||
strcat(exePath, "DLLs\\G302.hsc");
|
|
||||||
FILE* fp = fopen(exePath, "rb");
|
|
||||||
if (fp == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fseek(fp, 0, SEEK_END);
|
|
||||||
len = ftell(fp);
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
|
||||||
buf = new char[len];
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
fclose(fp);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memset(buf, 0, len);
|
|
||||||
fread(buf, len, 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
std::cout << buf << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
DECL_API(int) func_test_init(void* init)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DECL_API(int) func_test_get_list(wchar_t* buf, size_t* len)
|
DECL_API(int) func_test_get_list(wchar_t* buf, size_t* len)
|
||||||
{
|
{
|
||||||
return str_to_wchar(jsontext1, buf, len);
|
return str_to_wchar(jsontext1, buf, len);
|
||||||
}
|
}
|
||||||
DECL_API(int) func_test_go(const wchar_t* name, const wchar_t* oper, ui_helper* helper)
|
DECL_API(int) func_test_go(void* hanld, const wchar_t* TITLE, const wchar_t* oper)
|
||||||
{
|
{
|
||||||
if (!name || !oper || !helper)
|
if (!TITLE || !oper)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//helper->add_ref();
|
//helper->add_ref();
|
||||||
helper->register_sane_callback(sane_ex_callback1, NULL);
|
|
||||||
|
|
||||||
int ret = 0;
|
int ret = TEST_PTR(hanld)->set_test(TITLE);
|
||||||
test ts(helper);
|
|
||||||
ret = ts.set_test(name);
|
|
||||||
|
|
||||||
ret = helper->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
DECL_API(int) func_test_uninit(void* uninit)
|
DECL_API(int) func_test_uninit(void* hanld)
|
||||||
{
|
{
|
||||||
|
if (hanld)
|
||||||
|
{
|
||||||
|
delete TEST_PTR(hanld);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue