This commit is contained in:
yangjiaxuan 2023-11-27 15:27:10 +08:00
commit 6f57fbf081
9 changed files with 275 additions and 41 deletions

View File

@ -18,8 +18,12 @@ HGLib_GetDeviceNameList
HGLib_ReleaseDeviceNameList
HGLib_OpenDevice
HGLib_CloseDevice
HGLib_GetDeviceType
HGLib_GetDeviceSN
HGLib_GetDeviceFWVersion
HGLib_GetDeviceRollerCount
HGLib_GetDeviceTotalCount
HGLib_ClearDeviceRollerCount
HGLib_SetDeviceParam
HGLib_GetDeviceParamGroupList
HGLib_GetDeviceParam
@ -48,8 +52,12 @@ Java_com_easing_java_HGScannerLib_DeinitDevice
Java_com_easing_java_HGScannerLib_GetDeviceNameList
Java_com_easing_java_HGScannerLib_OpenDevice
Java_com_easing_java_HGScannerLib_CloseDevice
Java_com_easing_java_HGScannerLib_GetDeviceType
Java_com_easing_java_HGScannerLib_GetDeviceSN
Java_com_easing_java_HGScannerLib_GetDeviceFWVersion
Java_com_easing_java_HGScannerLib_GetDeviceRollerCount
Java_com_easing_java_HGScannerLib_GetDeviceTotalCount
Java_com_easing_java_HGScannerLib_ClearDeviceRollerCount
Java_com_easing_java_HGScannerLib_StartDeviceScan
Java_com_easing_java_HGScannerLib_StopDeviceScan
Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList

View File

@ -391,58 +391,73 @@ HGBool HGLibDeviceImpl::Close()
return HGTRUE;
}
HGBool HGLibDeviceImpl::GetType(HGChar *type, HGUInt maxLen)
{
assert(NULL != m_devHandle);
return GetValueStr256(0x8855, type, maxLen);
}
HGBool HGLibDeviceImpl::GetSN(HGChar* sn, HGUInt maxLen)
{
if (NULL == sn || 0 == maxLen)
{
return HGFALSE;
}
assert(NULL != m_devHandle);
std::string serialNum;
unsigned int serialNumLen = 0;
m_statusCode = sane_io_control(m_devHandle, IO_CTRL_CODE_GET_SERIAL, NULL, &serialNumLen);
if (SANE_STATUS_NO_MEM == m_statusCode && serialNumLen)
{
serialNum.resize(serialNumLen);
m_statusCode = sane_io_control(m_devHandle, IO_CTRL_CODE_GET_SERIAL, &serialNum[0], &serialNumLen);
}
if (serialNum.empty() || maxLen < serialNum.size() + 1)
{
return HGFALSE;
}
strcpy(sn, serialNum.c_str());
return HGTRUE;
return GetValueStr256(0x8856, sn, maxLen);
}
HGBool HGLibDeviceImpl::GetFWVersion(HGChar* fwVersion, HGUInt maxLen)
{
if (NULL == fwVersion || 0 == maxLen)
{
return HGFALSE;
assert(NULL != m_devHandle);
return GetValueStr256(0x8857, fwVersion, maxLen);
}
HGInt HGLibDeviceImpl::GetRollerCount()
{
assert(NULL != m_devHandle);
HGInt ret = -1;
GetValueInt32(0x9902, &ret);
return ret;
}
HGInt HGLibDeviceImpl::GetTotalCount()
{
assert(NULL != m_devHandle);
HGInt ret = -1;
GetValueInt32(0x8849, &ret);
return ret;
}
HGBool HGLibDeviceImpl::ClearRollerCount()
{
assert(NULL != m_devHandle);
std::string versionNum;
unsigned int versionNumLen = 0;
m_statusCode = sane_io_control(m_devHandle, IO_CTRL_CODE_GET_HARDWARE_VERSION, NULL, &versionNumLen);
if (SANE_STATUS_NO_MEM == m_statusCode && versionNumLen)
std::string userName = "user";
std::string password;
#if defined(OEM_HANWANG)
password = "hanvonscan";
#elif defined(OEM_LISICHENG)
password = "lanxum";
#elif defined(OEM_CANGTIAN)
password = "cumtenn";
#elif defined(OEM_ZHONGJING)
password = "microtek";
#elif defined(OEM_ZIGUANG)
password = "uniscan";
#elif defined(OEM_NEUTRAL)
password = "scan";
#elif defined(OEM_DELI)
password = "deliscan";
#else
password = "huagoscan";
#endif
HGBool ret = Login(userName.c_str(), password.c_str());
if (ret)
{
versionNum.resize(versionNumLen);
m_statusCode = sane_io_control(m_devHandle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &versionNum[0], &versionNumLen);
ret = SetValueInt32(0x9902, 0);
Logout();
}
if (versionNum.empty() || maxLen < versionNum.size() + 1)
{
return HGFALSE;
}
strcpy(fwVersion, versionNum.c_str());
return HGTRUE;
return ret;
}
HGBool HGLibDeviceImpl::SetParam(HGUInt option, const HGVoid* data)
@ -1073,6 +1088,81 @@ HGInt HGLibDeviceImpl::GetOperateCode()
return m_statusCode;
}
HGBool HGLibDeviceImpl::Login(const HGChar *user, const HGChar *pwd)
{
if (NULL == user || strlen(user) >= 32
|| NULL == pwd || strlen(pwd) >= 32)
{
return HGFALSE;
}
HGChar value[256] = {0};
strcpy(value, user);
strcpy(value + 32, pwd);
return SetValueStr256(0x9900, value);
}
HGBool HGLibDeviceImpl::Logout()
{
HGChar value[256] = {0};
return SetValueStr256(0x9901, value);
}
HGBool HGLibDeviceImpl::SetValueInt32(HGUInt optionId, HGInt value)
{
SANE_Int v = (SANE_Int)value;
m_statusCode = sane_control_option(m_devHandle, (SANE_Int)optionId, SANE_ACTION_SET_VALUE, &v, NULL);
return (SANE_STATUS_GOOD == m_statusCode) ? HGTRUE : HGFALSE;
}
HGBool HGLibDeviceImpl::GetValueInt32(HGUInt optionId, HGInt *value)
{
SANE_Int v = 0;
m_statusCode = sane_control_option(m_devHandle, (SANE_Int)optionId, SANE_ACTION_GET_VALUE, &v, NULL);
if (SANE_STATUS_GOOD != m_statusCode)
{
return HGFALSE;
}
*value = (HGInt)v;
return HGTRUE;
}
HGBool HGLibDeviceImpl::SetValueStr256(HGUInt optionId, const HGChar *value)
{
if (NULL == value || strlen(value) >= 256)
{
return HGFALSE;
}
const char *v = value;
m_statusCode = sane_control_option(m_devHandle, (SANE_Int)optionId, SANE_ACTION_SET_VALUE, (void*)v, NULL);
return (SANE_STATUS_GOOD == m_statusCode) ? HGTRUE : HGFALSE;
}
HGBool HGLibDeviceImpl::GetValueStr256(HGUInt optionId, HGChar *value, HGUInt maxLen)
{
if (NULL == value || 0 == maxLen)
{
return HGFALSE;
}
char v[256] = {0};
m_statusCode = sane_control_option(m_devHandle, (SANE_Int)optionId, SANE_ACTION_GET_VALUE, v, NULL);
if (SANE_STATUS_GOOD != m_statusCode)
{
return HGFALSE;
}
if (maxLen <= strlen(v))
{
return HGFALSE;
}
strcpy(value, v);
return HGTRUE;
}
const char* HGLibDeviceImpl::GetGroupName(HGUInt group)
{
if (group > HGLIB_GROUP_NAME_PAPERFEEDING)

View File

@ -23,8 +23,12 @@ public:
static HGLibDeviceImpl* Open(const HGChar* deviceName);
HGBool Close();
HGBool GetType(HGChar *type, HGUInt maxLen);
HGBool GetSN(HGChar* sn, HGUInt maxLen);
HGBool GetFWVersion(HGChar* fwVersion, HGUInt maxLen);
HGInt GetRollerCount();
HGInt GetTotalCount();
HGBool ClearRollerCount();
HGBool SetParam(HGUInt option, const HGVoid* data);
HGLibDeviceParamGroup* GetParamGroupList(HGUInt* count);
HGLibDeviceParam* GetParam(HGUInt option);
@ -42,6 +46,12 @@ public:
HGInt GetOperateCode();
private:
HGBool Login(const HGChar *user, const HGChar *pwd);
HGBool Logout();
HGBool SetValueInt32(HGUInt optionId, HGInt value);
HGBool GetValueInt32(HGUInt optionId, HGInt *value);
HGBool SetValueStr256(HGUInt optionId, const HGChar *value);
HGBool GetValueStr256(HGUInt optionId, HGChar *value, HGUInt maxLen);
static const char* GetGroupName(HGUInt group);
static HGUInt GetGroupName(const char* group);
static const char* GetOptionName(HGUInt option);

View File

@ -259,6 +259,17 @@ HGBool HGAPI HGLib_CloseDevice(HGLibDevice device)
return deviceImpl->Close();
}
HGBool HGAPI HGLib_GetDeviceType(HGLibDevice device, HGChar *type, HGUInt maxLen)
{
if (NULL == device)
{
return HGFALSE;
}
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
return deviceImpl->GetType(type, maxLen);
}
HGBool HGAPI HGLib_GetDeviceSN(HGLibDevice device, HGChar* sn, HGUInt maxLen)
{
if (NULL == device)
@ -281,6 +292,39 @@ HGBool HGAPI HGLib_GetDeviceFWVersion(HGLibDevice device, HGChar* fwVersion, HGU
return deviceImpl->GetFWVersion(fwVersion, maxLen);
}
HGInt HGAPI HGLib_GetDeviceRollerCount(HGLibDevice device)
{
if (NULL == device)
{
return -1;
}
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
return deviceImpl->GetRollerCount();
}
HGInt HGAPI HGLib_GetDeviceTotalCount(HGLibDevice device)
{
if (NULL == device)
{
return -1;
}
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
return deviceImpl->GetTotalCount();
}
HGBool HGAPI HGLib_ClearDeviceRollerCount(HGLibDevice device)
{
if (NULL == device)
{
return HGFALSE;
}
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
return deviceImpl->ClearRollerCount();
}
HGBool HGAPI HGLib_SetDeviceParam(HGLibDevice device, HGUInt option, const HGVoid* data)
{
if (NULL == device)

View File

@ -569,12 +569,24 @@ HGEXPORT HGLibDevice HGAPI HGLib_OpenDevice(const HGChar *deviceName);
/* 关闭设备 */
HGEXPORT HGBool HGAPI HGLib_CloseDevice(HGLibDevice device);
/* 获取设备型号 */
HGEXPORT HGBool HGAPI HGLib_GetDeviceType(HGLibDevice device, HGChar *type, HGUInt maxLen);
/* 获取设备序列号 */
HGEXPORT HGBool HGAPI HGLib_GetDeviceSN(HGLibDevice device, HGChar *sn, HGUInt maxLen);
/* 获取设备固件版本号*/
HGEXPORT HGBool HGAPI HGLib_GetDeviceFWVersion(HGLibDevice device, HGChar* fwVersion, HGUInt maxLen);
/* 获取设备滚轴计数 */
HGEXPORT HGInt HGAPI HGLib_GetDeviceRollerCount(HGLibDevice device);
/* 获取设备历史扫描张数 */
HGEXPORT HGInt HGAPI HGLib_GetDeviceTotalCount(HGLibDevice device);
/* 清除滚轴计数 */
HGEXPORT HGBool HGAPI HGLib_ClearDeviceRollerCount(HGLibDevice device);
/* 设置设备参数 */
HGEXPORT HGBool HGAPI HGLib_SetDeviceParam(HGLibDevice device, HGUInt option, const HGVoid *data);

View File

@ -335,6 +335,30 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_CloseDev
return (jboolean)ret;
}
extern "C" JNIEXPORT jstring JNICALL Java_com_easing_java_HGScannerLib_GetDeviceType(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceType\n");
jstring type;
HGChar type2[256];
HGBool ret = HGLib_GetDeviceType((HGLibDevice)dev, type2, 256);
printf("ret=%d\n", ret);
if (ret)
{
type = env->NewStringUTF(type2);
}
else
{
type = env->NewStringUTF(NULL);
}
printf("\n");
return type;
}
extern "C" JNIEXPORT jstring JNICALL Java_com_easing_java_HGScannerLib_GetDeviceSN(
JNIEnv* env, jclass clazz, jlong dev)
{
@ -383,6 +407,48 @@ extern "C" JNIEXPORT jstring JNICALL Java_com_easing_java_HGScannerLib_GetDevice
return fwVersion;
}
extern "C" JNIEXPORT jint JNICALL Java_com_easing_java_HGScannerLib_GetDeviceRollerCount(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceRollerCount\n");
HGInt rollerCount = HGLib_GetDeviceRollerCount((HGLibDevice)dev);
printf("rollerCount=%d\n", rollerCount);
printf("\n");
return (jint)rollerCount;
}
extern "C" JNIEXPORT jint JNICALL Java_com_easing_java_HGScannerLib_GetDeviceTotalCount(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceTotalCount\n");
HGInt totalCount = HGLib_GetDeviceTotalCount((HGLibDevice)dev);
printf("totalCount=%d\n", totalCount);
printf("\n");
return (jint)totalCount;
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_ClearDeviceRollerCount(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)env;
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_ClearDeviceRollerCount\n");
HGBool ret = HGLib_ClearDeviceRollerCount((HGLibDevice)dev);
printf("ret=%d\n", ret);
printf("\n");
return (jboolean)ret;
}
static void HGAPI DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGBool err, const HGChar *info, HGPointer param)
{
(void)param;

View File

@ -81,8 +81,12 @@ public class HGScannerLib {
public native String[] GetDeviceNameList();
public native long OpenDevice(String deviceName);
public native boolean CloseDevice(long dev);
public native String GetDeviceType(long dev);
public native String GetDeviceSN(long dev);
public native String GetDeviceFWVersion(long dev);
public native int GetDeviceRollerCount(long dev);
public native int GetDeviceTotalCount(long dev);
public native boolean ClearDeviceRollerCount(long dev);
public native boolean StartDeviceScan(long dev);
public native boolean StopDeviceScan(long dev);
public native HGLibDeviceParamGroup[] GetDeviceParamGroupList(long dev);