parent
e705ba136a
commit
77b5b76c85
|
@ -1,7 +1,9 @@
|
|||
#include "WebUser.h"
|
||||
#include "WebServer.h"
|
||||
#include "base/HGBase64.h"
|
||||
#include "base/HGUtility.h"
|
||||
#include "base/HGImage.h"
|
||||
#include "base/HGTime.h"
|
||||
#include "imgfmt/HGJpeg.h"
|
||||
#include "sha1.h"
|
||||
#include "base64.h"
|
||||
|
@ -213,6 +215,21 @@ WebUser::WebUser(WebServer* server, HGUInt id, HGMsgPump msgPump, const std::str
|
|||
m_devHandle = NULL;
|
||||
m_scanEvent = NULL;
|
||||
|
||||
HGChar defSavePath[256];
|
||||
HGBase_GetCacheFilePath(defSavePath, 256);
|
||||
m_filepath = defSavePath;
|
||||
m_fileprefix = "img";
|
||||
m_deletefilesbeforescan = "0";
|
||||
m_filetype = "3";
|
||||
m_filesuffix = "jpg";
|
||||
m_writerFileName.clear();
|
||||
m_imgFmtWriter = NULL;
|
||||
m_writerFileValid = false;
|
||||
m_showbase64 = "0";
|
||||
m_source = "Adf-duplex";
|
||||
m_mode = "Color";
|
||||
m_resolution = "200";
|
||||
|
||||
SANE_Int version_code = 0;
|
||||
sane_init_ex(&version_code, sane_ex_callback, this);
|
||||
}
|
||||
|
@ -363,11 +380,22 @@ void WebUser::HandleCmd(const WSCmdParam* param)
|
|||
}
|
||||
else if (cmdData.find("COPT|") == 0)
|
||||
{
|
||||
GetSettingInfoNew(cmdData.substr(5));
|
||||
GetSettingInfoNew(cmdData.substr(strlen("COPT|")));
|
||||
}
|
||||
else if (cmdData.find("CBASE64|") == 0)
|
||||
{
|
||||
ConvertToBase64New(cmdData.substr(8));
|
||||
ConvertToBase64New(cmdData.substr(strlen("CBASE64|")));
|
||||
}
|
||||
else if (cmdData.find("CSCAN|") == 0)
|
||||
{
|
||||
std::string param = cmdData.substr(strlen("CSCAN|"));
|
||||
size_t pos = param.find("|");
|
||||
if (std::string::npos != pos)
|
||||
{
|
||||
std::string devName = param.substr(0, pos);
|
||||
std::string devParam = param.substr(pos + 1);
|
||||
ScanNew(devName, devParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -794,6 +822,115 @@ void WebUser::DeviceListPlugNew()
|
|||
}
|
||||
|
||||
void WebUser::GetSettingInfoNew(const std::string& devName)
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SOPT"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2006));
|
||||
|
||||
std::string optStr;
|
||||
std::string optListStr;
|
||||
|
||||
cJSON* optJson = cJSON_CreateObject();
|
||||
if (NULL != optJson)
|
||||
{
|
||||
cJSON* optListJson = cJSON_CreateObject();
|
||||
if (NULL != optListJson)
|
||||
{
|
||||
cJSON* arrayJson = cJSON_CreateArray();
|
||||
|
||||
bool find = false;
|
||||
HGBase_EnterLock(m_lockName);
|
||||
for (int i = 0; i < (int)m_devNameList.size(); ++i)
|
||||
{
|
||||
if (m_devNameList[i] == devName)
|
||||
{
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HGBase_LeaveLock(m_lockName);
|
||||
|
||||
if (find)
|
||||
{
|
||||
AddOptItem(optJson, arrayJson, "filepath", m_filepath.c_str(), NULL);
|
||||
AddOptItem(optJson, arrayJson, "fileprefix", m_fileprefix.c_str(), NULL);
|
||||
const char* deleteFileBeforeScanList[] = { "0", "1", NULL };
|
||||
AddOptItem(optJson, arrayJson, "deletefilesbeforescan", m_deletefilesbeforescan.c_str(), deleteFileBeforeScanList);
|
||||
const char* fileTypeList[] = { "1", "2", "3", "4", "5", "6", "7", NULL };
|
||||
AddOptItem(optJson, arrayJson, "filetype", m_filetype.c_str(), fileTypeList);
|
||||
const char* showBase64List[] = { "0", "1", NULL };
|
||||
AddOptItem(optJson, arrayJson, "showbase64", m_showbase64.c_str(), showBase64List);
|
||||
const char* sourceList[] = { "Adf-front", "Adf-back", "Adf-duplex", NULL };
|
||||
AddOptItem(optJson, arrayJson, "source", m_source.c_str(), sourceList);
|
||||
const char* modeList[] = { "Lineart", "Gray", "Color", NULL };
|
||||
AddOptItem(optJson, arrayJson, "mode", m_mode.c_str(), modeList);
|
||||
AddOptItem(optJson, arrayJson, "resolution", m_resolution.c_str(), NULL);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(optListJson, "Options", arrayJson);
|
||||
|
||||
char* str = cJSON_Print(optListJson);
|
||||
if (NULL != str)
|
||||
{
|
||||
optListStr = GetBase64((HGByte*)str, strlen(str));
|
||||
free(str);
|
||||
}
|
||||
|
||||
cJSON_Delete(optListJson);
|
||||
}
|
||||
|
||||
char* str = cJSON_Print(optJson);
|
||||
if (NULL != str)
|
||||
{
|
||||
optStr = GetBase64((HGByte*)str, strlen(str));
|
||||
free(str);
|
||||
}
|
||||
|
||||
cJSON_Delete(optJson);
|
||||
}
|
||||
|
||||
std::string dataStr = optStr + "|" + optListStr;
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(dataStr.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("json"));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
|
||||
void WebUser::ConvertToBase64New(const std::string& filePath)
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SBASE64"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2007));
|
||||
std::string base64 = GetBase64(filePath);
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(base64.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("base64"));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
|
||||
void WebUser::ScanNew(const std::string& devName, const std::string& devParam)
|
||||
{
|
||||
if (NULL != m_scanEvent)
|
||||
{
|
||||
|
@ -828,245 +965,95 @@ void WebUser::GetSettingInfoNew(const std::string& devName)
|
|||
|
||||
if (NULL != m_devHandle)
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
cJSON* json = cJSON_Parse(devParam.c_str());
|
||||
if (NULL != json)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SOPT"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2006));
|
||||
|
||||
std::string optStr;
|
||||
std::string optListStr;
|
||||
|
||||
cJSON* optJson = cJSON_CreateObject();
|
||||
if (NULL != optJson)
|
||||
cJSON* p = json->child;
|
||||
while (NULL != p)
|
||||
{
|
||||
cJSON* optListJson = cJSON_CreateObject();
|
||||
if (NULL != optListJson)
|
||||
if (0 == strcmp(p->string, "filepath"))
|
||||
{
|
||||
cJSON* arrayJson = cJSON_CreateArray();
|
||||
|
||||
SANE_Int num_dev_options = 0;
|
||||
sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
|
||||
for (int i = 1; i < num_dev_options; ++i)
|
||||
{
|
||||
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i);
|
||||
if (NULL == desp)
|
||||
continue;
|
||||
|
||||
const char* name = desp->title;
|
||||
while (' ' == *name)
|
||||
++name;
|
||||
|
||||
if (SANE_TYPE_STRING == desp->type)
|
||||
{
|
||||
char value[256] = { 0 };
|
||||
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, value, NULL);
|
||||
cJSON_AddItemToObject(optJson, name, cJSON_CreateString(value));
|
||||
|
||||
cJSON* objJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(objJson, "constType", cJSON_CreateNumber(3));
|
||||
cJSON_AddItemToObject(objJson, "current", cJSON_CreateString(value));
|
||||
cJSON_AddItemToObject(objJson, "isActive", cJSON_CreateTrue());
|
||||
cJSON_AddItemToObject(objJson, "isSettable", cJSON_CreateTrue());
|
||||
|
||||
if (SANE_CONSTRAINT_STRING_LIST == desp->constraint_type)
|
||||
{
|
||||
cJSON* arrayJson2 = cJSON_CreateArray();
|
||||
const SANE_String_Const* p = desp->constraint.string_list;
|
||||
while (NULL != *p)
|
||||
{
|
||||
cJSON_AddItemToArray(arrayJson2, cJSON_CreateString(*p));
|
||||
++p;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "list", arrayJson2);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(objJson, "type", cJSON_CreateNumber(3));
|
||||
cJSON_AddItemToObject(objJson, "unit", cJSON_CreateString(""));
|
||||
|
||||
cJSON_AddItemToArray(arrayJson, objJson);
|
||||
}
|
||||
else if (SANE_TYPE_INT == desp->type)
|
||||
{
|
||||
SANE_Int value = 0;
|
||||
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
cJSON_AddItemToObject(optJson, name, cJSON_CreateNumber(value));
|
||||
|
||||
cJSON* objJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(objJson, "constType", cJSON_CreateNumber(1));
|
||||
cJSON_AddItemToObject(objJson, "current", cJSON_CreateNumber(value));
|
||||
cJSON_AddItemToObject(objJson, "isActive", cJSON_CreateTrue());
|
||||
cJSON_AddItemToObject(objJson, "isSettable", cJSON_CreateTrue());
|
||||
|
||||
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
||||
{
|
||||
cJSON* arrayJson2 = cJSON_CreateArray();
|
||||
const SANE_Word* p = desp->constraint.word_list;
|
||||
for (SANE_Int i = 0; i < p[0]; ++i)
|
||||
{
|
||||
cJSON_AddItemToArray(arrayJson2, cJSON_CreateNumber(p[i + 1]));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "list", arrayJson2);
|
||||
}
|
||||
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
// desp->constraint.range->min;
|
||||
// desp->constraint.range->max;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(objJson, "type", cJSON_CreateNumber(1));
|
||||
cJSON_AddItemToObject(objJson, "unit", cJSON_CreateString(""));
|
||||
|
||||
cJSON_AddItemToArray(arrayJson, objJson);
|
||||
}
|
||||
else if (SANE_TYPE_FIXED == desp->type)
|
||||
{
|
||||
SANE_Word value = 0;
|
||||
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
cJSON_AddItemToObject(optJson, name, cJSON_CreateNumber(SANE_UNFIX(value)));
|
||||
|
||||
cJSON* objJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(objJson, "constType", cJSON_CreateNumber(2));
|
||||
cJSON_AddItemToObject(objJson, "current", cJSON_CreateNumber(SANE_UNFIX(value)));
|
||||
cJSON_AddItemToObject(objJson, "isActive", cJSON_CreateTrue());
|
||||
cJSON_AddItemToObject(objJson, "isSettable", cJSON_CreateTrue());
|
||||
|
||||
if (SANE_CONSTRAINT_WORD_LIST == desp->constraint_type)
|
||||
{
|
||||
cJSON* arrayJson2 = cJSON_CreateArray();
|
||||
const SANE_Word* p = desp->constraint.word_list;
|
||||
for (SANE_Int i = 0; i < p[0]; ++i)
|
||||
{
|
||||
cJSON_AddItemToArray(arrayJson2, cJSON_CreateNumber(SANE_UNFIX(p[i + 1])));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "list", arrayJson2);
|
||||
}
|
||||
else if (SANE_CONSTRAINT_RANGE == desp->constraint_type)
|
||||
{
|
||||
// SANE_UNFIX(desp->constraint.range->min);
|
||||
// SANE_UNFIX(desp->constraint.range->max);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(objJson, "type", cJSON_CreateNumber(2));
|
||||
cJSON_AddItemToObject(objJson, "unit", cJSON_CreateString(""));
|
||||
|
||||
cJSON_AddItemToArray(arrayJson, objJson);
|
||||
}
|
||||
else if (SANE_TYPE_BOOL == desp->type)
|
||||
{
|
||||
SANE_Bool value = 0;
|
||||
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
|
||||
cJSON_AddItemToObject(optJson, name, value ? cJSON_CreateTrue() : cJSON_CreateFalse());
|
||||
|
||||
cJSON* objJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(objJson, "constType", cJSON_CreateNumber(0));
|
||||
cJSON_AddItemToObject(objJson, "current", value ? cJSON_CreateTrue() : cJSON_CreateFalse());
|
||||
cJSON_AddItemToObject(objJson, "isActive", cJSON_CreateTrue());
|
||||
cJSON_AddItemToObject(objJson, "isSettable", cJSON_CreateTrue());
|
||||
|
||||
cJSON_AddItemToObject(objJson, "name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(objJson, "type", cJSON_CreateNumber(0));
|
||||
cJSON_AddItemToObject(objJson, "unit", cJSON_CreateString(""));
|
||||
|
||||
cJSON_AddItemToArray(arrayJson, objJson);
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(optListJson, "Options", arrayJson);
|
||||
|
||||
char* str = cJSON_Print(optListJson);
|
||||
if (NULL != str)
|
||||
{
|
||||
optListStr = GetBase64((HGByte*)str, strlen(str));
|
||||
free(str);
|
||||
}
|
||||
|
||||
cJSON_Delete(optListJson);
|
||||
char filePath[260];
|
||||
HGBase_StandardiseFileName(p->valuestring, filePath, 260);
|
||||
m_filepath = filePath;
|
||||
#ifdef _WIN32
|
||||
if (m_filepath[m_filepath.size() - 1] != '\\')
|
||||
m_filepath.push_back('\\');
|
||||
#else
|
||||
if (m_filepath[m_filepath.size() - 1] != '/')
|
||||
m_filepath.push_back('/');
|
||||
#endif
|
||||
}
|
||||
else if (0 == strcmp(p->string, "fileprefix"))
|
||||
m_fileprefix = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "deletefilesbeforescan"))
|
||||
m_deletefilesbeforescan = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "filetype"))
|
||||
m_filetype = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "showbase64"))
|
||||
m_showbase64 = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "source"))
|
||||
m_source = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "mode"))
|
||||
m_mode = p->valuestring;
|
||||
else if (0 == strcmp(p->string, "resolution"))
|
||||
m_resolution = p->valuestring;
|
||||
|
||||
char* str = cJSON_Print(optJson);
|
||||
if (NULL != str)
|
||||
{
|
||||
optStr = GetBase64((HGByte*)str, strlen(str));
|
||||
free(str);
|
||||
}
|
||||
|
||||
cJSON_Delete(optJson);
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
std::string dataStr = optStr + "|" + optListStr;
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(dataStr.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("json"));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
SetParam();
|
||||
|
||||
HGBase_CreateEvent(HGFALSE, HGFALSE, &m_scanEvent);
|
||||
assert(NULL != m_scanEvent);
|
||||
|
||||
SANE_Status status = sane_start(m_devHandle);
|
||||
if (SANE_STATUS_GOOD != status)
|
||||
{
|
||||
HGBase_DestroyEvent(m_scanEvent);
|
||||
m_scanEvent = NULL;
|
||||
|
||||
if (NULL != m_imgFmtWriter)
|
||||
{
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
free(resp);
|
||||
HGImgFmt_CloseImageWriter(m_imgFmtWriter);
|
||||
m_imgFmtWriter = NULL;
|
||||
HGBase_DeleteFile(m_writerFileName.c_str());
|
||||
m_writerFileName.clear();
|
||||
m_writerFileValid = false;
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebUser::ConvertToBase64New(const std::string& filePath)
|
||||
void WebUser::AddOptItem(cJSON* optJson, cJSON* arrayJson, const char* name, const char* value, const char** list)
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
cJSON_AddItemToObject(optJson, name, cJSON_CreateString(value));
|
||||
|
||||
cJSON* objJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(objJson, "constType", cJSON_CreateNumber(3));
|
||||
cJSON_AddItemToObject(objJson, "current", cJSON_CreateString(value));
|
||||
cJSON_AddItemToObject(objJson, "isActive", cJSON_CreateTrue());
|
||||
cJSON_AddItemToObject(objJson, "isSettable", cJSON_CreateTrue());
|
||||
|
||||
if (NULL != list)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SBASE64"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2007));
|
||||
|
||||
std::string dataStr;
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (NULL != file)
|
||||
cJSON* arrayJson2 = cJSON_CreateArray();
|
||||
const char** p = list;
|
||||
while (0 != *p)
|
||||
{
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
HGByte* data = new HGByte[size];
|
||||
long readLen = (long)fread(data, 1, size, file);
|
||||
if (readLen == size)
|
||||
{
|
||||
HGSize base64Size = 0;
|
||||
HGBase_Base64Encode(data, size, NULL, &base64Size);
|
||||
uint8_t* base64Data = new uint8_t[base64Size + 1];
|
||||
HGBase_Base64Encode(data, size, base64Data, &base64Size);
|
||||
base64Data[base64Size] = 0;
|
||||
dataStr = (const char*)base64Data;
|
||||
delete[] base64Data;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
cJSON_AddItemToArray(arrayJson2, cJSON_CreateString(*p));
|
||||
++p;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(dataStr.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("base64"));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
cJSON_AddItemToObject(objJson, "list", arrayJson2);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(objJson, "name", cJSON_CreateString(name));
|
||||
cJSON_AddItemToObject(objJson, "type", cJSON_CreateNumber(3));
|
||||
cJSON_AddItemToObject(objJson, "unit", cJSON_CreateString(""));
|
||||
cJSON_AddItemToArray(arrayJson, objJson);
|
||||
}
|
||||
|
||||
void WebUser::PostDisConnectMsg()
|
||||
|
@ -1499,6 +1486,8 @@ int WebUser::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
|
||||
if (p->m_server->IsOld())
|
||||
{
|
||||
assert(NULL == p->m_imgFmtWriter);
|
||||
|
||||
int code = 0;
|
||||
std::string result = "";
|
||||
|
||||
|
@ -1518,6 +1507,63 @@ int WebUser::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NULL != p->m_imgFmtWriter)
|
||||
{
|
||||
HGImgFmt_CloseImageWriter(p->m_imgFmtWriter);
|
||||
p->m_imgFmtWriter = NULL;
|
||||
|
||||
if (p->m_writerFileValid)
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SSCANMUL"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2003));
|
||||
std::string data = p->m_filesuffix + "|" + p->m_writerFileName;
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(data.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("string"));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HGBase_DeleteFile(p->m_writerFileName.c_str());
|
||||
}
|
||||
|
||||
p->m_writerFileName.clear();
|
||||
p->m_writerFileValid = false;
|
||||
}
|
||||
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SSCANALL"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2004));
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(""));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString(""));
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
|
@ -1582,6 +1628,69 @@ int WebUser::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned i
|
|||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
else if (NULL != p->m_imgFmtWriter)
|
||||
{
|
||||
if (HGBASE_ERR_OK == HGImgFmt_SaveImageToWriter(p->m_imgFmtWriter, img, NULL))
|
||||
p->m_writerFileValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON* retJson = cJSON_CreateObject();
|
||||
if (NULL != retJson)
|
||||
{
|
||||
cJSON_AddItemToObject(retJson, "Cmd", cJSON_CreateString("SSCANONE"));
|
||||
cJSON_AddItemToObject(retJson, "Code", cJSON_CreateNumber(2002));
|
||||
|
||||
HGBase_CreateDir(p->m_filepath.c_str());
|
||||
HGChar fileName[256];
|
||||
HGTimeInfo timeInfo;
|
||||
HGBase_GetLocalTime(&timeInfo);
|
||||
sprintf(fileName, "%s%04d%02d%02d%02d%02d%02d%03d.%s", p->m_fileprefix.c_str(), timeInfo.year, timeInfo.month,
|
||||
timeInfo.day, timeInfo.hour, timeInfo.minute, timeInfo.second, timeInfo.milliseconds, p->m_filesuffix.c_str());
|
||||
HGChar filePath[256];
|
||||
sprintf(filePath, "%s%s", p->m_filepath.c_str(), fileName);
|
||||
|
||||
if (atoi(p->m_showbase64.c_str()))
|
||||
{
|
||||
std::string data;
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, NULL, filePath))
|
||||
cJSON_AddItemToObject(obj, "ImagePath", cJSON_CreateString(filePath));
|
||||
std::string imgBase64 = GetBase64(filePath);
|
||||
if (!imgBase64.empty())
|
||||
cJSON_AddItemToObject(obj, "Base64Data", cJSON_CreateString(imgBase64.c_str()));
|
||||
|
||||
char* objStr = cJSON_Print(obj);
|
||||
data = p->m_filesuffix + "|" + GetBase64((HGByte*)objStr, strlen(objStr));
|
||||
free(objStr);
|
||||
cJSON_Delete(obj);
|
||||
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(data.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("base64"));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string data = p->m_filesuffix + "|";
|
||||
if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, NULL, filePath))
|
||||
data += filePath;
|
||||
|
||||
cJSON_AddItemToObject(retJson, "Data", cJSON_CreateString(data.c_str()));
|
||||
cJSON_AddItemToObject(retJson, "DataType", cJSON_CreateString("string"));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(retJson, "Msg", cJSON_CreateString("Success"));
|
||||
|
||||
char* resp = cJSON_Print(retJson);
|
||||
if (NULL != resp)
|
||||
{
|
||||
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
||||
free(resp);
|
||||
}
|
||||
|
||||
cJSON_Delete(retJson);
|
||||
}
|
||||
}
|
||||
|
||||
HGBase_DestroyImage(img);
|
||||
}
|
||||
|
@ -1630,6 +1739,61 @@ std::string WebUser::GetBase64(HGImage image)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string WebUser::GetBase64(const std::string& filePath)
|
||||
{
|
||||
std::string base64;
|
||||
FILE* file = fopen(filePath.c_str(), "rb");
|
||||
if (NULL != file)
|
||||
{
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
HGByte* data = new HGByte[size];
|
||||
long readLen = (long)fread(data, 1, size, file);
|
||||
if (readLen == size)
|
||||
{
|
||||
HGSize base64Size = 0;
|
||||
HGBase_Base64Encode(data, size, NULL, &base64Size);
|
||||
uint8_t* base64Data = new uint8_t[base64Size + 1];
|
||||
HGBase_Base64Encode(data, size, base64Data, &base64Size);
|
||||
base64Data[base64Size] = 0;
|
||||
base64 = (const char*)base64Data;
|
||||
delete[] base64Data;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
if (!base64.empty())
|
||||
{
|
||||
HGUInt imgType = 0;
|
||||
HGImgFmt_GetImgFmtType(filePath.c_str(), &imgType);
|
||||
|
||||
std::string prefix;
|
||||
if (HGIMGFMT_TYPE_JPEG == imgType)
|
||||
prefix = "data:image/jpeg;base64,";
|
||||
else if (HGIMGFMT_TYPE_BMP == imgType)
|
||||
prefix = "data:image/bmp;base64,";
|
||||
else if (HGIMGFMT_TYPE_PNG == imgType)
|
||||
prefix = "data:image/png;base64,";
|
||||
else if (HGIMGFMT_TYPE_TIFF == imgType)
|
||||
prefix = "data:image/tiff;base64,";
|
||||
else if (HGIMGFMT_TYPE_PDF == imgType)
|
||||
prefix = "data:image/pdf;base64,";
|
||||
else if (HGIMGFMT_TYPE_OFD == imgType)
|
||||
prefix = "data:image/ofd;base64,";
|
||||
base64.insert(0, prefix);
|
||||
}
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
std::string WebUser::GetBase64(const HGByte* data, HGUInt size)
|
||||
{
|
||||
std::string ret;
|
||||
|
@ -1647,6 +1811,129 @@ std::string WebUser::GetBase64(const HGByte* data, HGUInt size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void WebUser::ClearPath(const std::string& path)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
char szFind[MAX_PATH];
|
||||
sprintf(szFind, "%s*.*", path.c_str());
|
||||
|
||||
WIN32_FIND_DATAA FindFileData;
|
||||
HANDLE hFind = FindFirstFileA(szFind, &FindFileData);
|
||||
if (INVALID_HANDLE_VALUE == hFind)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
if (0 == (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
char fileName[MAX_PATH];
|
||||
sprintf(fileName, "%s%s", path.c_str(), FindFileData.cFileName);
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
|
||||
} while (FindNextFileA(hFind, &FindFileData));
|
||||
|
||||
FindClose(hFind);
|
||||
#else
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (NULL != dir)
|
||||
{
|
||||
struct dirent* dire = NULL;
|
||||
while (dire = readdir(dir))
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%s", path.c_str(), dire->d_name);
|
||||
|
||||
struct stat filebuf;
|
||||
lstat(fileName, &filebuf);
|
||||
if (!S_ISDIR(filebuf.st_mode))
|
||||
{
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebUser::SetParam()
|
||||
{
|
||||
// Set Param
|
||||
|
||||
if (m_source == "Adf-front")
|
||||
{
|
||||
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_DM);
|
||||
HGBool b = HGFALSE;
|
||||
SetParam(OPTION_TITLE_JHZFM, &b);
|
||||
}
|
||||
else if (m_source == "Adf-back")
|
||||
{
|
||||
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_DM);
|
||||
HGBool b = HGTRUE;
|
||||
SetParam(OPTION_TITLE_JHZFM, &b);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetParam(OPTION_TITLE_SMYM, OPTION_VALUE_SMYM_SM);
|
||||
HGBool b = HGFALSE;
|
||||
SetParam(OPTION_TITLE_JHZFM, &b);
|
||||
}
|
||||
|
||||
if (m_mode == "Lineart")
|
||||
{
|
||||
SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_HB);
|
||||
}
|
||||
else if (m_mode == "Gray")
|
||||
{
|
||||
SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_256JHD);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetParam(OPTION_TITLE_YSMS, OPTION_VALUE_YSMS_24WCS);
|
||||
}
|
||||
|
||||
HGInt dpi = atoi(m_resolution.c_str());
|
||||
SetParam(OPTION_TITLE_FBL, &dpi);
|
||||
|
||||
if (atoi(m_deletefilesbeforescan.c_str()))
|
||||
{
|
||||
ClearPath(m_filepath);
|
||||
}
|
||||
|
||||
if (1 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "bmp";
|
||||
else if (2 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "png";
|
||||
else if (4 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "tif";
|
||||
else if (5 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "gif";
|
||||
else if (6 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "pdf";
|
||||
else if (7 == atoi(m_filetype.c_str()))
|
||||
m_filesuffix = "ofd";
|
||||
else
|
||||
m_filesuffix = "jpg";
|
||||
|
||||
if ("tif" == m_filesuffix || "pdf" == m_filesuffix || "ofd" == m_filesuffix)
|
||||
{
|
||||
HGBase_CreateDir(m_filepath.c_str());
|
||||
HGChar fileName[256];
|
||||
HGTimeInfo timeInfo;
|
||||
HGBase_GetLocalTime(&timeInfo);
|
||||
sprintf(fileName, "%s%04d%02d%02d%02d%02d%02d%03d.%s", m_fileprefix.c_str(), timeInfo.year, timeInfo.month,
|
||||
timeInfo.day, timeInfo.hour, timeInfo.minute, timeInfo.second, timeInfo.milliseconds, m_filesuffix.c_str());
|
||||
m_writerFileName = m_filepath + fileName;
|
||||
m_writerFileValid = false;
|
||||
HGImgFmt_OpenImageWriter(m_writerFileName.c_str(), 0, &m_imgFmtWriter);
|
||||
if (NULL == m_imgFmtWriter)
|
||||
{
|
||||
m_writerFileName.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HGBool WebUser::SetParam(const char* optionName, const HGVoid* data)
|
||||
{
|
||||
assert(NULL != m_devHandle);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "base/HGThread.h"
|
||||
#include "base/HGImage.h"
|
||||
#include "base/HGMsgPump.h"
|
||||
#include "imgfmt/HGImgFmt.h"
|
||||
#include "Msg.h"
|
||||
#include "cJSON.h"
|
||||
#include "sane/sane_ex.h"
|
||||
|
@ -45,15 +46,20 @@ private:
|
|||
void DeviceListPlugNew();
|
||||
void GetSettingInfoNew(const std::string &devName);
|
||||
void ConvertToBase64New(const std::string& filePath);
|
||||
void ScanNew(const std::string& devName, const std::string& devParam);
|
||||
|
||||
private:
|
||||
static void AddOptItem(cJSON* optJson, cJSON* arrayJson, const char *name, const char *value, const char **list);
|
||||
void PostDisConnectMsg();
|
||||
void PostCmdMsg(const HGByte* data, HGUInt dataSize);
|
||||
void PostEventMsg(const HGByte* data, HGUInt dataSize);
|
||||
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
|
||||
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
||||
std::string GetBase64(HGImage image);
|
||||
std::string GetBase64(const HGByte* data, HGUInt size);
|
||||
static std::string GetBase64(const std::string& filePath);
|
||||
static std::string GetBase64(const HGByte* data, HGUInt size);
|
||||
static void ClearPath(const std::string &path);
|
||||
void SetParam();
|
||||
HGBool SetParam(const char* optionName, const HGVoid* data);
|
||||
|
||||
bool ShakeHand(const std::string& head);
|
||||
|
@ -80,4 +86,17 @@ private:
|
|||
std::string m_devName;
|
||||
SANE_Handle m_devHandle;
|
||||
HGEvent m_scanEvent;
|
||||
|
||||
std::string m_filepath;
|
||||
std::string m_fileprefix;
|
||||
std::string m_deletefilesbeforescan;
|
||||
std::string m_filetype;
|
||||
std::string m_filesuffix;
|
||||
std::string m_writerFileName;
|
||||
HGImgFmtWriter m_imgFmtWriter;
|
||||
bool m_writerFileValid;
|
||||
std::string m_showbase64;
|
||||
std::string m_source;
|
||||
std::string m_mode;
|
||||
std::string m_resolution;
|
||||
};
|
||||
|
|
|
@ -42,9 +42,6 @@ int main()
|
|||
assert(0 == ret);
|
||||
#endif
|
||||
|
||||
lang_initialize(nullptr);
|
||||
lang_set_code_page(20127);
|
||||
|
||||
HGMsgPump msgPump = NULL;
|
||||
HGBase_CreateMsgPump(&msgPump);
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
|
@ -0,0 +1,703 @@
|
|||
! function(e) {
|
||||
function t(r) {
|
||||
if (n[r]) return n[r].exports;
|
||||
var i = n[r] = {
|
||||
i: r,
|
||||
l: !1,
|
||||
exports: {}
|
||||
};
|
||||
return e[r].call(i.exports, i, i.exports, t), i.l = !0, i.exports
|
||||
}
|
||||
var n = {};
|
||||
t.m = e, t.c = n, t.d = function(e, n, r) {
|
||||
t.o(e, n) || Object.defineProperty(e, n, {
|
||||
configurable: !1,
|
||||
enumerable: !0,
|
||||
get: r
|
||||
})
|
||||
}, t.n = function(e) {
|
||||
var n = e && e.__esModule ? function() {
|
||||
return e.default
|
||||
} : function() {
|
||||
return e
|
||||
};
|
||||
return t.d(n, "a", n), n
|
||||
}, t.o = function(e, t) {
|
||||
return Object.prototype.hasOwnProperty.call(e, t)
|
||||
}, t.p = "", t(t.s = 0)
|
||||
}([function(e, t) {
|
||||
! function(e, t) {
|
||||
function n(e) {
|
||||
var t = String(e)
|
||||
.trim();
|
||||
if (isNaN(t)) return !1;
|
||||
var n = Math.floor(Number(t));
|
||||
return n !== 1 / 0 && String(n) === t
|
||||
}
|
||||
|
||||
function r(e) {
|
||||
var t = String(e)
|
||||
.trim();
|
||||
return "yes" === t || "1" === t || "true" === t ? "yes" : "no"
|
||||
}
|
||||
|
||||
function i(e, t) {
|
||||
y[e] = t, S[e] = t
|
||||
}
|
||||
|
||||
function o(e) {
|
||||
var n = S[e];
|
||||
return n !== t ? n : ""
|
||||
}
|
||||
|
||||
function s(r, i, o) {
|
||||
if (!("WebSocket" in e)) return void console.error("%c浏览器不支持WebSocket,请更换浏览器", "color:red");
|
||||
b = (1 == o || 0 == o) && o, m = r !== t && null !== r && "" !== String(r) && n(r) ? b ? "ws://localhost:" + String(r + 1) : "ws://localhost:" + String(r) : b ? "wss://localhost:23166" : "ws://localhost:23165", d = (1 == i || 0 == i) && i, null === h ? (h = new WebSocket(m), h.onopen = function() {
|
||||
d && console.log("连接已打开")
|
||||
}, h.onmessage = function(e) {
|
||||
console.log(e.data);
|
||||
var t = String(e.data),
|
||||
n = JSON.parse(t),
|
||||
r = n.Cmd,
|
||||
i = n.Code,
|
||||
o = n.Msg;
|
||||
if (0 !== i && i < 2001 && (y = {}, x("Code:" + i + ";Msg:" + o)), "HOME" === r) j(n.Data);
|
||||
else if ("SDEV" === r) {
|
||||
var s = JSON.parse(e.data);
|
||||
if ("2005" === String(s.Code)) {
|
||||
var c = atob(s.Data),
|
||||
a = decodeURI(c),
|
||||
u = JSON.parse(a);
|
||||
P(u.Devs)
|
||||
} else P([])
|
||||
} else if ("SDEVPLUG" === r) {
|
||||
var s = JSON.parse(e.data);
|
||||
if ("2005" === String(s.Code)) {
|
||||
var c = atob(s.Data),
|
||||
a = decodeURI(c),
|
||||
u = JSON.parse(a);
|
||||
v(u.Devs)
|
||||
} else v([])
|
||||
} else if ("SOPT" === r) {
|
||||
S = {}, O = {}, y = {};
|
||||
var s = JSON.parse(e.data),
|
||||
f = s.Data.split("|");
|
||||
if (2 === f.length) {
|
||||
var c = atob(f[0]),
|
||||
a = decodeURI(c),
|
||||
p = JSON.parse(a);
|
||||
S = p, O = p, c = atob(f[1]), a = decodeURI(c);
|
||||
JSON.parse(a);
|
||||
D(a)
|
||||
}
|
||||
} else if ("SSCANONE" === r) {
|
||||
var l = JSON.parse(e.data),
|
||||
ld = l.liveDetect,
|
||||
f = l.Data.split("|");
|
||||
if (2 === f.length) {
|
||||
var d = f[0],
|
||||
b = f[1];
|
||||
if (0 === g) w(l.DataType,ld, d, b, "");
|
||||
else {
|
||||
var m = atob(b),
|
||||
h = decodeURI(m),
|
||||
E = JSON.parse(h);
|
||||
w(l.DataType, ld, d, E.ImagePath, E.Base64Data)
|
||||
}
|
||||
}
|
||||
} else if ("SSCANALL" === r) k(e.data), y = {};
|
||||
else if ("SSCANMUL" === r) {
|
||||
var J = "",
|
||||
M = "",
|
||||
l = JSON.parse(e.data),
|
||||
f = l.Data.split("|");
|
||||
2 === f.length && (J = f[0], M = f[1]), N(J, M), y = {}
|
||||
} else if ("SBASE64" === r) {
|
||||
var l = JSON.parse(e.data);
|
||||
C(l.Data)
|
||||
} else y = {}, console.log(n.Code, n.Msg)
|
||||
}, h.onclose = function(e) {
|
||||
h = null, console.error("%c连接已关闭,请检查进程pslapisvr是否存在,并重新刷新页面进行连接。\r\n 详细信息:", "color:red", e)
|
||||
}, h.onerror = function(e) {
|
||||
h = null, console.error("%c连接出现错误,请检查进程pslapisvr是否存在。\r\n 详细信息:", "color:red", e)
|
||||
}) : h = null
|
||||
}
|
||||
|
||||
function c(e, t) {
|
||||
"function" == typeof t && ("OnGetHomePath" === e ? j = t : "OnGetDevices" === e ? P = t : "OnDetectDevices" === e ? v = t : "OnScanOneFileDone" === e ? w = t : "OnScanAllFilesDone" === e ? k = t : "OnScanMultiPagesFileDone" === e ? N = t : "OnGetSettingInfo" === e ? D = t : "OnGetBase64" === e ? C = t : "OnErrorMessage" === e && (x = t))
|
||||
}
|
||||
|
||||
function a() {
|
||||
if (null === h) return void x("GetDevices:未连接服务");
|
||||
h.send("CDEV")
|
||||
}
|
||||
|
||||
function u(e) {
|
||||
return null === h ? void x("GetSettingInfo:未连接服务") : e && "" !== e ? void h.send("COPT|" + String(e)) : void x("GetSettingInfo:未选择扫描仪")
|
||||
}
|
||||
|
||||
function f(e) {
|
||||
if (null === h) return void x("Scan:未连接服务");
|
||||
if (!e || "" === e) return void x("Scan:未选择扫描仪");
|
||||
var t = JSON.stringify(y);
|
||||
h.send("CSCAN|" + String(e) + "|" + t)
|
||||
}
|
||||
|
||||
function p(e) {
|
||||
if (null === h) return void x("ConvertToBase64:未连接服务");
|
||||
h.send("CBASE64|" + e)
|
||||
}
|
||||
|
||||
function l() {
|
||||
y = {}, S = O, g = 0
|
||||
}
|
||||
e.psl = {
|
||||
sane: {}
|
||||
}, Object.defineProperty(psl.sane, "filepath", {
|
||||
get: function() {
|
||||
return o("filepath")
|
||||
},
|
||||
set: function(e) {
|
||||
i("filepath", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "filetype", {
|
||||
get: function() {
|
||||
return o("filetype")
|
||||
},
|
||||
set: function(e) {
|
||||
var t = String(e)
|
||||
.trim();
|
||||
if ("1" !== t && "2" !== t && "3" !== t && "4" !== t && "5" !== t && "6" !== t && "7" !== t) throw new Error("filetype 值范围:1-7,且为整数,当前值:" + t);
|
||||
i("filetype", t)
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "fileprefix", {
|
||||
get: function() {
|
||||
return o("fileprefix")
|
||||
},
|
||||
set: function(e) {
|
||||
i("fileprefix", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "scancount", {
|
||||
get: function() {
|
||||
return o("scancount")
|
||||
},
|
||||
set: function(e) {
|
||||
var t = String(e)
|
||||
.trim(),
|
||||
r = Math.floor(Number(t));
|
||||
if (!n(t) && r < 1 && r > 2e9) throw new Error("scancount 值范围:1-2000000000,且为整数,当前值:" + t);
|
||||
i("scancount", t)
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "scanmincountsize", {
|
||||
get: function() {
|
||||
return o("scanmincountsize")
|
||||
},
|
||||
set: function(e) {
|
||||
var t = String(e)
|
||||
.trim(),
|
||||
r = Math.floor(Number(t));
|
||||
if (!n(t) && r < 1 && r > 9) throw new Error("scanmincountsize 值范围:1-9,且为整数,当前值:" + t);
|
||||
i("scanmincountsize", t)
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "deletefilesbeforescan", {
|
||||
get: function() {
|
||||
return o("deletefilesbeforescan")
|
||||
},
|
||||
set: function(e) {
|
||||
var t = String(e)
|
||||
.trim();
|
||||
if ("0" !== t && "1" !== t) throw new Error("deletefilesbeforescan 值范围:0-1,且为整数,当前值:" + t);
|
||||
i("deletefilesbeforescan", t)
|
||||
}
|
||||
});
|
||||
var g = 0;
|
||||
Object.defineProperty(psl.sane, "showbase64", {
|
||||
get: function() {
|
||||
return o("showbase64")
|
||||
},
|
||||
set: function(e) {
|
||||
var t = String(e)
|
||||
.trim();
|
||||
if ("0" !== t && "1" !== t) throw new Error("showbase64 值范围:0-1,且为整数,当前值:" + t);
|
||||
g = Math.floor(Number(t)), i("showbase64", t)
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "source", {
|
||||
get: function() {
|
||||
return o("source")
|
||||
},
|
||||
set: function(e) {
|
||||
i("source", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "mode", {
|
||||
get: function() {
|
||||
return o("mode")
|
||||
},
|
||||
set: function(e) {
|
||||
i("mode", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "resolution", {
|
||||
get: function() {
|
||||
return o("resolution")
|
||||
},
|
||||
set: function(e) {
|
||||
i("resolution", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "pagewidth", {
|
||||
get: function() {
|
||||
return o("page-width")
|
||||
},
|
||||
set: function(e) {
|
||||
i("page-width", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "pageheight", {
|
||||
get: function() {
|
||||
return o("page-height")
|
||||
},
|
||||
set: function(e) {
|
||||
i("page-height", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "tlx", {
|
||||
get: function() {
|
||||
return o("tl-x")
|
||||
},
|
||||
set: function(e) {
|
||||
i("tl-x", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "tly", {
|
||||
get: function() {
|
||||
return o("tl-y")
|
||||
},
|
||||
set: function(e) {
|
||||
i("tl-y", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "brx", {
|
||||
get: function() {
|
||||
return o("br-x")
|
||||
},
|
||||
set: function(e) {
|
||||
i("br-x", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bry", {
|
||||
get: function() {
|
||||
return o("br-y")
|
||||
},
|
||||
set: function(e) {
|
||||
i("br-y", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "papersize", {
|
||||
get: function() {
|
||||
return o("paper-size")
|
||||
},
|
||||
set: function(e) {
|
||||
i("paper-size", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "pageauto", {
|
||||
get: function() {
|
||||
return o("page-auto")
|
||||
},
|
||||
set: function(e) {
|
||||
i("page-auto", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "pageautopriority", {
|
||||
get: function() {
|
||||
return o("page-auto-priority")
|
||||
},
|
||||
set: function(e) {
|
||||
i("page-auto-priority", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "cropping", {
|
||||
get: function() {
|
||||
return o("cropping")
|
||||
},
|
||||
set: function(e) {
|
||||
i("cropping", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bgcolor", {
|
||||
get: function() {
|
||||
return o("bgcolor")
|
||||
},
|
||||
set: function(e) {
|
||||
i("bgcolor", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bwmode", {
|
||||
get: function() {
|
||||
return o("bw-mode")
|
||||
},
|
||||
set: function(e) {
|
||||
i("bw-mode", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bwidtcsensitivity", {
|
||||
get: function() {
|
||||
return o("bw-idtc-sensitivity")
|
||||
},
|
||||
set: function(e) {
|
||||
i("bw-idtc-sensitivity", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bwidtcbackgroundthreshold", {
|
||||
get: function() {
|
||||
return o("bw-idtc-background-threshold")
|
||||
},
|
||||
set: function(e) {
|
||||
i("bw-idtc-background-threshold", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "bwsdtcvariance", {
|
||||
get: function() {
|
||||
return o("bw-sdtc-variance")
|
||||
},
|
||||
set: function(e) {
|
||||
i("bw-sdtc-variance", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "threshold", {
|
||||
get: function() {
|
||||
return o("threshold")
|
||||
},
|
||||
set: function(e) {
|
||||
i("threshold", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "brightness", {
|
||||
get: function() {
|
||||
return o("brightness")
|
||||
},
|
||||
set: function(e) {
|
||||
i("brightness", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "contrast", {
|
||||
get: function() {
|
||||
return o("contrast")
|
||||
},
|
||||
set: function(e) {
|
||||
i("contrast", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "shadow", {
|
||||
get: function() {
|
||||
return o("shadow")
|
||||
},
|
||||
set: function(e) {
|
||||
i("shadow", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "highlight", {
|
||||
get: function() {
|
||||
return o("highlight")
|
||||
},
|
||||
set: function(e) {
|
||||
i("highlight", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "gamma", {
|
||||
get: function() {
|
||||
return o("gamma")
|
||||
},
|
||||
set: function(e) {
|
||||
i("gamma", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "multifeeddetection", {
|
||||
get: function() {
|
||||
return o("multifeed-detection")
|
||||
},
|
||||
set: function(e) {
|
||||
i("multifeed-detection", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "mfoverlapping", {
|
||||
get: function() {
|
||||
return o("mf-overlapping")
|
||||
},
|
||||
set: function(e) {
|
||||
i("mf-overlapping", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "mflength", {
|
||||
get: function() {
|
||||
return o("mf-length")
|
||||
},
|
||||
set: function(e) {
|
||||
i("mf-length", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "prepick", {
|
||||
get: function() {
|
||||
return o("prepick")
|
||||
},
|
||||
set: function(e) {
|
||||
i("prepick", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "dropoutcolor", {
|
||||
get: function() {
|
||||
return o("dropoutcolor")
|
||||
},
|
||||
set: function(e) {
|
||||
i("dropoutcolor", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "cleanupsharpness", {
|
||||
get: function() {
|
||||
return o("cleanup-sharpness")
|
||||
},
|
||||
set: function(e) {
|
||||
i("cleanup-sharpness", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "blankpageskip", {
|
||||
get: function() {
|
||||
return o("blank-page-skip")
|
||||
},
|
||||
set: function(e) {
|
||||
i("blank-page-skip", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "blankpageskipsensitivity", {
|
||||
get: function() {
|
||||
return o("blank-page-skip-sensitivity")
|
||||
},
|
||||
set: function(e) {
|
||||
i("blank-page-skip-sensitivity", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "jpeg", {
|
||||
get: function() {
|
||||
return o("jpeg")
|
||||
},
|
||||
set: function(e) {
|
||||
i("jpeg", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "jpegtype", {
|
||||
get: function() {
|
||||
return o("jpeg-type")
|
||||
},
|
||||
set: function(e) {
|
||||
i("jpeg-type", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "jpegquality", {
|
||||
get: function() {
|
||||
return o("jpeg-quality")
|
||||
},
|
||||
set: function(e) {
|
||||
i("jpeg-quality", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "autofeed", {
|
||||
get: function() {
|
||||
return o("autofeed")
|
||||
},
|
||||
set: function(e) {
|
||||
i("autofeed", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "getscstatus", {
|
||||
get: function() {
|
||||
return o("get-sc-status")
|
||||
},
|
||||
set: function(e) {
|
||||
console.error("%c参数只读,不能进行设置", "color:red")
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "getscerror", {
|
||||
get: function() {
|
||||
return o("get-sc-error")
|
||||
},
|
||||
set: function(e) {
|
||||
console.error("%c参数只读,不能进行设置", "color:red")
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "toneadjustment", {
|
||||
get: function() {
|
||||
return o("tone-adjustment")
|
||||
},
|
||||
set: function(e) {
|
||||
i("tone-adjustment", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "edgerepair", {
|
||||
get: function() {
|
||||
return o("edge-repair")
|
||||
},
|
||||
set: function(e) {
|
||||
i("edge-repair", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "holepunchremoval", {
|
||||
get: function() {
|
||||
return o("hole-punch-removal")
|
||||
},
|
||||
set: function(e) {
|
||||
i("hole-punch-removal", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "holepunchremovalfillcolor", {
|
||||
get: function() {
|
||||
return o("hole-punch-removal-fillcolor")
|
||||
},
|
||||
set: function(e) {
|
||||
i("hole-punch-removal-fillcolor", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "holepunchremovalmode", {
|
||||
get: function() {
|
||||
return o("hole-punch-removal-mode")
|
||||
},
|
||||
set: function(e) {
|
||||
i("hole-punch-removal-mode", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "rotation", {
|
||||
get: function() {
|
||||
return o("rotation")
|
||||
},
|
||||
set: function(e) {
|
||||
i("rotation", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "splitimage", {
|
||||
get: function() {
|
||||
return o("split-image")
|
||||
},
|
||||
set: function(e) {
|
||||
i("split-image", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "frontbackmerging", {
|
||||
get: function() {
|
||||
return o("front-back-merging")
|
||||
},
|
||||
set: function(e) {
|
||||
i("front-back-merging", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "backsidelocation", {
|
||||
get: function() {
|
||||
return o("back-side-location")
|
||||
},
|
||||
set: function(e) {
|
||||
i("back-side-location", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "backsiderotation", {
|
||||
get: function() {
|
||||
return o("back-side-rotation")
|
||||
},
|
||||
set: function(e) {
|
||||
i("back-side-rotation", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "colorcleanup", {
|
||||
get: function() {
|
||||
return o("color-cleanup")
|
||||
},
|
||||
set: function(e) {
|
||||
i("color-cleanup", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "colorcleanupcleanness", {
|
||||
get: function() {
|
||||
return o("color-cleanup-cleanness")
|
||||
},
|
||||
set: function(e) {
|
||||
i("color-cleanup-cleanness", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "timescan", {
|
||||
get: function() {
|
||||
return o("time-scan")
|
||||
},
|
||||
set: function(e) {
|
||||
i("time-scan", r(e))
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "intervaltime", {
|
||||
get: function() {
|
||||
return o("interval-time")
|
||||
},
|
||||
set: function(e) {
|
||||
i("interval-time", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "imprinter", {
|
||||
get: function() {
|
||||
return o("imprinter")
|
||||
},
|
||||
set: function(e) {
|
||||
i("imprinter", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "string", {
|
||||
get: function() {
|
||||
return o("string")
|
||||
},
|
||||
set: function(e) {
|
||||
i("string", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "offset", {
|
||||
get: function() {
|
||||
return o("offset")
|
||||
},
|
||||
set: function(e) {
|
||||
i("offset", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "initialcountervalue", {
|
||||
get: function() {
|
||||
return o("initial-counter-value")
|
||||
},
|
||||
set: function(e) {
|
||||
i("initial-counter-value", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "counterstep", {
|
||||
get: function() {
|
||||
return o("counter-step")
|
||||
},
|
||||
set: function(e) {
|
||||
i("counter-step", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "fonttype", {
|
||||
get: function() {
|
||||
return o("font-type")
|
||||
},
|
||||
set: function(e) {
|
||||
i("font-type", String(e)
|
||||
.trim())
|
||||
}
|
||||
}), Object.defineProperty(psl.sane, "fontdirection", {
|
||||
get: function() {
|
||||
return o("font-direction")
|
||||
},
|
||||
set: function(e) {
|
||||
i("font-direction", String(e)
|
||||
.trim())
|
||||
}
|
||||
});
|
||||
var d, b, m = "",
|
||||
y = {},
|
||||
S = {},
|
||||
O = {},
|
||||
h = null,
|
||||
j = function() {},
|
||||
P = function() {},
|
||||
v = function() {},
|
||||
w = function() {},
|
||||
k = function() {},
|
||||
N = function() {},
|
||||
D = function() {},
|
||||
C = function() {},
|
||||
x = function(e) {
|
||||
console.error("%c" + e, "color:red")
|
||||
};
|
||||
e.psl.sane.init = s, e.psl.sane.registerevent = c, e.psl.sane.getdevices = a, e.psl.sane.getsettinginfo = u, e.psl.sane.scan = f, e.psl.sane.converttobase64 = p, e.psl.sane.clear = l
|
||||
}(window)
|
||||
}]);
|
|
@ -0,0 +1,201 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test!</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script type="text/javascript" src="psl.sane.webapi.min 2.1.0.js" charset="utf-8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<h1>Test!</h1>
|
||||
<select id="devicenames" style="width:200px; height:25px;">
|
||||
</select>
|
||||
<input id="getdevices" type="button" value="获取设备列表" onclick="getdevices()" /><br>
|
||||
<label for="showbase64">显示Base64:</label>
|
||||
<input type="checkbox" id="showbase64"><br>
|
||||
<label for="source">单/双面:</label>
|
||||
<select id="source">
|
||||
<option value="Adf-front">Adf-front</option>
|
||||
<option value="Adf-back">Adf-back</option>
|
||||
<option value="Adf-duplex" selected>Adf-duplex</option>
|
||||
</select><br>
|
||||
<label for="mode">颜色模式:</label>
|
||||
<select id="mode">
|
||||
<option value="Lineart">Lineart</option>
|
||||
<option value="Gray">Gray</option>
|
||||
<option value="Color" selected>Color</option>
|
||||
</select><br>
|
||||
<label for="resolution">分辨率:</label>
|
||||
<input type="number" id="resolution" min="1" max="600" value="200" step="1"><br>
|
||||
<input id="scan" type="button" value="扫描" onclick="scan()" /><br>
|
||||
<input id="getsettinginfo" type="button" value="获取扫描参数" onclick="getsettinginfo()" />
|
||||
<input id="converttobase64" type="button" value="转换Base64" onclick="converttobase64()" />
|
||||
</p>
|
||||
<p>
|
||||
<img id="myCanvas" width='640' height='480' style="background-color: black;"/>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" id="pathinfo" style="width:640px; height:40px;" />
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" id="errinfo" style="width:640px; height:40px;" />
|
||||
</p>
|
||||
<script>
|
||||
|
||||
function onGetDevicesFunc(devs)
|
||||
{
|
||||
//alert(JSON.stringify(devs));
|
||||
|
||||
var select = document.getElementById('devicenames');
|
||||
select.innerHTML = "";
|
||||
for (var i = 0; i < devs.length; ++i)
|
||||
{
|
||||
var option = document.createElement('option');
|
||||
option.value = devs[i]['Name'];
|
||||
option.textContent = devs[i]['Name'];
|
||||
select.appendChild(option);
|
||||
}
|
||||
}
|
||||
|
||||
function onDetectDevicesFunc(devs)
|
||||
{
|
||||
//alert(JSON.stringify(devs));
|
||||
|
||||
var select = document.getElementById('devicenames');
|
||||
select.innerHTML = "";
|
||||
for (var i = 0; i < devs.length; ++i)
|
||||
{
|
||||
var option = document.createElement('option');
|
||||
option.value = devs[i]['Name'];
|
||||
option.textContent = devs[i]['Name'];
|
||||
select.appendChild(option);
|
||||
}
|
||||
}
|
||||
|
||||
function onGetSettingInfoFunc(optList)
|
||||
{
|
||||
alert(optList);
|
||||
}
|
||||
|
||||
function onGetBase64Func(base64)
|
||||
{
|
||||
if (base64)
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = base64;
|
||||
}
|
||||
}
|
||||
|
||||
function onScanOneFileDoneFunc(datatype, liveDetect, imgfmt, imgpath, imgbase64data)
|
||||
{
|
||||
if (imgpath)
|
||||
{
|
||||
var pathinfo = document.getElementById('pathinfo');
|
||||
pathinfo.value = imgpath;
|
||||
}
|
||||
|
||||
if (imgbase64data)
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = imgbase64data;
|
||||
}
|
||||
}
|
||||
|
||||
function onScanAllFilesDoneFunc(str)
|
||||
{
|
||||
alert(str);
|
||||
}
|
||||
|
||||
function onScanMultiPagesFileDoneFunc(imgfmt, imgpath)
|
||||
{
|
||||
if (imgpath)
|
||||
{
|
||||
var pathinfo = document.getElementById('pathinfo');
|
||||
pathinfo.value = imgpath;
|
||||
}
|
||||
}
|
||||
|
||||
function onErrorMessageFunc(errormsg)
|
||||
{
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = errormsg;
|
||||
}
|
||||
|
||||
function getdevices()
|
||||
{
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = "";
|
||||
|
||||
psl.sane.getdevices();
|
||||
}
|
||||
|
||||
function scan()
|
||||
{
|
||||
var pathinfo = document.getElementById('pathinfo');
|
||||
pathinfo.value = "";
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = "";
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = 'placeholder.png';
|
||||
|
||||
psl.sane.showbase64 = document.getElementById('showbase64').checked ? 1 : 0;
|
||||
psl.sane.source = document.getElementById('source').value;
|
||||
psl.sane.mode = document.getElementById('mode').value;
|
||||
psl.sane.resolution = parseInt(document.getElementById('resolution').value, 10);
|
||||
psl.sane.deletefilesbeforescan = 1;
|
||||
psl.sane.filepath = "D:\\123456";
|
||||
psl.sane.fileprefix = "KKKKKK";
|
||||
psl.sane.filetype = 6;
|
||||
|
||||
psl.sane.scan(document.getElementById('devicenames').value);
|
||||
}
|
||||
|
||||
function getsettinginfo()
|
||||
{
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = "";
|
||||
|
||||
psl.sane.getsettinginfo(document.getElementById('devicenames').value);
|
||||
}
|
||||
|
||||
function converttobase64()
|
||||
{
|
||||
var pathinfo = document.getElementById('pathinfo');
|
||||
pathinfo.value = "";
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = "";
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = 'placeholder.png';
|
||||
|
||||
psl.sane.converttobase64('D:\\1.png');
|
||||
}
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var pathinfo = document.getElementById('pathinfo');
|
||||
pathinfo.value = "";
|
||||
var errinfo = document.getElementById('errinfo');
|
||||
errinfo.value = "";
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = 'placeholder.png';
|
||||
|
||||
psl.sane.registerevent("OnGetDevices", onGetDevicesFunc);
|
||||
psl.sane.registerevent("OnDetectDevices", onDetectDevicesFunc);
|
||||
psl.sane.registerevent("OnGetSettingInfo", onGetSettingInfoFunc);
|
||||
psl.sane.registerevent("OnGetBase64", onGetBase64Func);
|
||||
psl.sane.registerevent("OnScanOneFileDone", onScanOneFileDoneFunc);
|
||||
psl.sane.registerevent("OnScanAllFilesDone", onScanAllFilesDoneFunc);
|
||||
psl.sane.registerevent("OnScanMultiPagesFileDone", onScanMultiPagesFileDoneFunc);
|
||||
psl.sane.registerevent("OnErrorMessage", onErrorMessageFunc);
|
||||
|
||||
psl.sane.init(23165, true);
|
||||
}
|
||||
|
||||
window.onbeforeunload = function()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue