dynarithmic / twain_library

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

how to stop or terminate the scan #56

Closed madeline0528 closed 1 week ago

madeline0528 commented 1 year ago

I use the DTWAIN_AcquireFile api to acquire the image,but I don't want to these images,how do I stop or terminate it?

dynarithmic commented 1 year ago

Not clear what you are asking, but if your goal is to stop the feeder, you can set up the application to get the DTWAIN_TN_PAGECONTINUE notification, and return 0 or 2 back to DTWAIN when this notification is sent.

This is not documented fully (will need to update it), but you will see DTWAIN_TN_PAGECONTINUE explained here.

madeline0528 commented 1 year ago

What I mean is that,I want to stop the scanner to acquire images when the images are acquiring,which api should I use?DTWAIN_TN_PAGECONTINUE notification is dtwain triggered,not the user,is that right?

dynarithmic commented 1 year ago

Yes, DTWAIN_TN_PAGECONTINUE is sent to the application by DTWAIN. You need to respond to it by returning the desired value. By default (returning a 1), it does nothing, but returning a 0 should act in stopping the scanning process. If returning 0 doesn't reset the scanner, then try returning 2 (which makes a call to stop the feeder directly).

But be aware that stopping the scanner when already set up to scan all (or a set) number of pages is highly dependent on the device as to how it will behave. Some devices may eject all the remaining pages, some will report an error, others may stop right away and report no error. Just be aware of the possible consequences of stopping the scanning process abruptedly.

Also, please state the model of the scanner you are using. This way, I have an idea of what may happen, and address any issues if there are problems.

madeline0528 commented 1 year ago

The production of scanner which I use is HuaGao,and the model of the scanner is one of these:HS-8010Pro、HS-7010Pro、HS-6010Pro、P-5010Pro、Hi-4010Pro、HS-6010Pro、HS-4010Pro、i-5010UW、Hi-5010Pro、i-6010UW、Hi-6010Pro、p-6010pro、HS-6010UW、i-6010P、G-0701W、i-6010Pro

madeline0528 commented 1 year ago

I saw the twain pdf,which write:To discard all pending images, use the DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET operation. Does the dtwain support it?

dynarithmic commented 1 year ago

The DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET will be automatically done if DTWAIN_TN_PAGECONTINUE is returned 0.

Also, in general, you are free to call any TWAIN triplet by using DTWAIN_CallDSMProc. But this requires that you know exactly what you are doing.

dynarithmic commented 1 year ago

Also, if you eventually want to debug the library source code, basically all of the logic for DTWAIN_TN_PAGECONTINUE is found here.

A notification is sent out, and the return value of 0 issues the ResetTransfer(MSG_RESET)

exactly as mentioned by the TWAIN specification.

dynarithmic commented 1 year ago

Another question: What computer language are you using? Is it C#, C++, etc.?

Also, I made a few changes to the libraries in the development branch. Please test your application using the release versions found here (32-bit) and here (64-bit).

madeline799 commented 1 year ago

OK,thanks, and I use Javascript

dynarithmic commented 1 year ago

Thanks. I would like to know how you used Javacript with the library. The reason is that unfortunately, I am not a JS expert, and would like to know how you were able to get the library to work with JavaScript.

We currently have Java, C#, Delphi, Python, and a few other languages working with the library, but haven't come up with the interface for JS.

madeline799 commented 1 year ago

I use the node Library ffi to call the api of dtwail.dll.But I have a question,how do I define these variablesDG_CONTROL / DAT_PENDINGXFERS / MSG_RESET when I use DTWAIN_CallDSMProc.

dynarithmic commented 1 year ago

Ok. I will have to look into ffi.

The TWAIN constants are in twain.h.

DG_CONTROL = 1 DAT_PENDINGXFERS = 5 MSG_RESET = 7

madeline799 commented 1 year ago

Thanks,and other question is when dtwain api is calling,(for example DTWAIN_AcquireFile )the other api can not be called,do you know the reason?

dynarithmic commented 1 year ago

the other api can not be called

Can you clarify this question? I am not sure what you mean here.

madeline799 commented 1 year ago

When the DTWAIN_AcquireFile is calling,I use DTWAIN_CallDSMProc to terminate the scanner,but it was not called,I have no idea about it.(The requirement is to stop the scanner if user do not want to scan.)

dynarithmic commented 1 year ago

What verification do you have that the function was not called? The function must have been called, and possibly you are passing in bad application and/or source identity values. What is the return value?

This can also be verified by generating a log (DTWAIN_SetTwainLog) and seeing the call go through to the TWAIN system by looking at the function call and the sequence of steps that occur before returning.

Also, did you try what was suggested earlier? Doing things like stopping the scanner are best done for languages that have callback mechanisms, and I do not know if ffi has such capabiltiies. If not, then you may be stuck.

Finally, the scanners you mentioned are not sold in the part of the world where I am located. The worst case scenario is to get the source code, compile, and debug what is going on.

dynarithmic commented 1 week ago

Closing. Only will reopen if the issue has not been resolved.