Re: Running External Programs from Within Python
At 10:50 PM 1/31/2004 +0100, Nuff Said wrote: On Sat, 31 Jan 2004 11:23:42 -0800, Bob=Moore wrote: If anyone is interested, I used the following non-threaded code; I tried pipedream.py, but had apparent timing issues with the threads that I couldn't clear up. I usually use wxPython. An *NIX version would be interesting as well (hint). The external .exe is an interactive DOS-menu'd program in FORTRAN. == snip = import os import time from wxPython.wx import * import win32pipe def getDataFrom(pipe): done = False timeout = 4 ## seconds start_time = time.time() data = '' error = None while not done: try: ## check to see if the 'file' has any data, using stat() #print os.fstat(input.fileno())[6], if(os.fstat(pipe.fileno())[6]!=0): ## this will read up to a large amount data = os.read(pipe.fileno(), 2**16) elif(len(data)): ## if the read was done on the last loop, we can quit done = True #print 'read all' elif((time.time() - start_time) > timeout): ## something went wrong done = True print 'Error; read timed out' else: ## might be starting up the remote process... time.sleep(.01) except (IOError, OSError): print '(IOError, OSError)',(IOError, OSError) done = True return [error, data] def driveRemote(stdinput, stdoutput, resp): """ takes pipes and a string to send always gets the current DOS output first... """ timeOut, result = getDataFrom(stdoutput) if timeOut: print 'timedOut resp', result return timeOut print "remote:'%s'" % result[-60:], if (result==('' or None)): dlg = wxMessageDialog(parent, "resp not received!"+"\nGot '"+result+"'", 'Error', wxOK | wxICON_INFORMATION) try: dlg.ShowModal() finally: dlg.Destroy() pgDlg.Destroy() ## check for errors if (string.find(result, 'run-time error')>-1): print resp, '\n' dlg = wxMessageDialog(None, result, 'Error!', wxOK | wxICON_INFORMATION) try: dlg.ShowModal() finally: dlg.Destroy() return 'error: '+result if resp!=None: try: print resp, '\n' os.write(stdinput.fileno(), resp+'\n') except IOError, e: print 'error; resp, reslt:', resp, result print "IOError %s" % e return result ## actually start, text mode stdinput, stdoutput = win32pipe.popen4("FV4R.EXE", 't') ## go through a list of actions for resp in actionList: result = driveRemote(stdinput, stdoutput, resp) snap === > Can I run (call? exec? eval?) an external program from inside a Python > program? > Check out os.popen (in all it's variants); e.g. something like the following will do what you want: import os stdin, stdout, stderr = os.popen3('your program goes here') output = stdout.read() errors = stderr.read() stdin.close(); stdout.close(); stderr.close() ... do something with 'output' and 'errors' ... HTH / Nuff -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python module for LX200 telescope command set
I've begun a Python module to provide a complete interface to the Meade LX200 command set: http://rjs.org/Python/LX200.py and would like input from potential users or people interested in developing it further. The code I have online is a very alpha start - it contains all of the command set, parsed from http://www.meade.com/support/LX200CommandSet.pdf reg-exp'd into methods, but few methods are actually complete yet. My thinking is to have it useful for Python command line testing, as well as GUI programs. History: after searching for such a thing, I had found only: http://72.14.203.104/search?q=cache:hOgO7H_MUeYJ:phl3pc02.phytch.dur.ac.uk/~jrl/source/source_code.html+lx200.py&hl=en&gl=us&ct=clnk&cd=1 from University of Durham, but the code is not available... and http://cvs.sourceforge.net/viewcvs.py/projgalileo/lx200/lx200.py?rev=1.4 from the Galileo project, but which only has a subset and is aimed at their needs, mostly. Some of the Galileo code looks useful, and so I might want to make use of at least some of the methodology, even if only to get their interest as well. Current input I would most like is on module structure and Pythonic-ness: -Only one class, or two? I was considering splitting the commands into two classes: Telescope and Library, as either could be used without the other for a scope session. (If you have large libraries on your PC, you do not need the LX one - or if you don't, or have a PDA, then just doing a Library lookup alone might be useful.) If you were to "import LX200", how would you expect it to work? -Should I have module methods, as I do? (Galileo uses some static methods) -What constants might be useful to define? -When should the com port be opened/tested? (I have it on init...) -What about the class names? It is already ~1200 lines code and comments, even without most of the commands actually useful yet, and so I'd like to get a good form started before getting too far along. Is anyone here interested in using such a module, or willing to critique? Thanks, Ray arr-ayy-why-ess at blue-cove.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for LX200 telescope command set
At 06:55 PM 1/29/2006, you wrote: >Subject: Re: Python module for LX200 telescope command set >Message: 9 > >On Sun, 29 Jan 2006 15:25:43 -0800, RayS <[EMAIL PROTECTED]> declaimed >the following in comp.lang.python: > > > I've begun a Python module to provide a complete interface to the Meade > > LX200 command set: > > http://rjs.org/Python/LX200.py > > and would like input from potential users or people interested in > > developing it further. > > While you might scare some away, have you considered posting in: >alt.telescopes.meade and/or alt.telescopes.meade.lx200? Thanks Wulfraed, I hadn't followed those groups, as I'm a fairly new Meade user. I'll post there. Whatever happened to the astropy list? Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for LX200 telescope command set
Hello Neil, Thank you for the extended response! All of your suggestions are reasonable, at the least. The only misgiving I had with breaking up into multiple classes is that the scope itself maintains state variables (it runs a Motorola processor etc) - so you can pick an object from the library, then other scope driving commands can use that "current" selection. I would then be required to have a similar state saving that works with all classes. I'll think about that some more... The serial port error checking is an important part that needs extending. Thanks again, Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for the LX200 command set
Hello Dez, Thanks for the reply - I was hoping to hear from your project. It will be interesting to see what John Lucey is doing before I go too far along - I hate re-inventing the wheel. I was wondering why the directory was simply empty. I will try to email him, if I can. I suspect that he also implemented a useful sub-set of the protocol. My basic idea was a comprehensive set of commands, and as many convenience functions as we desire - it is an exercise in Pythonic-ness as well, so I'd like to see design issues agreed on early. I also am thinking of getting place and time from my PCMCIA GPS (I have a 10" non-GPS LX200 EMC). Cheers, Ray At 11:47 PM 1/29/2006, you wrote: >Hi Ray - I'm the co-ordinator of Project Galileo - great to see >someone else is developing code too, especially in Python. > >It might be we can do some dovetailing with what you're doing; my >main developer, Tm Northover, is pretty busy during term time, but >it might be possible to do some collaboration. There's also the >possibility of some help with some undergraduates at York >University, too. I'm not very familiar with Python yet, so I'm not >at the prductive stage yet in terms of code development. > >Finally, John Lucey at Durham university is currently updating his >lx200 code, which he is due to release fairly soon - I think he >might have removed the existing code whilst he updates it, as the >new code will make use of pyro in a much better manner. > >I'll try &chat with Tim in the next few days or so & see how he's >placed in terms of possible collaboration; I suspect that in >principle he would be, but as I say, his term time study often means >he's unable to help out. > >Best regards, > >Dez. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for LX200 telescope command set (Steve Horsley)
At 08:25 AM 1/30/2006, you wrote: >Terry Hancock wrote: >>On Sun, 29 Jan 2006 15:25:43 -0800 >>RayS <[EMAIL PROTECTED]> wrote: >>(about LX200 module) >>Sounds interesting, but I don't actually know what an LX200 >>is. I considered buying one of the Meade computer controlled >>telescopes (there is a very inexpensive one that has been >>marketed through Walmart. Ordinarily, I would steer clear of >>a "department store telescope", but I was intrigued that >>they were selling a name brand telescope). > >Very wise. But I think even Meade's cheapest offering would be worth >having. They don't make really crap scopes. A friend just bought an ~$450 Meade GOTO, it has a 5" mirror and does have ability to enter RA-DEC. The downside is that it will not work with a PC like the larger scopes unless you buy an accessory - only keypad control. The more expensive models are always much heavier and stiffer. You could use the 5" visually or with a webcam, but no long exposure, really. My 10" LX weighs ~90lbs. Cheers, Ray -- http://mail.python.org/mailman/listinfo/python-list
python-list@python.org
Hi Alan, At 04:25 PM 1/31/2006, you wrote: >IIUC, ASCOM is a set of Windows COM objects which provides a >standardised API for controlling telescopes. Since it uses Windows >COM, you should be able to control it easily from python using the >excellent win32 extensions. Yes, I had seen it, and it looks well developed - but - it _requires_ Windows COM. (I do use Win32 and ctypes for talking to interface cards and such, that I actually get paid for) but even the company I do it for is migrating to LINUX (slowly) by customer demand (!) and I guess don't want to do new COM projects. INDI actually looks like a great project - but - it's _only_ LINUX... http://indi.sourceforge.net/ There are a good number of professional astro Python creations supported by STSCI and Enthought http://www.stsci.edu/resources/software_hardware/ Kstars http://edu.kde.org/kstars/indi.php looks nice but uses its own scripting and only runs on LINUX I see the professional Astronomy community moving to Python, and I think it's a good idea to ride their coat-tails; university projects like Galileo and DRACO use Meade LX's as undergraduate study tools, with Python/LINUX. Thanks for the reply, Ray -- http://mail.python.org/mailman/listinfo/python-list
pyHook and Win98 key events
(Note: there's not a lot of traffic on Win32, so I'm cross-posting here...) To debug pyKeyLogger, I wrote this with pyHook (and compiled with py2exe on Win2K), which prints the ascii codes as expected on Win2K: import pyHook import time import pythoncom def OnKeyboardEvent(event): print event.Ascii def main(): hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent hm.HookKeyboard() while True: pythoncom.PumpMessages() if __name__ == '__main__': main() It silently does nothing on Win98... What is needed? py2exe on 98? I did test it on a fresh install of 98... I also just thought about trying loading ANSI.SYS at boot, but I can't test until tomorrow. Thanks, Ray -- http://mail.python.org/mailman/listinfo/python-list
Req. for module style/organization
I've begun a Python module to provide a complete interface to the Meade LX200 command set, and have searched for a style/development guide for Python Lib/site-packages type modules, but only saw guides for C-modules. I realize that I need to make some changes to follow http://www.python.org/doc/essays/styleguide.html better. Does anyone have an appropriate URL for me to follow for this task? Is one of the C-module guides appropriate? I had quickly parsed the official PDF into prototype methods and started off, got some good advice from Python-list and MAPUG, and broke it into Classes: http://rjs.org/Python/LX200.zip Not having written a generic module before, I'd like input on organization and style. As I usually learn from examples, I browsed 2.4 Lib/site-packages/ and saw a wide variety of structure: -some have empty __init__.py files, others are loaded -some have module vars and methods, others not -some have 0, 1, or many classes per .py file I have: LX200/ __init__.py LXSerial.py Telescope.py Focuser.py LXUtils.py ... etc Each file has one class defined. In the above, LXSerial, Telescope and Focuser are actual separate objects (there are others). None can be used without the serial port, but some might be used without a scope present. They all ultimately rely on a set of atomic serial commands in somewhat overlapping categories, not all of which are available on every model device (many other makers follow the LX set for its inertia). There is a second com port available for optional separate control, but rarely used by anyone. I am trying also to follow the ASCOM standard for names and high-level function behavior, as just a subset of the total of methods. (ASCOM is the biggest standard in the amateur astro industry, but is entirely MS COM, not even CORBA.) That part isn't very hard. Currently, a user creates a port object, tests ports if desired, then opens one (presumably with an LX on the other end, or it Excepts). A Telescope object is created before or after, and the port object is set as an attribute of the scope. Alternatively, I could require that the port is passed explicitly to the Telescope methods, and likewise the accessory's methods... There is the issue of inheritance and making Classes aware of parents' objects and other Classes' stuff (if needed). Where in this structure should constants be defined? __init__, module*.py, or the module's Class(s)? Should I rename LXSerial to _serial? BAUD rate is 9600, so speed here is a non-issue. The seeming lack of uniformity in the Libs/* is causing my uncertainty: All advice is appreciated, Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Req. for module style/organization
Thanks Ziga, At 04:42 PM 2/19/2006, you wrote: >RayS wrote: > > I realize that I need to make some changes to follow > > http://www.python.org/doc/essays/styleguide.html > > better. Does anyone have an appropriate URL for me to follow for this > > task? Is one of the C-module guides appropriate? > > > >There are two informal Python Enhancements Proposals: >Style Guide for C Code - http://www.python.org/peps/pep-0007.html >Style Guide for Python Code - http://www.python.org/peps/pep-0008.html Thanks, those are helpful and show that I should do some editing throughout. The import .moduleName for relative imports might come into play, as each of the modules of the package require the use of LXSerial (oops, I mean: lxserial.Serial :-) ) Given the example structure from Guido: http://www.python.org/peps/pep-0328.html#guido-s-decision package/ __init__.py subpackage1/ __init__.py moduleX.py moduleY.py moduleA.py seems like it would be appropriate here, but I still need to decide on the appropriate hierarchy within the package. Should it be lx200/ __init__.py devices/ __init__.py drive.py focuser.py lxserial.py which reflects usage hierarchy, or lx200/ __init__.py drive.py focuser.py lxserial.py which is simpler... I still don't see a consistent rationale where some packages have empty __init__.py with all the init stuff in the modules, and others don't. And then there's the large-ish modules like wxPyPlot that have almost everything in one module - I assume that is discouraged. Thanks for the info, Ray -- http://mail.python.org/mailman/listinfo/python-list
Cypress FX2 - py libusb code?
I'm looking for a Python example for the FX2 USB chip (I'm using the SerMod-100 board http://www.acquiredevices.com/sermod100.jsp). Does anyone have a simple "hello" script to re-enumerate the chip, and then do control or bulk reads with only Python and libusb? I've found C code and some Python modules that use the FX2, however I'm now using ActivePython 2.6.2.2 and don't have an appropriate compiler (I haven't found out which they use ?). I've used pure Python/libusb to work with a Ti ADS1271 kit http://focus.ti.com/docs/toolsw/folders/print/ads1271evm.html (Ti's demo developer also liked Python BTW!) and it seem that I should be able with this FX2 as well. The catch is that the chip can re-enumerate and needs to be put in command state to accept the binary string, then stopped and re-enumerated. http://lea.hamradio.si/~s57uuu/uuusb/simple_prg_rd.c looks like I can base work on it. So that's where I'll start if no one pipes up. There was a thread Wander replied in, but no code snip in it. So far I've read: http://lea.hamradio.si/~s57uuu/uuusb/uuusb_software.htm http://github.com/mulicheng/fx2lib/tree/master http://allmybrain.com/tag/fx2/ http://volodya-project.sourceforge.net/fx2_programmer.php http://www.fpgaz.com/usbp/ http://www.triplespark.net/elec/periph/USB-FX2/software/ Ray Schumacher -- http://mail.python.org/mailman/listinfo/python-list
Re: Cypress FX2 - py libusb code?
Reply to self: code attached. As Marco wrote: "To run the single C file USB bulk read program properly, you must provide a source of data to the CY7C68013 FIFO bus, like the Simple dual channel A/D system, otherwise the reading call will time out in one second, you will get a bunch of zeros, and the ninth status number will be something negative instead of 512. " The Python behavior is bulkRead error: ('usb_reap: timeout error',) when un-connected. Ray At 12:25 AM 8/5/2009 -0700, you wrote: I'm looking for a Python example for the FX2 USB chip (I'm using the SerMod-100 board http://www.acquiredevices.com/sermod100.jsp). Does anyone have a simple "hello" script to re-enumerate the chip, and then do control or bulk reads with only Python and libusb? I've found C code and some Python modules that use the FX2, however I'm now using ActivePython 2.6.2.2 and don't have an appropriate compiler (I haven't found out which they use ?). I've used pure Python/libusb to work with a Ti ADS1271 kit http://focus.ti.com/docs/toolsw/folders/print/ads1271evm.html (Ti's demo developer also liked Python BTW!) and it seem that I should be able with this FX2 as well. The catch is that the chip can re-enumerate and needs to be put in command state to accept the binary string, then stopped and re-enumerated. http://lea.hamradio.si/~s57uuu/uuusb/simple_prg_rd.c looks like I can base work on it. So that's where I'll start if no one pipes up. There was a thread Wander replied in, but no code snip in it. So far I've read: http://lea.hamradio.si/~s57uuu/uuusb/uuusb_software.htm http://github.com/mulicheng/fx2lib/tree/master http://allmybrain.com/tag/fx2/ http://volodya-project.sourceforge.net/fx2_programmer.php http://www.fpgaz.com/usbp/ http://www.triplespark.net/elec/periph/USB-FX2/software/ Ray Schumacher -- http://mail.python.org/mailman/listinfo/python-list """ To run the single C file USB bulk read program properly, you must provide a source of data to the CY7C68013 FIFO bus, like the Simple dual channel A/D system, otherwise the reading call will time out in one second, you will get a bunch of zeros, and the ninth status number will be something negative instead of 512. """ import sys import os import time import usb def PrintDevInfo(dev): """Print device information.""" print "Device:", dev.filename print " Device class:",dev.deviceClass print " Device sub class:",dev.deviceSubClass print " Device protocol:",dev.deviceProtocol print " Max packet size:",dev.maxPacketSize print " idVendor:",dev.idVendor print " idProduct:",dev.idProduct print " Device Version:",dev.deviceVersion print " Device SerialNumber:",dev.iSerialNumber for config in dev.configurations: print " Configuration:", config.value print "Total length:", config.totalLength print "selfPowered:", config.selfPowered print "remoteWakeup:", config.remoteWakeup print "maxPower:", config.maxPower for intf in config.interfaces: print "Interface:",intf[0].interfaceNumber for alt in intf: print "Alternate Setting:",alt.alternateSetting print " Interface class:",alt.interfaceClass print " Interface sub class:",alt.interfaceSubClass print " Interface protocol:",alt.interfaceProtocol for ep in alt.endpoints: print " Endpoint:",hex(ep.address) print "Type:",ep.type print "Max packet size:",ep.maxPacketSize print "Interval:",ep.interval firmware = [0x90, 0xE6, 0x0B, 0x74, 0x03, 0xF0,##REVCTL = 0x03 0x90, 0xE6, 0x04, 0x74, 0x80, 0xF0, ##FIFORESET = 0x80 0x74, 0x08, 0xF0, ##FIFORESET = 0x08 0xE4, 0xF0, ##FIFORESET = 0x00 0x90, 0xE6, 0x01, 0x74, 0xCB, 0xF0, ##IFCONFIG = 0xCB 0x90, 0xE6, 0x1B, 0x74, 0x0D, 0xF0, ##EP8FIFOCFG = 0x0D #0x90, 0xE6, 0x09, 0x74, 0x10, 0xF0,##FIFOPINPOLAR = 0x10 TRUST!!! 0x80, 0xFE] ##while (1) {} reset = 0x01 er = [] endpoint = 8 # find all of the USB busses busses = usb.busses() #print busses # Find one device rdev = None for bus in busses: for dev in bus.devices: if dev.idVendor == 0x04B4 and dev.idProduct == 0x8613: rdev = dev if rdev==None: print "Could not find a CY7C68013\ndev.idVendor == 0x04B4 and dev.idProduct == 0x8613" sys.exit() else: dev = rdev #PrintDevInfo(dev) endpoint=8 current_handle = dev.open() requestType = 0x40 request = 0xa0 #buffer = ''.zfill(4096) value=0 index=0 timeout=1000 er.append(('RESET', current_handle.controlMsg(requestType, request, reset, value, index, timeou
Re: Python docs disappointing - group effort to hire writers?
At 08:35 PM 8/5/2009 -0700, r wrote: """... Any real sense of community is undermined -- or even destroyed -- to be replaced by virtual equivalents that strive, unsuccessfully, to synthesize a sense of community.""" I've brought up the idea of the quasi-community doc that PHP uses to good effect. http://www.php.net/manual/en/language.types.array.php is a prime example where 2/3 of the "doc" is user-contributed comments and code. http://www.php.net/manual/en/about.notes.php "By allowing readers of the manual to contribute examples, caveats, and further clarifications from their browser, we are able to incorporate that feedback into the main text of the manual. And until the notes have been incorporated, they may be viewed in their submitted form online, and in some of the offline formats. " The terseness or non-clarity of a doc is quickly remedied by numerous User Contributed Notes, and over the years, they have rolled these contributed examples into the "official" doc section. While I hardly do much PHP any more, when I do need to perform maintenance etc. it is THE invaluable resource, and I believe an important part of PHP's enduring popularity. Language arguments aside http://docs.python.org/library/array.html, for instance, would benefit from such community. -- http://mail.python.org/mailman/listinfo/python-list