473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Twain problems

Hi all!

Sorry for this rather lengthy post. It's a long preamble followed by a few
questions based on that.

Here's my situation: I am trying to write a specialized scanner utility for
my own needs, and I want to use the module twain to control my scanner. I
haven't used the twain module before, which is most certainly why I'm facing
problems. My problem is to interprete some of the information I get from the
scanner. The scanner, by the way, is an HP LaserJet 3020, which is a
multi-toy (printer/scanner/copyer), and I use Python 2.3 on Windows XP.

I set up communication with the scanner as follows (modulo a few ifs to take
care of unsuccessful connections). Here self is an instance of a class with
Tkinter.Tk as its base class.

self.SM = twain.SourceMan ager(self.winfo _id(),ProductNa me='foo')
self.SD = self.SM.OpenSou rce()

The TWAIN dialog pops up nicely, and I get two options: "hp LaserJet 3020
TWAIN 1.0 (32-32)" and "WIA-hp LaserJet 3020 1.0 (32-32)". The first choice
is HPs interface to the scanner, while the second seems to be a scanner
interface that comes with Windows.

One issue arises if I choose "WIA-hp LaserJet 3020 1.0 (32-32)" and then do
the following:

capVal=self.SD. GetCapability(t wain.ICAP_CONTR AST)

After that capVal is

{'StepSize': 1,
'DefaultValue': 0,
'CurrentValue': 0,
'MaxValue': 1000,
'MinValue': 64536}

My educated guess is that 64536 should be interpreted as -1000, since 64536
is -1000 modulo 2**16. One problem is that the twain type is not specified.
So, perhaps I can find the twain type in some other way. The check

capDef=self.SD. GetCapabilityDe fault(twain.ICA P_CONTRAST)

gives me capDef==( 7, 0.0 ). According to my introspection of the twain
module, the type 7 is twain.TWTY_FIX3 2. Googling around gives me the
impression that this corresponds to 32 bits of which the first 16 bits
correspond to the integer part, and the last 16 bits correspond to the
fraction part. I thought that the twain module would take care of sign
issues for me, but it does not seem to do so. OK, I can probably live with
that. In any case, I guess I'll have to.

OK, that's perhaps not so tough.

Another issue arises if I choose "hp LaserJet 3020 TWAIN 1.0 (32-32)" and
then do the following:

capVal=self.SD. GetCapability(t wain.ICAP_XSCAL ING)

After that capVal is

{'StepSize': 429457408,
'DefaultValue': 1,
'CurrentValue': 1,
'MaxValue': 6,
'MinValue': 429457408}

Now I'm in trouble. The problem is to interprete capVal['StepSize'] and
capVal['MinValue']. Both should correspond to some small positive value.
Here the check

capDef=self.SD. GetCapabilityDe fault(twain.ICA P_XSCALING)

gives me capDef==( 4, 100 ). More introspection says that type 4 is
twain.TWTY_UINT 16. So, again googling around, and I find that this
corresponds to an unsigned 16bit integer, but that doesn't help me much
since 429457408 > 2**16. I also notice that capDef[1]==100, while
capVal['DefaultValue']==1, so there must be a scaling factor of 100
(percents, yes I know). But that doesn't change the fact that I'm completely
lost here.

Finally, here are my questions:
Can anyone enlighten me? From the above, I get the impression that the
dictionary returned by self.SD.GetCapa bility in these cases give me integer
approximations of the current and default values. Is that a correct
interpretation? How should I deal with 429457408 in the example above? Are
there other twain-type related issues that I haven't seen yet, that I should
be aware of? Is there some web-resource out there that answers my questions?
Am I simply missing some information that I might already have? At least I
haven't been able to find any enlightment in the documentation of the twain
module or in the TWAIN specification. It seems to me that I need to be very
careful with the type of the capabilities. How careful should I be?

Googling for things like TWTY_UINT16 typically results in what I interprete
as C or C++ code, which does not help me much. I'm less fluent in C or C++
than I am in Italian (I can order a beer and buy postcards or stamps, that's
more or less it).

I-cannot-order-a-beer-in-C-but-I-can-in-Python-ly yours
/Mikael Olofsson
Universitetslek tor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet

-----------------------------------------------------------------------
E-Mail: mi****@isy.liu. se
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com Vi söker tenorer och basar!

Jul 18 '05 #1
0 1981

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4827
by: ren | last post by:
Hello all, I'm looking for a method, to program TWAIN directly via API calls... Because the Twain OCX under Windows from Kodak is very slow... When I scan via software or the OCX, the TWAIN driver reloads everytime, I would like to keep it open, so I can close it when I exit the program. Thanx, Paul
0
2311
by: Neil Benn | last post by:
Hello, Has anyone had any success with python twain? I've downloaded it and run the module however, I'm getting a python core crash when calling to SourceManager.OpenSource. Needless to say, I've already tested the scanner with a twain based application and it didn't crash it so I'm guessing that the issue is with the python twain and not the scanner itself. Any tips, helps or <didn't you check that you wally comments> would
3
12873
by: Konrad | last post by:
Hi Can you point me articles concerning using of twain drivers for grabbing image from camera. Thanks Konrad
4
1937
by: Chuck Rewood | last post by:
Can somebody here tell me how to access TWAIN from web ? I am gonna make a button to call TWAIN however, the twain.h from (www.twain.org) need some handle from hWnd (System.Windows.Form ??) What kind of wrapper or is there any namespace available ? Thanks, Riwut
2
3323
by: samuabreu | last post by:
I'm currently developing an API of Twain for Java. As Twain is implemented in C (and in fact Im writing and calling C methods from the app) I couldn't find a better group to search for twain development related issues. Here's my question: Does anyone know why when I negociate the capabilities ICAP_XRESOLUTION and ICAP_YRESOLUTION I'm getting all sorts of repeated random values like: 100, 100, 0, 0, 117, 5, 8, 0, 87, 78, 79, 83, 115,...
5
1374
by: Scott Meddows | last post by:
What EASY TO USE TWAIN component do you guys use? We've tried Pegasus and Leadtools and they are both implementations that we cannot use. Anyone have another suggestion? URLs and comments are appreciated. Thanks Scott
4
9799
by: Dustin Davis | last post by:
I'm hoping there is a TWAIN expert lurking here somewhere :) I'm writing a very customized application. The software will be set up in multiple location and will always have two types of scanners attached to the computer. The scanners are microfilm/fiche and a flatbed. So I've created a scanner setup screen where the user can select the twain source for the fiche/film scanner and the twain source for the flatbed scanner. I'm using an...
3
3330
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm facing what i consider to be a serious problem, because i can't find the solution!!! I've made possible, for the software i'm developing, to aquire images from a scanner using WIA. The problem is that, when i aquire an image in, for instance, photo editor, i have the oportunity to choose between the several drivers availlable for the scanner. These drivers are WIA and Twain drivers. Both. So, the software i'm developing, must be...
1
8361
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm facing what i consider to be a serious problem, because i can't find the solution!!! I've made possible, for the software i'm developing, to aquire images from a scanner using WIA. The problem is that, when i aquire an image in, for instance, photo editor, i have the oportunity to choose between the several drivers availlable for the scanner. These drivers are WIA and Twain drivers. Both. So, the software i'm developing, must be...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.