Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occasionally, when I call the DTWAIN_EnumSources method, there is a long delay before getting a response #107

Closed
dongshaoyang opened this issue Aug 19, 2024 · 12 comments

Comments

@dongshaoyang
Copy link

When I call the DTWAIN_EnumSources method, there is no response for a long time.

@dynarithmic
Copy link
Owner

dynarithmic commented Aug 20, 2024

The delay can occur due to Windows having to load the DLL's (or .ds files) for each device. This cannot be prevented.

If you have Visual Studio, you can look at the Output Window when running your application, and watch the DLL's that Windows has to load when starting up the TWAIN system and discovering the devices that are attached. You may see that it takes a lot of time to load the DLLs (in the case where you are seeing the slowdown).

@dongshaoyang
Copy link
Author

This is the output log file. The first few attempts didn't produce any results, only the last one was successful.
I don't know what caused it because I am not familiar with DTWAIN
dtwain.log

@dynarithmic
Copy link
Owner

What computer language are you using? I see several repeated attempts of using DTWAIN_SetTwainLog. It looks like you are calling DTWAIN_SetTwainLog in some sort of loop. If you ran the demo DTWDEMO.exe program, do you get the same results with the speed of enumerating the sources?

The DTWAIN_EnumSources uses TWAIN directly to go through the sources, as per the TWAIN specification using the TWAIN triplets that perform "Get the first source" and then "get the next source". The way this works is that TWAIN itself is going to your system and finding all of the .ds extensions and calls on each .ds for basic information.

This is what I mentioned in the previous post -- if it takes the system time to get the information, this is an issue that DTWAIN has no control over. This is why DTWAIN caches the sources found when DTWAIN_EnumSources is called, so that subsequent calls to DTWAIN_EnumSources do not have to go through TWAIN to enumerate the sources again.

@dongshaoyang
Copy link
Author

The programming language I'm using is Go. I did call DTWAIN_SetTwainLog multiple times. As a WebSocket server, I initialize (DTWAIN_SysInitialize) and call DTWAIN_SetTwainLog each time a client establishes a connection, but these calls are made in different threads.
I ran the demo programs DTWDEMO.exe and twacker_32.exe and encountered the same issue, so it’s not a problem with DTWAIN.

@dynarithmic
Copy link
Owner

It really depends on the OS and working environment. For example, I have multiple TWAIN devices (more than 6) that take about a second (not more than two seconds) to enumerate. If you take those devices and installed them on another machine, the enumeration may take longer.

If you want to know exactly what is slowing down the process, create a Go program that pauses in some way (maybe wait for a keypress) before you call DTWAIN_EnumSources. If you have Visual Studio, you open up Visual Studio and attach to the Go process that is running. Then open the Output Window of Visual Studio. Then what you want to do is "unpause" the Go program and look at the Output window. You will see all of the DLL's that are being loaded -- the DLL that shows up being "stuck" is the one that is taking the time to load.

@dongshaoyang
Copy link
Author

Thanks for the feedback. I'll do some more testing a report back. Thank you

@dynarithmic
Copy link
Owner

Since I do not use Go, if possible can you give me a small example of how you set up DTWAIN with the Go language? I may have to make a language binding for Go (and also for Rust), so that programmers of those languages do not have issues with using DTWAIN right away,

If you can't do this, no problem. Just that I would like to get other language examples out there, besides the ones that already exist (C/C++, C#, Python, Java, Delphi, VB).

@dongshaoyang
Copy link
Author

I tried to upload this example to GitHub, but it was not successful. I am not sure why.
So I sent you an email.

@dynarithmic
Copy link
Owner

I didn't get the email.

What you can do is copy and paste a few lines of code of the declaration of the DTWAIN function and a sample line calling the code. For example, in C#, all I would need would have been a couple of sample lines or two declaring a few of the DLL functions.

Unless in Go, you have to have a major coding setup, I should be able to get the general idea of what is required.

@dongshaoyang
Copy link
Author

mian.zip
ok,
A small example of how to set up DTWAIN with Go language

@dynarithmic
Copy link
Owner

I opened up a new issue #109 concerning the Go language, so any updates should go there.

@dongshaoyang
Copy link
Author

Thank you very much, this is not an issue with DTWAIN, so I closed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants