Thread: [Pyobjc-dev] Wrapping GetLocationID from IOUSBLib
Brought to you by:
ronaldoussoren
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-22 21:26:42
Attachments:
Brendan_Simon.vcf
|
I'm new to PyObjC (and Object C in general). I have a python application that accesses a USB device, and I want to display the LocationID (like System Profiler and ioreg does). The LocationID seems to be OS X specific and not part of the standard USB protocol and thus not part of PyUSB. So assuming OS X does not provide a python interface to IOUSBLib (please let me know if it does), then I have to find a way to access it from Python. It would seem that PyObjC would be an appropriate method -- yes/no ??? The header file IOUSBLib.h contains the function GetLocationID. IOReturn (*GetLocationID)(void *self, UInt32 *locationID); Am I able to wrap this one function (or is it a method ?) easily with PyObjC ?? If it is easy, could someone provide some skeleton code for me to work/play with. If not so easy, could someone outline things that need to done and point me to some appropriate doucmentation. Many thanks, Brendan (pyobjc newbie) :) |
From: Orestis M. <or...@or...> - 2009-06-22 22:18:22
|
Hi Brendan, I would advise that you first confirm (by reading the apple docs or by asking at the appropriate apple list) that GetLocationID does indeed do what you want it to. The I/O Kit documentation should point you to the right direction. You are unlikely to receive answers about such esoteric stuff on this list, unless you strike gold and one of the members of the audience has experience with the inner workings of Mac OS X usb libs. If you do find out that GetLocationID does what you want, you'd need to load the framework it's part of in PyObjC, as it's not already there. If that turns out to be too much of a bother (I think it might be), you can always try using ctypes, but I think you can't mix ctypes and PyObjC values together (in case you want to embed your code in a PyObjC app). I *think* the above are accurate, but I'd love to be corrected if anyone has more accurate information. Orestis -- or...@or... http://orestis.gr/ On 23 Jun 2009, at 00:25, Brendan Simon (eTRIX) wrote: > I'm new to PyObjC (and Object C in general). > > I have a python application that accesses a USB device, and I want to > display the LocationID (like System Profiler and ioreg does). > > The LocationID seems to be OS X specific and not part of the standard > USB protocol and thus not part of PyUSB. > > So assuming OS X does not provide a python interface to IOUSBLib > (please > let me know if it does), then I have to find a way to access it from > Python. It would seem that PyObjC would be an appropriate method -- > yes/no ??? > > The header file IOUSBLib.h contains the function GetLocationID. > > IOReturn (*GetLocationID)(void *self, UInt32 *locationID); > > Am I able to wrap this one function (or is it a method ?) easily with > PyObjC ?? > > If it is easy, could someone provide some skeleton code for me to > work/play with. > If not so easy, could someone outline things that need to done and > point > me to some appropriate doucmentation. > > Many thanks, Brendan (pyobjc newbie) :) > > < > Brendan_Simon > .vcf > > > ------------------------------------------------------------------------------ > Are you an open source citizen? Join us for the Open Source Bridge > conference! > Portland, OR, June 17-19. Two days of sessions, one day of > unconference: $250. > Need another reason to go? 24-hour hacker lounge. Register today! > http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-23 01:06:12
Attachments:
Brendan_Simon.vcf
|
Hi Orestis, Thanks for your response. I believe that GetLocationID() -- from the IOUSBLib -- is what I need. It simply takes a usb device handle and returns a unique integer which represents the location of the usb device on the usb busses. I beleive that GetLocationID() interrogates the IO Registry to obtain and/or calculate the information. I have made the assumption that anybody using PyObjC is probably familiar with Objective C and therefore familiar with OS X libraries (as that's the most prevalent ObjC platform) -- possibly an optimistic assumption ??? I had a quick look at ctypes and not sure if it can be used to access ObjC variables, functions, etc. I'm not sure if there is a way to build a C (or C++) wrapper around the ObjC code and then use ctypes. I presume it's possible but it's getting complicated :( What's involved in loading 'the framework' ?? I don't mind loading the framework if it's not overly complicated and there is not a big penalty (eg. too slow). I think the USB stuff is part of the IOKit framework. I've found this: http://pyobjc.sourceforge.net/documentation/pyobjc-core/wrapping.html The section 'the basics' seems to imply that I just need to have a file called 'Myframework.py' and that's it (if no wrappers are required) HUH ??? How does that work ??? Surely there must be some python or PyObjC code to write ??? Again, thanks for any assistance, Regards, Brendan. Orestis Markou wrote: > Hi Brendan, > > I would advise that you first confirm (by reading the apple docs or by > asking at the appropriate apple list) that GetLocationID does indeed do > what you want it to. The I/O Kit documentation should point you to the > right direction. > > You are unlikely to receive answers about such esoteric stuff on this > list, unless you strike gold and one of the members of the audience has > experience with the inner workings of Mac OS X usb libs. > > If you do find out that GetLocationID does what you want, you'd need to > load the framework it's part of in PyObjC, as it's not already there. If > that turns out to be too much of a bother (I think it might be), you can > always try using ctypes, but I think you can't mix ctypes and PyObjC > values together (in case you want to embed your code in a PyObjC app). > > I *think* the above are accurate, but I'd love to be corrected if anyone > has more accurate information. > > Orestis > -- > On 23 Jun 2009, at 00:25, Brendan Simon (eTRIX) wrote: > >> I'm new to PyObjC (and Object C in general). >> >> I have a python application that accesses a USB device, and I want to >> display the LocationID (like System Profiler and ioreg does). >> >> The LocationID seems to be OS X specific and not part of the standard >> USB protocol and thus not part of PyUSB. >> >> So assuming OS X does not provide a python interface to IOUSBLib (please >> let me know if it does), then I have to find a way to access it from >> Python. It would seem that PyObjC would be an appropriate method -- >> yes/no ??? >> >> The header file IOUSBLib.h contains the function GetLocationID. >> >> IOReturn (*GetLocationID)(void *self, UInt32 *locationID); >> >> Am I able to wrap this one function (or is it a method ?) easily with >> PyObjC ?? >> >> If it is easy, could someone provide some skeleton code for me to >> work/play with. >> If not so easy, could someone outline things that need to done and point >> me to some appropriate doucmentation. >> >> Many thanks, Brendan (pyobjc newbie) :) |
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-23 01:23:08
Attachments:
Brendan_Simon.vcf
|
Hi Orestis, Thanks for your response. I believe that GetLocationID() -- from the IOUSBLib -- is what I need. It simply takes a usb device handle and returns a unique integer which represents the location of the usb device on the usb busses. I beleive that GetLocationID() interrogates the IO Registry to obtain and/or calculate the information. I have made the assumption that anybody using PyObjC is probably familiar with Objective C and therefore familiar with OS X libraries (as that's the most prevalent ObjC platform) -- possibly an optimistic assumption ??? I had a quick look at ctypes and not sure if it can be used to access ObjC variables, functions, etc. I'm not sure if there is a way to build a C (or C++) wrapper around the ObjC code and then use ctypes. I presume it's possible but it's getting complicated :( What's involved in loading 'the framework' ?? I don't mind loading the framework if it's not overly complicated and there is not a big penalty (eg. too slow). I think the USB stuff is part of the IOKit framework. I've found this: http://pyobjc.sourceforge.net/documentation/pyobjc-core/wrapping.html The section 'the basics' seems to imply that I just need to have a file called 'Myframework.py' and that's it (if no wrappers are required) HUH ??? How does that work ??? Surely there must be some python or PyObjC code to write ??? Again, thanks for any assistance, Regards, Brendan. Orestis Markou wrote: > Hi Brendan, > > I would advise that you first confirm (by reading the apple docs or by > asking at the appropriate apple list) that GetLocationID does indeed do > what you want it to. The I/O Kit documentation should point you to the > right direction. > > You are unlikely to receive answers about such esoteric stuff on this > list, unless you strike gold and one of the members of the audience has > experience with the inner workings of Mac OS X usb libs. > > If you do find out that GetLocationID does what you want, you'd need to > load the framework it's part of in PyObjC, as it's not already there. If > that turns out to be too much of a bother (I think it might be), you can > always try using ctypes, but I think you can't mix ctypes and PyObjC > values together (in case you want to embed your code in a PyObjC app). > > I *think* the above are accurate, but I'd love to be corrected if anyone > has more accurate information. > > Orestis > -- > On 23 Jun 2009, at 00:25, Brendan Simon (eTRIX) wrote: > >> I'm new to PyObjC (and Object C in general). >> >> I have a python application that accesses a USB device, and I want to >> display the LocationID (like System Profiler and ioreg does). >> >> The LocationID seems to be OS X specific and not part of the standard >> USB protocol and thus not part of PyUSB. >> >> So assuming OS X does not provide a python interface to IOUSBLib (please >> let me know if it does), then I have to find a way to access it from >> Python. It would seem that PyObjC would be an appropriate method -- >> yes/no ??? >> >> The header file IOUSBLib.h contains the function GetLocationID. >> >> IOReturn (*GetLocationID)(void *self, UInt32 *locationID); >> >> Am I able to wrap this one function (or is it a method ?) easily with >> PyObjC ?? >> >> If it is easy, could someone provide some skeleton code for me to >> work/play with. >> If not so easy, could someone outline things that need to done and point >> me to some appropriate doucmentation. >> >> Many thanks, Brendan (pyobjc newbie) :) |
From: Ronald O. <ron...@ma...> - 2009-06-23 06:40:23
|
On 23 Jun, 2009, at 3:23, Brendan Simon (eTRIX) wrote: > > > I have made the assumption that anybody using PyObjC is probably > familiar with Objective C and therefore familiar with OS X libraries > (as > that's the most prevalent ObjC platform) -- possibly an optimistic > assumption ??? I'd also expect that most members of this list are familiar with OSX libraries, but not with all libraries. The IO Registry is a rather low-level library and I'd guess that most developers don't have to use it. The set of libraries on OSX, or any modern platform, is rather huge and I'd expect that most developers have a superficial knowledge of what's available and more detailed knowledge of what they actually expect to use (I know that IOKit exists if I ever need to do low-level hardware access, but as I haven't needed that functionality that's about it). > > I had a quick look at ctypes and not sure if it can be used to access > ObjC variables, functions, etc. I'm not sure if there is a way to > build > a C (or C++) wrapper around the ObjC code and then use ctypes. I > presume it's possible but it's getting complicated :( Neither wrapping using ctypes nor wrapping using PyObjC will be easy. You access functionality of "objects" from IOKit using function pointers in the "object" struct. That should be easy enough to write in ctypes, but PyObjC has no real support for that. On the other hand, PyObjC has support for CFString and other CoreFoundation types while ctypes hasn't. BTW. IOKit is not an Objective-C based framework, but is a plain C framework that makes use of CoreFoundation. Ronald |
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-23 07:07:25
Attachments:
Brendan_Simon.vcf
|
Ronald Oussoren wrote: > > On 23 Jun, 2009, at 3:23, Brendan Simon (eTRIX) wrote: >> I had a quick look at ctypes and not sure if it can be used to access >> ObjC variables, functions, etc. I'm not sure if there is a way to build >> a C (or C++) wrapper around the ObjC code and then use ctypes. I >> presume it's possible but it's getting complicated :( > > Neither wrapping using ctypes nor wrapping using PyObjC will be easy. > You access functionality of "objects" from IOKit using function pointers > in the "object" struct. That should be easy enough to write in ctypes, > but PyObjC has no real support for that. On the other hand, PyObjC has > support for CFString and other CoreFoundation types while ctypes hasn't. > > BTW. IOKit is not an Objective-C based framework, but is a plain C > framework that makes use of CoreFoundation. Thanks Ronald. I've had a look at libusb-1.0.2 it is written in C and makes IOKit calls :) PyUSB (0.x) uses ctypes to interface to libusb-0.1.12. PyUSB has just started a new 1.0 branch to use libusb-1.x.y, and as such there is no release yet. So it seems that the best solution for me is to take the libusb code, and either extend/modify it to provide the info I need. I can use PyUSB or my own ctype interface to get a python interface. So I think I will skip the PyObjC exercise for now, although I really like the project. If IOKit support was added to PyObjC that would be really really useful :) Thanks for everyone's help, Brendan. |
From: Brendan S. (eTRIX) <Bre...@eT...> - 2009-06-23 08:19:21
Attachments:
Brendan_Simon.vcf
|
Brendan Simon (eTRIX) wrote: > If IOKit support was added to PyObjC that would be really really useful :) Errrr, as previously stated, IOKit is written in C so PyObjC is not relevant. Sorry -- my bad. |
From: Ronald O. <ron...@ma...> - 2009-06-23 08:39:05
|
On 23 Jun, 2009, at 10:18, Brendan Simon (eTRIX) wrote: > Brendan Simon (eTRIX) wrote: >> If IOKit support was added to PyObjC that would be really really >> useful :) > Errrr, as previously stated, IOKit is written in C so PyObjC is not > relevant. Sorry -- my bad. That's not quite true: IOKit seems to expose an CoreFoundation based API, which is PyObjC territory. It's rather unlikely that I'll get around to adding IOKit support anytime soon though because I don't use IOKit myself and adding support will be a lot of work. Ronald > > > < > Brendan_Simon > .vcf > > > ------------------------------------------------------------------------------ > Are you an open source citizen? Join us for the Open Source Bridge > conference! > Portland, OR, June 17-19. Two days of sessions, one day of > unconference: $250. > Need another reason to go? 24-hour hacker lounge. Register today! > http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Orestis M. <or...@or...> - 2009-06-23 08:49:11
|
On 23 Jun 2009, at 11:36, Ronald Oussoren wrote: > > On 23 Jun, 2009, at 10:18, Brendan Simon (eTRIX) wrote: > >> Brendan Simon (eTRIX) wrote: >>> If IOKit support was added to PyObjC that would be really really >>> useful :) >> Errrr, as previously stated, IOKit is written in C so PyObjC is not >> relevant. Sorry -- my bad. > > That's not quite true: IOKit seems to expose an CoreFoundation based > API, which is PyObjC territory. It's rather unlikely that I'll get > around to adding IOKit support anytime soon though because I don't use > IOKit myself and adding support will be a lot of work. Is there a way to make ctypes and CF play together? I think that if this gets added to PyObjC then people needing to access low-level stuff from Python could do it themselves (for the bits they need). That's probably smaller in focus and more enabling than wrapping a C based framework that only a few people will use. |
From: Ronald O. <ron...@ma...> - 2009-06-23 08:53:26
|
On 23 Jun, 2009, at 10:48, Orestis Markou wrote: > On 23 Jun 2009, at 11:36, Ronald Oussoren wrote: > >> >> On 23 Jun, 2009, at 10:18, Brendan Simon (eTRIX) wrote: >> >>> Brendan Simon (eTRIX) wrote: >>>> If IOKit support was added to PyObjC that would be really really >>>> useful :) >>> Errrr, as previously stated, IOKit is written in C so PyObjC is not >>> relevant. Sorry -- my bad. >> >> That's not quite true: IOKit seems to expose an CoreFoundation based >> API, which is PyObjC territory. It's rather unlikely that I'll get >> around to adding IOKit support anytime soon though because I don't >> use >> IOKit myself and adding support will be a lot of work. > > Is there a way to make ctypes and CF play together? I think that if > this gets added to PyObjC then people needing to access low-level > stuff from Python could do it themselves (for the bits they need). > That's probably smaller in focus and more enabling than wrapping a C > based framework that only a few people will use. Accessing bit of CF from ctypes is not very hard (there is some code in Python2.6's urllib that does this). Making that interact properly with PyObjC is harder, and not something I've time to work on at the moment. Ronald |