Hi,
thanks for the awesome work; scanbuttond is just a mess.
I got things to run smoothly on Raspbian on a Raspberry Pi 3 with a Canon DR-2010C document scanner.
I noticed one thing. If the scanner is disconnected from USB, insaned continues to run (so far no problem). But when the scanner is reconnected insaned doesn't continue to poll for button presses. I tried to run a script via udev to killall insaned and promptly restarting it when the device is connected as workaround. But that - even though it kinda worked very slowly - was not the best solution. I even dug around in the source but my C++/USB-fu was too small (something about wrong parameters...).
So I made a little Python daemon called 'insanecheck.py'
import usb.core
import subprocess
import psutil
import daemon
import time
import sys
scriptdir="/mnt/dms/"
vId=0x1083
pId=0x161b
def getinsanedpid():
prcs = psutil.process_iter(attrs=['pid', 'name'])
pid = 0
count = 0
for p in prcs:
if 'insaned' in p.info['name']:
pid = p.info['pid']
count += 1
return pid
# 1083:161b
def main():
last = 0
try:
while(1):
dev = usb.core.find(idVendor=vId, idProduct=pId)
#print "insaned pid " + str(getinsanedpid())
if dev is None:
if last == 1:
subprocess.call([scriptdir+'/disconnect.sh'])
last = 0
#print "Scanner removed"
else:
if last == 0:
if getinsanedpid() > 0:
subprocess.call([scriptdir+'/disconnect.sh'])
subprocess.call([scriptdir+'/connect.sh'])
last = 1
#print "Scanner reconnected..."
time.sleep(0.5)
except:
print "Unexpected error:", sys.exc_info()[0]
raise
if __name__ == "__main__":
with daemon.DaemonContext():
main()
Works a treat. disconnect.sh just does "killall insaned" and connect.sh starts insaned with all parameters. 500ms scan interval might be a little low but whatever. It does the trick for me and only took an hour or so to code.
So long, keep it up :)
Hi, thanks for the awesome work; scanbuttond is just a mess. I got things to run smoothly on Raspbian on a Raspberry Pi 3 with a Canon DR-2010C document scanner.
I noticed one thing. If the scanner is disconnected from USB, insaned continues to run (so far no problem). But when the scanner is reconnected insaned doesn't continue to poll for button presses. I tried to run a script via udev to killall insaned and promptly restarting it when the device is connected as workaround. But that - even though it kinda worked very slowly - was not the best solution. I even dug around in the source but my C++/USB-fu was too small (something about wrong parameters...). So I made a little Python daemon called 'insanecheck.py'
Works a treat. disconnect.sh just does "killall insaned" and connect.sh starts insaned with all parameters. 500ms scan interval might be a little low but whatever. It does the trick for me and only took an hour or so to code. So long, keep it up :)