python-pillow / Sane

Python interface to the SANE scanner and frame grabber
Other
55 stars 19 forks source link

Example not working ?? #32

Closed Erim32 closed 7 years ago

Erim32 commented 7 years ago

Hi, great job. Sane example code looks not working ?

> python test-scan.py 
> SANE version: (16777241, 1, 0, 25)
> Available devices: [('pixma:MG3500_192.168.1.70', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral'), ('pixma:04A9176E_40BBB1', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral')]
> Traceback (most recent call last):
>  File "test-scan.py", line 29, in <module>
>     dev = sane.open(devices[0][0])
>   File "/usr/local/lib/python2.7/dist-packages/sane.py", line 400, in open
>     return SaneDev(devname)
>   File "/usr/local/lib/python2.7/dist-packages/sane.py", line 160, in __init__
>     d['dev'] = _sane._open(devname)
> TypeError: argument 1 must be string, not tuple
> 
> 
manisandro commented 7 years ago

Can you show the actual source code you are using? Is it https://github.com/python-pillow/Sane/blob/master/example.py?

Erim32 commented 7 years ago

Yes

manisandro commented 7 years ago

Odd, devices is

[('pixma:MG3500_192.168.1.70', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral'), ('pixma:04A9176E_40BBB1', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral')]

and hence devices[0][0] is 'pixma:MG3500_192.168.1.70', so definitely a string and not a tuple. If you print devices[0][0] before sane.open, what do you get?

Erim32 commented 7 years ago

Devices[0][0]:

pixma:MG3500_192.168.1.70

I dont know if that change something but i use usb for connexion.

manisandro commented 7 years ago

Nope whether usb or something else does not matter. But also in your case it looks like a string. To be sure, what's the output of type(devices[0][0])?

Erim32 commented 7 years ago

<type 'str'>

manisandro commented 7 years ago

And you are really sure that the sane.open call line immediately after afterwards, called with devices[0][0], fails claiming that it was passed a tuple and not a string?

Erim32 commented 7 years ago
#
# Initialize sane
#
ver = sane.init()
print('SANE version:', ver)

#
# Get devices
#
devices = sane.get_devices()
print('Available devices:', devices)
print('Devices[0][0]:', devices[0][0])
print(type(devices[0][0]))
#
# Open first device
#
dev = sane.open(devices[0][0])

Output;

Available devices: [('pixma:MG3500_192.168.1.70', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral'), ('pixma:04A9176E_40BBB1', 'CANON', 'Canon PIXMA MG3500 Series', 'multi-function peripheral')]
Devices[0][0]: pixma:MG3500_192.168.1.70
<type 'str'>
Traceback (most recent call last):
  File "./../test-scan.py", line 30, in <module>
    dev = sane.open(devices[0][0])
  File "/usr/local/lib/python2.7/dist-packages/sane.py", line 400, in open
    return SaneDev(devname)
File "/usr/local/lib/python2.7/dist-packages/sane.py", line 160, in __init__
    d['dev'] = _sane._open(devname)
_sane.error: Invalid argument
manisandro commented 7 years ago

Perhaps some badly coded driver which is corrupting your memory? Try

valgrind python2 <yourscript.py>
Erim32 commented 7 years ago

After investigations, the devname "pixma:MG3500_192.168.1.70" looks create _sane.error: Invalid argument, the question is why?

Erim32 commented 7 years ago

ERROR SUMMARY: 2177 errors from 126 contexts (suppressed: 0 from 0) Logical, because python2 "crash" before free memory allocate for the program.

manisandro commented 7 years ago

Yeah but are there any memory access errors such as

==15195== Conditional jump or move depends on uninitialised value(s)
==15195==    at 0x5C5C24F: tolower (in /usr/lib64/libc-2.26.90.so)
==15195==    by 0x40B643B: ??? (in /usr/lib64/sane/libsane-brother4.so.1.0.7)
==15195==    by 0x40B62F3: ReadModelInfoSize (in /usr/lib64/sane/libsane-brother4.so.1.0.7)
==15195==    by 0x40B4C9E: init_model_info (in /usr/lib64/sane/libsane-brother4.so.1.0.7)
==15195==    by 0x40C730A: sane_brother4_init (in /usr/lib64/sane/libsane-brother4.so.1.0.7)
==15195==    by 0x6C0C46F: ??? (in /usr/lib64/libsane.so.1.0.27)
==15195==    by 0x6C0CE8B: sane_dll_get_devices (in /usr/lib64/libsane.so.1.0.27)
==15195==    by 0x69ECAC3: ??? (in /usr/lib64/python2.7/site-packages/_sane.so)
==15195==    by 0x4FBC69D: PyEval_EvalFrameEx (in /usr/lib64/libpython2.7.so.1.0)
==15195==    by 0x4FBD2F7: PyEval_EvalCodeEx (in /usr/lib64/libpython2.7.so.1.0)
==15195==    by 0x4FBA332: PyEval_EvalFrameEx (in /usr/lib64/libpython2.7.so.1.0)
==15195==    by 0x4FBD2F7: PyEval_EvalCodeEx (in /usr/lib64/libpython2.7.so.1.0)
Erim32 commented 7 years ago

https://pastebin.com/ib7cJTDG

manisandro commented 7 years ago

öhm something is seriously wrong with your python, it keeps accessing deallocated memory.

Erim32 commented 7 years ago

Its a generic issue for canon printers.