parent
91dabae7c4
commit
6a5997200b
Binary file not shown.
|
@ -1224,11 +1224,15 @@ namespace ver_2
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (m_initDevice)
|
if (m_initDevice)
|
||||||
|
{
|
||||||
|
errInfo = "已初始化";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SANE_Int version_code = 0;
|
SANE_Int version_code = 0;
|
||||||
if (SANE_STATUS_GOOD != sane_init_ex(&version_code, sane_ex_callback, this))
|
if (SANE_STATUS_GOOD != sane_init_ex(&version_code, sane_ex_callback, this))
|
||||||
{
|
{
|
||||||
|
errInfo = "初始化失败";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,7 +1246,10 @@ namespace ver_2
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_initDevice)
|
if (!m_initDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未初始化";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
std::string errInfo2;
|
std::string errInfo2;
|
||||||
CloseDevice(errInfo2);
|
CloseDevice(errInfo2);
|
||||||
|
@ -1265,7 +1272,10 @@ namespace ver_2
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_initDevice)
|
if (!m_initDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未初始化";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
HGBase_EnterLock(m_lock);
|
HGBase_EnterLock(m_lock);
|
||||||
deviceNameList = m_devNameList;
|
deviceNameList = m_devNameList;
|
||||||
|
@ -1278,13 +1288,25 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_initDevice || m_openDevice)
|
if (!m_initDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未初始化";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_openDevice)
|
||||||
|
{
|
||||||
|
errInfo = "已打开设备";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SANE_Handle dev = NULL;
|
SANE_Handle dev = NULL;
|
||||||
SANE_Status status = sane_open(deviceName.c_str(), &dev);
|
SANE_Status status = sane_open(deviceName.c_str(), &dev);
|
||||||
if (SANE_STATUS_GOOD != status)
|
if (SANE_STATUS_GOOD != status)
|
||||||
|
{
|
||||||
|
errInfo = Utf8ToStdString(sane_strstatus(status));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// 从配置文件加载devParams
|
// 从配置文件加载devParams
|
||||||
std::vector<DeviceParam> devParams;
|
std::vector<DeviceParam> devParams;
|
||||||
|
@ -1310,7 +1332,10 @@ namespace ver_2
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice)
|
if (!m_openDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
std::string errInfo2;
|
std::string errInfo2;
|
||||||
StopScan(errInfo2);
|
StopScan(errInfo2);
|
||||||
|
@ -1325,12 +1350,45 @@ namespace ver_2
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ManagerV2::GetDeviceSN(std::string& sn, std::string& errInfo)
|
||||||
|
{
|
||||||
|
errInfo = "错误";
|
||||||
|
sn.clear();
|
||||||
|
|
||||||
|
if (!m_openDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char v[256] = {0};
|
||||||
|
SANE_Status status = sane_control_option(m_devHandle, (SANE_Int)0x8856, SANE_ACTION_GET_VALUE, v, NULL);
|
||||||
|
if (SANE_STATUS_GOOD != status)
|
||||||
|
{
|
||||||
|
errInfo = Utf8ToStdString(sane_strstatus(status));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sn = v;
|
||||||
|
errInfo.clear();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ManagerV2::SetDeviceParam(const std::vector<DeviceParam>& devParams, std::string& errInfo)
|
int ManagerV2::SetDeviceParam(const std::vector<DeviceParam>& devParams, std::string& errInfo)
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice || m_scanning)
|
if (!m_openDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_scanning)
|
||||||
|
{
|
||||||
|
errInfo = "已启动扫描";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// 设置devParams到设备
|
// 设置devParams到设备
|
||||||
int ret = SetParamsToDevice(m_devHandle, devParams);
|
int ret = SetParamsToDevice(m_devHandle, devParams);
|
||||||
|
@ -1351,8 +1409,17 @@ namespace ver_2
|
||||||
devParams.clear();
|
devParams.clear();
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice || m_devParams.empty())
|
if (!m_openDevice)
|
||||||
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_devParams.empty())
|
||||||
|
{
|
||||||
|
errInfo = "获取设备信息失败";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
devParams = m_devParams;
|
devParams = m_devParams;
|
||||||
errInfo.clear();
|
errInfo.clear();
|
||||||
|
@ -1363,8 +1430,17 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice || m_scanning)
|
if (!m_openDevice)
|
||||||
return -1;
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_scanning)
|
||||||
|
{
|
||||||
|
errInfo = "已启动扫描";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// 重置参数
|
// 重置参数
|
||||||
int ret = ResetParamsToDevice(m_devHandle);
|
int ret = ResetParamsToDevice(m_devHandle);
|
||||||
|
@ -1384,8 +1460,11 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice)
|
if (!m_openDevice)
|
||||||
return -1;
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
deviceName = m_devName;
|
deviceName = m_devName;
|
||||||
errInfo.clear();
|
errInfo.clear();
|
||||||
|
@ -1396,8 +1475,17 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_openDevice || m_scanning)
|
if (!m_openDevice)
|
||||||
return -1;
|
{
|
||||||
|
errInfo = "还未打开设备";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_scanning)
|
||||||
|
{
|
||||||
|
errInfo = "已启动扫描";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
m_scanBlankCheck = blankCheck;
|
m_scanBlankCheck = blankCheck;
|
||||||
m_scanTemp = temp;
|
m_scanTemp = temp;
|
||||||
|
@ -1407,6 +1495,7 @@ namespace ver_2
|
||||||
SANE_Status status = sane_start(m_devHandle);
|
SANE_Status status = sane_start(m_devHandle);
|
||||||
if (SANE_STATUS_GOOD != status)
|
if (SANE_STATUS_GOOD != status)
|
||||||
{
|
{
|
||||||
|
errInfo = Utf8ToStdString(sane_strstatus(status));
|
||||||
HGBase_DestroyEvent(m_scanEvent);
|
HGBase_DestroyEvent(m_scanEvent);
|
||||||
m_scanEvent = NULL;
|
m_scanEvent = NULL;
|
||||||
m_scanBlankCheck = false;
|
m_scanBlankCheck = false;
|
||||||
|
@ -1423,8 +1512,11 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
||||||
if (!m_scanning)
|
if (!m_scanning)
|
||||||
return -1;
|
{
|
||||||
|
errInfo = "还未启动扫描";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
assert(NULL != m_devHandle);
|
assert(NULL != m_devHandle);
|
||||||
sane_cancel(m_devHandle);
|
sane_cancel(m_devHandle);
|
||||||
|
|
|
@ -189,6 +189,8 @@ namespace ver_2
|
||||||
int OpenDevice(const std::string& deviceName, std::string& errInfo);
|
int OpenDevice(const std::string& deviceName, std::string& errInfo);
|
||||||
// 关闭设备
|
// 关闭设备
|
||||||
int CloseDevice(std::string& errInfo);
|
int CloseDevice(std::string& errInfo);
|
||||||
|
// 获取设备序列号
|
||||||
|
int GetDeviceSN(std::string& sn, std::string& errInfo);
|
||||||
// 设置设备参数
|
// 设置设备参数
|
||||||
int SetDeviceParam(const std::vector<DeviceParam>& devParams, std::string& errInfo);
|
int SetDeviceParam(const std::vector<DeviceParam>& devParams, std::string& errInfo);
|
||||||
// 获取设备参数
|
// 获取设备参数
|
||||||
|
|
|
@ -314,6 +314,10 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
CloseDevice(json);
|
CloseDevice(json);
|
||||||
}
|
}
|
||||||
|
else if ("get_device_sn" == func)
|
||||||
|
{
|
||||||
|
GetDeviceSN(json);
|
||||||
|
}
|
||||||
else if ("set_device_param" == func)
|
else if ("set_device_param" == func)
|
||||||
{
|
{
|
||||||
SetDeviceParam(json);
|
SetDeviceParam(json);
|
||||||
|
@ -2432,6 +2436,40 @@ namespace ver_2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSUser::GetDeviceSN(cJSON* json)
|
||||||
|
{
|
||||||
|
assert(NULL != json);
|
||||||
|
|
||||||
|
std::string sn;
|
||||||
|
std::string errInfo;
|
||||||
|
int ret = GetManager()->GetDeviceSN(sn, errInfo);
|
||||||
|
|
||||||
|
bool findIden = false;
|
||||||
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||||
|
|
||||||
|
cJSON* retJson = cJSON_CreateObject();
|
||||||
|
if (NULL != retJson)
|
||||||
|
{
|
||||||
|
cJSON_AddItemToObject(retJson, "func", cJSON_CreateString("get_device_sn"));
|
||||||
|
if (findIden)
|
||||||
|
cJSON_AddItemToObject(retJson, "iden", cJSON_CreateString(iden.c_str()));
|
||||||
|
cJSON_AddItemToObject(retJson, "ret", cJSON_CreateNumber(ret));
|
||||||
|
if (0 != ret)
|
||||||
|
cJSON_AddItemToObject(retJson, "err_info", cJSON_CreateString(StdStringToUtf8(errInfo).c_str()));
|
||||||
|
else
|
||||||
|
cJSON_AddItemToObject(retJson, "sn", cJSON_CreateString(StdStringToUtf8(sn).c_str()));
|
||||||
|
|
||||||
|
char* resp = cJSON_Print(retJson);
|
||||||
|
if (NULL != resp)
|
||||||
|
{
|
||||||
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||||
|
free(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(retJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WSUser::SetDeviceParam(cJSON* json)
|
void WSUser::SetDeviceParam(cJSON* json)
|
||||||
{
|
{
|
||||||
assert(NULL != json);
|
assert(NULL != json);
|
||||||
|
|
|
@ -57,6 +57,7 @@ namespace ver_2
|
||||||
void GetDeviceNameList(cJSON* json);
|
void GetDeviceNameList(cJSON* json);
|
||||||
void OpenDevice(cJSON* json);
|
void OpenDevice(cJSON* json);
|
||||||
void CloseDevice(cJSON* json);
|
void CloseDevice(cJSON* json);
|
||||||
|
void GetDeviceSN(cJSON* json);
|
||||||
void SetDeviceParam(cJSON* json);
|
void SetDeviceParam(cJSON* json);
|
||||||
void GetDeviceParam(cJSON* json);
|
void GetDeviceParam(cJSON* json);
|
||||||
void ResetDeviceParam(cJSON* json);
|
void ResetDeviceParam(cJSON* json);
|
||||||
|
|
|
@ -137,6 +137,10 @@
|
||||||
{
|
{
|
||||||
alert(msg.data);
|
alert(msg.data);
|
||||||
}
|
}
|
||||||
|
else if ("get_device_sn" == message['func'])
|
||||||
|
{
|
||||||
|
alert(msg.data);
|
||||||
|
}
|
||||||
else if ("set_device_param" == message['func'])
|
else if ("set_device_param" == message['func'])
|
||||||
{
|
{
|
||||||
alert(msg.data);
|
alert(msg.data);
|
||||||
|
@ -559,6 +563,13 @@
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetDeviceSN()
|
||||||
|
{
|
||||||
|
socket.send(JSON.stringify({
|
||||||
|
'func':'get_device_sn'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function SetDeviceParam()
|
function SetDeviceParam()
|
||||||
{
|
{
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
|
@ -933,6 +944,7 @@
|
||||||
<input type="button" value="获取设备列表" onclick="GetDevNameList()" />
|
<input type="button" value="获取设备列表" onclick="GetDevNameList()" />
|
||||||
<input type="button" value="打开设备" onclick="OpenDevice()" />
|
<input type="button" value="打开设备" onclick="OpenDevice()" />
|
||||||
<input type="button" value="关闭设备" onclick="CloseDevice()" />
|
<input type="button" value="关闭设备" onclick="CloseDevice()" />
|
||||||
|
<input type="button" value="获取序列号" onclick="GetDeviceSN()" />
|
||||||
<input type="button" value="设置设备参数" onclick="SetDeviceParam()" />
|
<input type="button" value="设置设备参数" onclick="SetDeviceParam()" />
|
||||||
<input type="button" value="获取设备参数" onclick="GetDeviceParam()" />
|
<input type="button" value="获取设备参数" onclick="GetDeviceParam()" />
|
||||||
<input type="button" value="重置设备参数" onclick="ResetDeviceParam()" />
|
<input type="button" value="重置设备参数" onclick="ResetDeviceParam()" />
|
||||||
|
|
Loading…
Reference in New Issue