dynarithmic / twain_library

Dynarithmic TWAIN Library, Version 5.x
Apache License 2.0
60 stars 25 forks source link

Java JNI stuck on AVISION AV830Plus scanner #32

Closed hebo1982 closed 2 years ago

hebo1982 commented 2 years ago

java stuck at "DTWAIN_AcquireFile", a dialog show from the scanner driver.

image

public class SimpleAcquire2 {
    public void SimpleTest() throws Exception {
        DTwainJavaAPI api = new DTwainJavaAPI(DTwainJavaAPI.JNIDLLName_64U);
        api.DTWAIN_JavaSysInitialize();
        api.DTWAIN_SetTwainLog(DTwainJavaAPIConstants.DTWAIN_LOG_ALL, "twain.log");

        long TwainSource = api.DTWAIN_SelectSource();
        if (TwainSource != 0) {
            int status = api.DTWAIN_AcquireFile(TwainSource, "test.png", DTwainFileType.FILETYPE_PNG,
                    DTwainJavaAPIConstants.DTWAIN_USELONGNAME, DTwainJavaAPIConstants.DTWAIN_PT_DEFAULT, 1, false,
                    false);
            System.out.println(status);
        }
        api.DTWAIN_JavaSysDestroy();
    }

    public static void main(String[] args) {
        SimpleAcquire2 s = new SimpleAcquire2();
        try {
            s.SimpleTest();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

twain.log.zip

hebo1982 commented 2 years ago

if remove

api.DTWAIN_SetTwainLog(DTwainJavaAPIConstants.DTWAIN_LOG_ALL, "twain.log");

the error is gone. DTWAIN_AcquireFile return 1000. But NO output file.

dynarithmic commented 2 years ago

Please make sure you are looking in the correct location for "test.png".

I would suggest to give a full path name instead of "test.png", to verify that the file actually exists.

hebo1982 commented 2 years ago

@dynarithmic thanks for your replay.


public class SimpleAcquire2 {
    public void SimpleTest() throws Exception {
        DTwainJavaAPI api = new DTwainJavaAPI(DTwainJavaAPI.JNIDLLName_64U);
        api.DTWAIN_JavaSysInitialize();
//      api.DTWAIN_SetTwainLog(DTwainJavaAPIConstants.DTWAIN_LOG_ALL, "twain.log");

        long TwainSource = api.DTWAIN_SelectSource();
        if (TwainSource != 0) {
            int status = api.DTWAIN_AcquireFile(TwainSource, "D:\\test.bmp", DTwainFileType.FILETYPE_BMP,
                    DTwainJavaAPIConstants.DTWAIN_USELONGNAME, DTwainJavaAPIConstants.DTWAIN_PT_BW, 1, false, false);
            System.out.println(status);
        }
        api.DTWAIN_JavaSysDestroy();
    }

    public static void main(String[] args) {
        SimpleAcquire2 s = new SimpleAcquire2();
        try {
            s.SimpleTest();
        } catch (Exception e) {

            e.printStackTrace();
        }

        System.out.println("OK");
    }
}

output:

dtwainjni64u
1000
OK

I fix the path of the file, but still no output file.

dynarithmic commented 2 years ago

Please run the DTWDEMO64u.exe program to determine if this is an issue with DTWAIN itself, or a Java/JNI issue. Right now it is impossible to tell what the issue is by looking at your Java code.

If the image can be acquired successfully using DTWDEMO64u, then the underlying issue is with the Java layer in some way.

Having said that, we are looking to overhaul the entire Java layer and utilize a new interface to the DLL through JNI. The new Java layer hasn't been posted, due to it only working for the experimental branch for version 5.3.0.0 of DTWAIN.

The new version could be posted, but it lacks documentation, thus will require anyone using it to look at the samples to figure out how to use it properly. That will be remedied in the coming weeks (and probably months). If posted, it will be part of the experimental branch listed above.

hebo1982 commented 2 years ago

@dynarithmic

i try DTWDEMO64u.exe

image

Acquire Native, Buffered, File is failed. image

Acquire File(Source Mode) like ok, get a tmp file: image

I change my code use "DTWAIN_USESOURCEMODE" :

int status = api.DTWAIN_AcquireFile(TwainSource, "D:\\test.bmp", DTwainFileType.FILETYPE_BMP,
                    DTwainJavaAPIConstants.DTWAIN_USELONGNAME + DTwainJavaAPIConstants.DTWAIN_USESOURCEMODE,
                    DTwainJavaAPIConstants.DTWAIN_PT_BW, 1, false, false);
// but status return -1
dynarithmic commented 2 years ago

You can generate a log from DTWDEMO by selecting logging from the main menu. Please do that, as it seems there is something very strange about the device you are using.

Also, using "source mode" is only available if your device itself supports the file type. You shouldn't use it unless you are certain that your device supports acquiring to BMP files. The list of file types can be retrieved by calling DTWAIN_IsFileXferSupported.

dynarithmic commented 2 years ago

You can also try the generic Twain Testing programs here. If they do not work, then there is something that is preventing this scanner from working correctly.

The TWACKER programs are directly from the TWAIN Working Group, and use no DTWAIN components.

hebo1982 commented 2 years ago

@dynarithmic

I test "TWACKER" AND twain-samples.

If choose output to a file are failed, but change to native is OK. image

I test DTWDEMO with "native", NO image like this: image

Use java API got a error.

public class SimpleAcquire4 {
    public void SimpleTest() throws Exception {
        DTwainJavaAPI api = new DTwainJavaAPI(DTwainJavaAPI.JNIDLLName_64U);
        api.DTWAIN_JavaSysInitialize();
        // api.DTWAIN_SetTwainLog(DTwainJavaAPIConstants.DTWAIN_LOG_ALL, "twain.log");

        long TwainSource = api.DTWAIN_SelectSource();
        if (TwainSource != 0) {
            DTwainAcquisitionArray array = api.DTWAIN_AcquireNative(TwainSource,
                    DTwainJavaAPIConstants.DTWAIN_PT_DEFAULT, 1, false, false);
            System.out.println(array);
        }
        api.DTWAIN_JavaSysDestroy();
    }

    public static void main(String[] args) {
        SimpleAcquire4 s = new SimpleAcquire4();
        try {
            s.SimpleTest();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

dtwainjni64u
com.dynarithmic.twain.DTwainJavaAPIException: Unrecoverable error in DTWAINJavaAPI.DLL
    at com.dynarithmic.twain.DTwainJavaAPI.DTWAIN_AcquireNative(Native Method)
    at com.dtwain.test.SimpleAcquire4.SimpleTest(SimpleAcquire4.java:16)
    at com.dtwain.test.SimpleAcquire4.main(SimpleAcquire4.java:26)

I think dtwain has something wrong?

dynarithmic commented 2 years ago

1) As mentioned previously, please turn on the logging in the DTWDEMO program. Since I do not have your device, it is impossible to diagnose the issue until a log is presented.

2) Also, you should only test for Native mode and not acquire to a file at this point. Also, do not test without the device user-interface showing. Your code does not show the user interface, and doing that complicates the testing.

3) The Java JNI layer has a lot more things that can go wrong with it besides DTWAIN. It would be better to work solely in C or C++ to solve this issue, as the code would then be directly tied to DTWAIN, instead of a middle layer such as JNI. And doing that would allow you to properly debug the code and see where the issue is.

TWACKER concludes that the device can work, but the difference in DTWAIN is that it puts more faith in the device's handling of TWAIN, unlike TWACKER. For example, more capabilities are queried during the acquisition than with TWACKER.

dynarithmic commented 2 years ago

As mentioned before, since I do not have your device, until a log is produced, you're basically the only person that can debug the issue (unless someone else has this device and can help you), and hopefully report back as to what you've found. You have the device, which goes a long way to get any fix to be done -- without the device, code adjustments are almost impossible. Devices have bugs, manufacturers may not even exist any more, and DTWAIN has to be written to work around all of these issues.

That is the goal of this project, for others to contribute their fixes to the code if they come across a device that doesn't work properly.

As to your issue, it can be debugged by obtaining the full source code here, compiling it by following the directions, and use dtwain64ud.dll (the debug version of the 64-bit DLL) when testing a simple program such as the Simple C console demo here.

hebo1982 commented 2 years ago

Wait a few days, I'm quarantined by COVID-19.

hebo1982 commented 2 years ago

I test on "Canon DR-G1100" and "Panasonic KV-SL1077/66/56 MK2" work well. "AVISION AV830Plus" has issues itself.