diff --git a/build2/qt/HGScannerLib/HGScannerLib.def b/build2/qt/HGScannerLib/HGScannerLib.def index 04814ece..8a96e95c 100644 --- a/build2/qt/HGScannerLib/HGScannerLib.def +++ b/build2/qt/HGScannerLib/HGScannerLib.def @@ -48,4 +48,7 @@ Java_com_easing_java_HGScannerLib_GetDeviceSN Java_com_easing_java_HGScannerLib_GetDeviceFWVersion Java_com_easing_java_HGScannerLib_StartDeviceScan Java_com_easing_java_HGScannerLib_StopDeviceScan -Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList \ No newline at end of file +Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList +Java_com_easing_java_HGScannerLib_GetDeviceParam +Java_com_easing_java_HGScannerLib_SetDeviceParam +Java_com_easing_java_HGScannerLib_ResetDeviceParam \ No newline at end of file diff --git a/sdk/scannerlib/HGScannerLibJni.cpp b/sdk/scannerlib/HGScannerLibJni.cpp index 5cecc167..f96f6155 100644 --- a/sdk/scannerlib/HGScannerLibJni.cpp +++ b/sdk/scannerlib/HGScannerLibJni.cpp @@ -630,5 +630,150 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetD devParamGroupList = env->NewObjectArray(0, clsDeviceParamGroup, env->NewObject(clsDeviceParamGroup, initDeviceParamGroup)); } + printf("\n"); return devParamGroupList; } + +extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetDeviceParam( + JNIEnv* env, jclass clazz, jlong dev, jint option) +{ + (void)clazz; + printf("\nJava_com_easing_java_HGScannerLib_GetDeviceParam\n"); + + jclass clsDeviceParam = env->FindClass("com/easing/java/HGLibDeviceParam"); + jmethodID initDeviceParam = env->GetMethodID(clsDeviceParam, "", "()V"); + jclass clsIntValueRange = env->FindClass("com/easing/java/HGLibDeviceIntValueRange"); + jmethodID initIntValueRange = env->GetMethodID(clsIntValueRange, "", "()V"); + jclass clsDoubleValueRange = env->FindClass("com/easing/java/HGLibDeviceDoubleValueRange"); + jmethodID initDoubleValueRange = env->GetMethodID(clsDoubleValueRange, "", "()V"); + + jobject devParam = env->NewObject(clsDeviceParam, initDeviceParam); + + HGLibDeviceParam* devParam2 = HGLib_GetDeviceParam((HGLibDevice)dev, (HGUInt)option); + if (NULL != devParam2) + { + env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "option", "I"), (jint)devParam2->option); + + env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "type", "I"), (jint)devParam2->type); + if (HGLIB_OPTION_VALUETYPE_INT == devParam2->type) + { + env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "intValue", "I"), (jint)devParam2->intValue); + } + else if (HGLIB_OPTION_VALUETYPE_ENUM == devParam2->type) + { + env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "enumValue", "I"), (jint)devParam2->enumValue); + } + else if (HGLIB_OPTION_VALUETYPE_DOUBLE == devParam2->type) + { + env->SetDoubleField(devParam, env->GetFieldID(clsDeviceParam, "doubleValue", "D"), (jdouble)devParam2->doubleValue); + } + else if (HGLIB_OPTION_VALUETYPE_BOOL == devParam2->type) + { + env->SetBooleanField(devParam, env->GetFieldID(clsDeviceParam, "boolValue", "Z"), (jboolean)devParam2->boolValue); + } + + env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "rangeType", "I"), (jint)devParam2->rangeType); + if (HGLIB_OPTION_VALUERANGETYPE_INTLIST == devParam2->rangeType) + { + jintArray intValueList = env->NewIntArray(devParam2->intValueList.count); + env->SetIntArrayRegion(intValueList, 0, devParam2->intValueList.count, (jint*)devParam2->intValueList.value); + env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueList", "[I"), intValueList); + } + else if (HGLIB_OPTION_VALUERANGETYPE_ENUMLIST == devParam2->rangeType) + { + jintArray enumValueList = env->NewIntArray(devParam2->enumValueList.count); + env->SetIntArrayRegion(enumValueList, 0, devParam2->enumValueList.count, (jint*)devParam2->enumValueList.value); + env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "enumValueList", "[I"), enumValueList); + } + else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLELIST == devParam2->rangeType) + { + jdoubleArray doubleValueList = env->NewDoubleArray(devParam2->doubleValueList.count); + env->SetDoubleArrayRegion(doubleValueList, 0, devParam2->doubleValueList.count, (jdouble*)devParam2->doubleValueList.value); + env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueList", "[D"), doubleValueList); + } + else if (HGLIB_OPTION_VALUERANGETYPE_INTRANGE == devParam2->rangeType) + { + jobject intValueRange = env->NewObject(clsIntValueRange, initIntValueRange); + env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "minValue", "I"), (jint)devParam2->intValueRange.minValue); + env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "maxValue", "I"), (jint)devParam2->intValueRange.maxValue); + env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueRange", "Lcom/easing/java/HGLibDeviceIntValueRange;"), intValueRange); + } + else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLERANGE == devParam2->rangeType) + { + jobject doubleValueRange = env->NewObject(clsDoubleValueRange, initDoubleValueRange); + env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "minValue", "D"), (jdouble)devParam2->doubleValueRange.minValue); + env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "maxValue", "D"), (jdouble)devParam2->doubleValueRange.maxValue); + env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueRange", "Lcom/easing/java/HGLibDeviceDoubleValueRange;"), doubleValueRange); + } + + HGLib_ReleaseDeviceParam(devParam2); + } + + printf("\n"); + return devParam; +} + +extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_SetDeviceParam( + JNIEnv* env, jclass clazz, jlong dev, jobject deviceSetParam) +{ + (void)clazz; + printf("\nJava_com_easing_java_HGScannerLib_SetDeviceParam\n"); + + jclass cls = env->GetObjectClass(deviceSetParam); + HGUInt option = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "option", "I")); + HGUInt type = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "type", "I")); + HGInt intValue = (HGInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "intValue", "I")); + HGUInt enumValue = (HGUInt)env->GetIntField(deviceSetParam, env->GetFieldID(cls, "enumValue", "I")); + HGDouble doubleValue = (HGDouble)env->GetDoubleField(deviceSetParam, env->GetFieldID(cls, "doubleValue", "D")); + HGBool boolValue = (HGBool)env->GetBooleanField(deviceSetParam, env->GetFieldID(cls, "boolValue", "Z")); + + printf("option=%u\n", option); + printf("type=%u\n", type); + + HGVoid *data = NULL; + if (HGLIB_OPTION_VALUETYPE_INT == type) + { + printf("intValue=%d\n", intValue); + data = &intValue; + } + else if (HGLIB_OPTION_VALUETYPE_ENUM == type) + { + printf("enumValue=%u\n", enumValue); + data = &enumValue; + } + else if (HGLIB_OPTION_VALUETYPE_DOUBLE == type) + { + printf("doubleValue=%f\n", doubleValue); + data = &doubleValue; + } + else if (HGLIB_OPTION_VALUETYPE_BOOL == type) + { + printf("boolValue=%d\n", boolValue); + data = &boolValue; + } + + if (NULL == data) + { + printf("Invalid Parameter\n"); + return (jboolean)HGFALSE; + } + + HGBool ret = HGLib_SetDeviceParam((HGLibDevice)dev, option, data); + printf("ret=%d\n", ret); + + printf("\n"); + return (jboolean)ret; +} + +extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_ResetDeviceParam( + JNIEnv* env, jclass clazz, jlong dev) +{ + (void)clazz; + printf("\nJava_com_easing_java_HGScannerLib_ResetDeviceParam\n"); + + HGBool ret = HGLib_ResetDeviceParam((HGLibDevice)dev); + printf("ret=%d\n", ret); + + printf("\n"); + return (jboolean)ret; +} diff --git a/test/scannerlib/huagao/java/com/easing/java/HGScannerLib.java b/test/scannerlib/huagao/java/com/easing/java/HGScannerLib.java index 0344a567..2853b4ea 100644 --- a/test/scannerlib/huagao/java/com/easing/java/HGScannerLib.java +++ b/test/scannerlib/huagao/java/com/easing/java/HGScannerLib.java @@ -52,6 +52,16 @@ class HGLibDeviceParamGroup { public HGLibDeviceParam[] params; } +class HGLibDeviceSetParam { + public int option; + + public int type; + public int intValue; + public int enumValue; + public double doubleValue; + public boolean boolValue; +} + public class HGScannerLib { static { @@ -76,7 +86,7 @@ public class HGScannerLib { public native boolean StopDeviceScan(long dev); public native HGLibDeviceParamGroup[] GetDeviceParamGroupList(long dev); public native HGLibDeviceParam GetDeviceParam(long dev, int option); - public native boolean SetDeviceParam(long dev, HGLibDeviceParam deviceParam); + public native boolean SetDeviceParam(long dev, HGLibDeviceSetParam deviceSetParam); public native boolean ResetDeviceParam(long dev); ; public void onDeviceHotPlugEvent(int event, String deviceName) { @@ -146,6 +156,7 @@ public class HGScannerLib { String fwVersion = inst.GetDeviceFWVersion(dev); System.out.println("fwVersion=" + fwVersion); + /* HGLibDeviceParamGroup[] devParamGroups = inst.GetDeviceParamGroupList(dev); for (int i = 0; i < devParamGroups.length; ++i) { @@ -204,6 +215,15 @@ public class HGScannerLib { } } } + */ + + HGLibDeviceSetParam deviceSetParam = new HGLibDeviceSetParam(); + deviceSetParam.option = 27; + deviceSetParam.type = 1; + deviceSetParam.intValue = 300; + inst.SetDeviceParam(dev, deviceSetParam); + + inst.ResetDeviceParam(dev); //inst.StartDeviceScan(dev);