Compare commits

...

4 Commits

Author SHA1 Message Date
luoliangyi 17a4dbff25 webscan增加自动大小、纸张大小、空白页检测等配置 2024-10-17 10:41:45 +08:00
luoliangyi 7fa2e7872c 完善webscan文件类型设置功能 2024-10-16 17:35:11 +08:00
luoliangyi 77b5b76c85 1)增加立思辰webapi-demo
2)立思辰webscan增加扫描功能
2024-10-16 16:49:36 +08:00
luoliangyi e705ba136a webscan项目增加立思辰新webapi接口 2024-10-16 09:11:27 +08:00
8 changed files with 1778 additions and 88 deletions

View File

@ -4,8 +4,9 @@
WebServer::WebServer(HGMsgPump msgPump) WebServer::WebServer(HGMsgPump msgPump)
{ {
m_msgPump = msgPump; m_msgPump = msgPump;
m_currUserId = 1; m_currUserId = 1;
m_port = 0;
#if defined(HG_CMP_MSC) #if defined(HG_CMP_MSC)
m_sockServer = INVALID_SOCKET; m_sockServer = INVALID_SOCKET;
#else #else
@ -75,6 +76,7 @@ bool WebServer::Open(HGUShort port)
return false; return false;
} }
m_port = port;
m_sockServer = sockServer; m_sockServer = sockServer;
HGBase_OpenThread(ThreadFunc, this, &m_listenThread); HGBase_OpenThread(ThreadFunc, this, &m_listenThread);
assert(NULL != m_listenThread); assert(NULL != m_listenThread);
@ -92,6 +94,17 @@ bool WebServer::Close()
return false; return false;
} }
#if defined(HG_CMP_MSC)
closesocket(m_sockServer);
m_sockServer = INVALID_SOCKET;
#else
close(m_sockServer);
m_sockServer = -1;
#endif
m_port = 0;
HGBase_CloseThread(m_listenThread);
m_listenThread = NULL;
while (!m_vectorUser.empty()) while (!m_vectorUser.empty())
{ {
WebUser* pUser = m_vectorUser[0]; WebUser* pUser = m_vectorUser[0];
@ -100,18 +113,14 @@ bool WebServer::Close()
pUser = NULL; pUser = NULL;
} }
#if defined(HG_CMP_MSC)
closesocket(m_sockServer);
m_sockServer = INVALID_SOCKET;
#else
close(m_sockServer);
m_sockServer = -1;
#endif
HGBase_CloseThread(m_listenThread);
m_listenThread = NULL;
return true; return true;
} }
bool WebServer::IsOld()
{
return (9458 == m_port);
}
void WebServer::Connect(const ConnectParam* param) void WebServer::Connect(const ConnectParam* param)
{ {
assert(NULL != param && this == param->svr); assert(NULL != param && this == param->svr);
@ -232,6 +241,7 @@ int WebServer::GetUserIndex(HGUInt id)
void HGAPI WebServer::ThreadFunc(HGThread thread, HGPointer param) void HGAPI WebServer::ThreadFunc(HGThread thread, HGPointer param)
{ {
(void)thread;
WebServer* p = (WebServer*)param; WebServer* p = (WebServer*)param;
while (1) while (1)

View File

@ -15,6 +15,7 @@ public:
bool Open(HGUShort port); bool Open(HGUShort port);
bool Close(); bool Close();
bool IsOld();
void Connect(const ConnectParam* param); void Connect(const ConnectParam* param);
void DisConnect(const DisConnectParam* param); void DisConnect(const DisConnectParam* param);
@ -34,8 +35,9 @@ private:
private: private:
HGMsgPump m_msgPump; HGMsgPump m_msgPump;
HGUInt m_currUserId; HGUInt m_currUserId;
HGUShort m_port;
#if defined(HG_CMP_MSC) #if defined(HG_CMP_MSC)
SOCKET m_sockServer; SOCKET m_sockServer;
#else #else

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
#include "base/HGThread.h" #include "base/HGThread.h"
#include "base/HGImage.h" #include "base/HGImage.h"
#include "base/HGMsgPump.h" #include "base/HGMsgPump.h"
#include "imgfmt/HGImgFmt.h"
#include "Msg.h" #include "Msg.h"
#include "cJSON.h" #include "cJSON.h"
#include "sane/sane_ex.h" #include "sane/sane_ex.h"
@ -32,6 +33,7 @@ public:
void HandleEvent(const WSEvtParam* param); void HandleEvent(const WSEvtParam* param);
private: private:
// OLD
void GetDeviceList(cJSON *json); void GetDeviceList(cJSON *json);
void SelectDevice(cJSON* json); void SelectDevice(cJSON* json);
void SetScanColorType(cJSON* json); void SetScanColorType(cJSON* json);
@ -39,16 +41,26 @@ private:
void SetDuplex(cJSON* json); void SetDuplex(cJSON* json);
void SetScanJPGQuality(cJSON* json); void SetScanJPGQuality(cJSON* json);
void StartScan(cJSON* json); void StartScan(cJSON* json);
//NEW
void GetDeviceListNew();
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: private:
static void AddOptItem(cJSON* optJson, cJSON* arrayJson, const char *name, const char *value, const char **list);
void PostDisConnectMsg(); void PostDisConnectMsg();
void PostCmdMsg(const HGByte* data, HGUInt dataSize); void PostCmdMsg(const HGByte* data, HGUInt dataSize);
void PostEventMsg(const HGByte* data, HGUInt dataSize); void PostEventMsg(const HGByte* data, HGUInt dataSize);
static void HGAPI ThreadFunc(HGThread thread, HGPointer param); 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); 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(HGImage image);
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); HGBool SetParam(const char* optionName, const HGVoid* data);
HGInt GetDpi();
bool ShakeHand(const std::string& head); bool ShakeHand(const std::string& head);
void Pong(); void Pong();
@ -73,6 +85,23 @@ private:
std::vector<std::string> m_devNameList; std::vector<std::string> m_devNameList;
std::string m_devName; std::string m_devName;
SANE_Handle m_devHandle; SANE_Handle m_devHandle;
int m_dpi;
HGEvent m_scanEvent; 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;
std::string m_pageauto;
std::string m_papersize;
std::string m_blankpageskip;
std::string m_blankpageskipsensitivity;
std::string m_multifeeddetection;
}; };

View File

@ -2,17 +2,27 @@
#include "base/HGInc.h" #include "base/HGInc.h"
#include "base/HGThread.h" #include "base/HGThread.h"
#include "base/HGMsgPump.h" #include "base/HGMsgPump.h"
#include "base/HGUtility.h"
#include "base/HGIni.h"
#include "WebServer.h" #include "WebServer.h"
#include "MsgPumpCallback.h" #include "MsgPumpCallback.h"
#include "lang/app_language.h"
static void HGAPI ThreadFunc(HGThread thread, HGPointer param) static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
{ {
(void)thread; (void)thread;
HGMsgPump msgPump = (HGMsgPump)param; HGMsgPump msgPump = (HGMsgPump)param;
HGChar cfgPath[256];
HGBase_GetConfigPath(cfgPath, 256);
HGChar cfgName[256];
sprintf(cfgName, "%s%s", cfgPath, "config.ini");
WebServer wsServer(msgPump); WebServer wsServer(msgPump);
HGInt port = 9458; //HGInt port = 9458;
HGInt port = 23165;
HGBase_GetProfileInt(cfgName, "connect", "port", 23165, &port);
if (wsServer.Open(port)) if (wsServer.Open(port))
{ {
HGBase_RunMsgPump(msgPump, HGMsgPumpCallback, NULL); HGBase_RunMsgPump(msgPump, HGMsgPumpCallback, NULL);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -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)
}]);

View File

@ -0,0 +1,190 @@
<!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>
<input id="scan" type="button" value="扫描" onclick="scan()" /><br>
<input id="getsettinginfo" type="button" value="获取扫描参数" onclick="getsettinginfo()" /><br>
<input id="converttobase64" type="button" value="转换Base64" onclick="converttobase64()" /><br>
</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 = 1;
psl.sane.source = "Adf-duplex";
psl.sane.mode = "Color";
psl.sane.resolution = "200";
psl.sane.deletefilesbeforescan = 1;
psl.sane.filepath = "D:\\123456";
psl.sane.fileprefix = "KKKKKK";
psl.sane.filetype = 3;
psl.sane.pageauto = 1;
psl.sane.papersize = "A4";
psl.sane.blankpageskip = 0;
psl.sane.blankpageskipsensitivity = 3;
psl.sane.multifeeddetection = "Stop";
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>