473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.SourceManager(self.winfo_id(),ProductName='f oo')
self.SD = self.SM.OpenSource()

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(twain.ICAP_CONTRAST)

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.GetCapabilityDefault(twain.ICAP_CON TRAST)

gives me capDef==( 7, 0.0 ). According to my introspection of the twain
module, the type 7 is twain.TWTY_FIX32. 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(twain.ICAP_XSCALING)

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.GetCapabilityDefault(twain.ICAP_XSC ALING)

gives me capDef==( 4, 100 ). More introspection says that type 4 is
twain.TWTY_UINT16. 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.GetCapability 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
Universitetslektor (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 1957

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

Similar topics

0
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...
0
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,...
3
by: Konrad | last post by:
Hi Can you point me articles concerning using of twain drivers for grabbing image from camera. Thanks Konrad
4
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...
2
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...
5
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...
4
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...
3
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.