On Wed, Jan 25, 2012 at 8:01 PM, Wander Lairson Costa <
wander.lair...@gmail.com> wrote:
> 2012/1/25 bibek chitrakar <bibek.chitra...@gmail.com>:
> > I have modified my code a bit adding class.
> > Still the same problem.
> > Why cant I write into the device since the device has been detected.
> > Here's my code
> >
> > ########################################################
> >
> > #!usr/bin/python
> >
> > import usb
> > import time
> >
> > class HardwareMonitor_printer(object):
> > def __init__(self, vendor_id, product_id):
> > self.device_found = False # True if device found
> > busses = usb.busses() # enumerate busses
> > self.handle = None
> > # print 'busses: ',busses
> > for bus in busses:
> > # print 'bus: ',bus
> > devices = bus.devices
> > # print 'devices: ',devices
> > for dev in devices:
> > if dev.idVendor == vendor_id and dev.idProduct ==
> > product_id: # device matches
> > self.dev = dev
> > self.conf = self.dev.configurations[0]
> > self.intf = self.conf.interfaces[0][0]
> > self.endpoints = []
> > for endpoint in self.intf.endpoints:
> > self.endpoints.append(endpoint)
> >
> > self.device_found = True
> > return
> >
> > def open(self):
> > if self.handle:
> > self.handle = None
> > try:
> > self.handle = self.dev.open()
> > self.handle.detachKernelDriver(0)
> > self.handle.detachKernelDriver(1)
> > self.handle.setConfiguration(self.conf)
> > self.handle.claimInterface(self.intf)
> > self.handle.setAltInterface(self.intf)
> > return True
> > except:
> > return False
> >
> > def write(self, ep , buff, timeout=100):
> > try:
> > return self.handle.interruptWrite(ep, buff, timeout) #return
> > bytes written
> > except usb.USBError as e:
> > print e
> > return 0
> >
> > def read(self, ep, size, timeout=100):
> > try:
> > return self.handle.interruptRead(ep, size, timeout) # return
> > data read
> > except:
> > return []
> >
> > def getDeviceName(self):
> > try:
> > for i in range (1, 4):
> > print self.handle.getString(i,25)
> > except IOError as e:
> > print e
> >
> > def endpoint(self):
> > return self.endpoints
> >
> > if __name__ == '__main__':
> > printer = HardwareMonitor_printer(0xdd4,0x1a8)
> > if printer.device_found:
> > printer.open()
> > printer.getDeviceName()
> > #: is there something wrong with the parameters ?
> > bytes_written = printer.write(1, [0x81], 1000)
> > time.sleep(1)
> > #: is this parameter right ?
> > bytes_read = printer.read(0x81, 64)
> > print 'rx data: ', bytes_read
> > else:
> > print 'device not found!!!'
> >
> > ===============================
> > I got this output.
> >
> > $ sudo python hardware_monitor_printer.py
> > CUSTOM Engineering S.p.A.
> > TG2480-H
> > Self Power Mode
> > error submitting URB: No such file or directory
> > rx data: []
> >
> > ===============================
> > Please someone help me. I really need to
> > solve this. At least I need to send some hex
> > codes into the device.
> >
> > Thanks in regards.
> >
>
> Are you sure the endpoint type is of interrupt type? What kind of
> device is that?
>
> --
> Best Regards,
> Wander Lairson Costa
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> pyusb-users mailing list
> pyusb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>
>
> I am not sure if the endpoint is of interrupt type.
> running usbenum.py from '
> http://wiki.erazor-zone.de/wiki:projects:python:pyusb:setup:examples:usbenum
> '
> gave following output (I removed other listings)
>
> Device: 004
> Device class: 0
> Device sub class: 0
> Device protocol: 0
> Max packet size: 64
> idVendor: 3540
> idProduct: 424
> Device Version: 01.19
> Configuration: 1
> Total length: 32
> selfPowered: 1
> remoteWakeup: 0
> maxPower: 4
> Interface: 0
> Alternate Setting: 0
> Interface class: 7
> Interface sub class: 1
> Interface protocol: 2
> Endpoint: 0x81L
> Type: 2
> Max packet size: 64
> Interval: 0
> Endpoint: 0x2L
> Type: 2
> Max packet size: 64
> Interval: 0
>
> I can track the device. Device is a thermal printer. And I need to send
some hex data to so that
the printer will response accordingly and the current status of printer be
determined.
Is there anything I am missing ?
Robert von Burg ei...@eitchnet.ch told that I need to detach the module
from kernel.-
But, the code did nothing..
if device.is_kernel_driver_active(interface):
try:
device.detach_kernel_driver(interface)
detached = True
except Exception as e:
print "ERROR: Could not detach device from kernel:",
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users