From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-17 05:14:39
Attachments:
Brendan_Simon.vcf
|
I have a device with a usb connection that presents itself as a serial device to operating system (OS X). It appears as /dev/cu.usbmodem0001 and /dev/tty.usbmodem0001 on the filesystem when the device is plugged in. I can successfully detect the device USB Vendor ID and Product ID using pyusb :) Now I have to use pyserial to talk to the device -- which I have successfully done by opening the serial port with a hard coded device filename (/dev/cu.usbmodem0001). There must be some way for me to use the pyusb information to be able to determine the appropriate device filename to open with pyusb. Does anyone know how to do this or have any suggestions ??? Thanks, Brendan. |
From: Santiago P. Sanchez-M. <sp...@gm...> - 2009-06-17 06:56:30
|
Well, you can use the device VID and PID to select which device to open. I use something like: def do_d(self, args): if self.devh is not None: self.do_close('') #ls if self.devh is None: self.devs=getdevs() shortlist(self.devs) dn = -1; index = 0; for d in self.devs: if (d[1].idVendor == 0xFFFF and d[1].idProduct == 0x0000): dn = index; index = index + 1; if(dn == -1): return 1 self.curdev=self.devs[dn] self.devh=self.curdev[1].open() self.devn=dn self.devh.setConfiguration(self.curdev[2]) self.devh.claimInterface(self.curdev[2].interfaces[0][0]) self.devh.setAltInterface(0) On Wed, Jun 17, 2009 at 7:14 AM, Brendan Simon (eTRIX) < Bre...@et...> wrote: > I have a device with a usb connection that presents itself as a serial > device to operating system (OS X). > It appears as /dev/cu.usbmodem0001 and /dev/tty.usbmodem0001 on the > filesystem when the device is plugged in. > > I can successfully detect the device USB Vendor ID and Product ID using > pyusb :) > > Now I have to use pyserial to talk to the device -- which I have > successfully done by opening the serial port with a hard coded device > filename (/dev/cu.usbmodem0001). > > There must be some way for me to use the pyusb information to be able to > determine the appropriate device filename to open with pyusb. > > Does anyone know how to do this or have any suggestions ??? > > Thanks, Brendan. > > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Pyusb-users mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users > > |
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-17 07:27:30
Attachments:
Brendan_Simon.vcf
|
Thanks Santiago :) Unfortunately I'm new to usb so it's not making too much sense at the moment. What is the class object that self is referring to here ? Is getdevs() your own function or a standard os function ? Presumably getdevs calls something like usb.busses() somewhere ? I don't see how this gives me the name of the serial device (eg. /dev/cu.usbmodem0001) that I can then reference with pyserial Serial() function. example: port = '/dev/cu.usbmodem0001' # need to auto detect/determine this ser = serial.Serial( port ) Thanks Brendan. Santiago Palomino Sanchez-Manjavacas wrote: > Well, you can use the device VID and PID to select which device to open. > I use something like: > > def do_d(self, args): > if self.devh is not None: > self.do_close('') > #ls > if self.devh is None: > self.devs=getdevs() > shortlist(self.devs) > dn = -1; > index = 0; > for d in self.devs: > if (d[1].idVendor == 0xFFFF and d[1].idProduct == 0x0000): > dn = index; > index = index + 1; > if(dn == -1): > return 1 > self.curdev=self.devs[dn] > self.devh=self.curdev[1].open() > self.devn=dn > self.devh.setConfiguration(self.curdev[2]) > > self.devh.claimInterface(self.curdev[2].interfaces[0][0]) > self.devh.setAltInterface(0) > > > > On Wed, Jun 17, 2009 at 7:14 AM, Brendan Simon (eTRIX) > <Bre...@et... <mailto:Bre...@et...>> wrote: > > I have a device with a usb connection that presents itself as a serial > device to operating system (OS X). > It appears as /dev/cu.usbmodem0001 and /dev/tty.usbmodem0001 on the > filesystem when the device is plugged in. > > I can successfully detect the device USB Vendor ID and Product ID using > pyusb :) > > Now I have to use pyserial to talk to the device -- which I have > successfully done by opening the serial port with a hard coded device > filename (/dev/cu.usbmodem0001). > > There must be some way for me to use the pyusb information to be able to > determine the appropriate device filename to open with pyusb. > > Does anyone know how to do this or have any suggestions ??? > > Thanks, Brendan. |
From: Santiago P. Sanchez-M. <sp...@gm...> - 2009-06-17 08:08:20
|
Hi, This is based on a script that I downloaded with Porus. I think it was called porustest.py: http://prdownload.berlios.de/porus/porus-0.1.1.tgz I recommend you to test it. It has a command interface that is useful for debugging. Self is the command interpreter object, def getdevs(): """Returns a flat array of configs on all busses -- ie an array of tuples of (bus,dev,conf). Array is guaranteed to be sorted by bus and dev. Used for giving numbers to configs""" rtn=[] for b in usb.busses(): for d in b.devices: for c in d.configurations: rtn.append((b,d,c)) return rtn I don't know much about the serial part, but I would look into how serial.Serial(port) is implemented. May be you need to change it a bit if you want to open a device by PID and VID. I guess that it opens the device and claims an interface, but I haven't used that library. I hope this helps. Ah, I forgot On Wed, Jun 17, 2009 at 9:27 AM, Brendan Simon (eTRIX) < Bre...@et...> wrote: > Thanks Santiago :) > Unfortunately I'm new to usb so it's not making too much sense at the > moment. > > What is the class object that self is referring to here ? > > Is getdevs() your own function or a standard os function ? > Presumably getdevs calls something like usb.busses() somewhere ? > > I don't see how this gives me the name of the serial device (eg. > /dev/cu.usbmodem0001) that I can then reference with pyserial Serial() > function. > example: > port = '/dev/cu.usbmodem0001' # need to auto detect/determine this > ser = serial.Serial( port ) > > Thanks Brendan. > > > Santiago Palomino Sanchez-Manjavacas wrote: > > Well, you can use the device VID and PID to select which device to open. > > I use something like: > > > > def do_d(self, args): > > if self.devh is not None: > > self.do_close('') > > #ls > > if self.devh is None: > > self.devs=getdevs() > > shortlist(self.devs) > > dn = -1; > > index = 0; > > for d in self.devs: > > if (d[1].idVendor == 0xFFFF and d[1].idProduct == > 0x0000): > > dn = index; > > index = index + 1; > > if(dn == -1): > > return 1 > > self.curdev=self.devs[dn] > > self.devh=self.curdev[1].open() > > self.devn=dn > > self.devh.setConfiguration(self.curdev[2]) > > > > self.devh.claimInterface(self.curdev[2].interfaces[0][0]) > > self.devh.setAltInterface(0) > > > > > > > > On Wed, Jun 17, 2009 at 7:14 AM, Brendan Simon (eTRIX) > > <Bre...@et... <mailto:Bre...@et...>> wrote: > > > > I have a device with a usb connection that presents itself as a > serial > > device to operating system (OS X). > > It appears as /dev/cu.usbmodem0001 and /dev/tty.usbmodem0001 on the > > filesystem when the device is plugged in. > > > > I can successfully detect the device USB Vendor ID and Product ID > using > > pyusb :) > > > > Now I have to use pyserial to talk to the device -- which I have > > successfully done by opening the serial port with a hard coded device > > filename (/dev/cu.usbmodem0001). > > > > There must be some way for me to use the pyusb information to be able > to > > determine the appropriate device filename to open with pyusb. > > > > Does anyone know how to do this or have any suggestions ??? > > > > Thanks, Brendan. > > |