[PYTHONMAC-SIG] Re: copying from serial port

Steven D. Majewski sdm7g@elvis.med.virginia.edu
Thu, 2 Oct 1997 15:51:17 -0400


In article <3431EFD3.21B5CD7B@panetheon.yale.edu>,
Tim Lovelock  <tjl6@panetheon.yale.edu> wrote:
>Hi,
>
>I was looking for an application (hopefully) or a hint on how to go
>about scripting or programing something that would monitor the serial
>port for and automatically copy any text strings that came in through
>the serial port so that they could be easily pasted into another
>application.
>
>Any thoughts would be great.


There is a communications toolbox module for Python. <http://www.python.org/>
I've never used the communications toolbox, so I don't know 
exactly how to do this, but it should be able to be done. 

There is also AppleEvents support in MacPython, so you may be able to 
do the pasting into a scriptable application. 


---

I've also got a very crude first hack at a device mgr. module for Python. 

It supports the high-level routines:
 OpenDriver,CloseDriver,Status,Control,KillIO*,FSRead,FSWrite

(* I have been able to crash my Mac into the macsbug by doing a KillIO 
  under certain circumstances, but I'm thinking that may be because
  KillIO is an Immediate driver call and the driver may not be reentrant. )

And experimentally, a StatusImmed & ControlImmed call. 
PBRead and PBWrite are in there, but I haven't wrapped up 
a parameter block struct interface yet. ( Should have async 
reads and write when that's done. ) 

I'm doing this for an interface to a custom device, but I'm starting
with generic device support so I can test the code without that board
in my Mac. 

Without the async support, the best you can do is to poll for chars
available with csCode=2. 


The following seems to work. 


import struct

def toint( str ):
	return struct.unpack( 'i', str[:4] )[0]

def charsAvail( refno ):
	return toint( Status( refno, 2 ))


ain = OpenDriver( '.Ain' )

while 1:
	n = charsAvail( ain )
	if n: 
		data = FSRead( ain, n )
		# do something with data 




I'll post the sources and a plugin when it's finished, but if you're
desperate for it immediately ( or like living dangerously ), let me 
know. 


BTW: SWIG <http://www.cs.utah.edu/~beazley/SWIG/swig.html> is a nice
tool to help automate the glue-code generation needed to make arbitrary
C code into Python/Perl/Tcl/et.al. callable extensions. 



---|  Steven D. Majewski   (804-982-0831)  <sdm7g@Virginia.EDU>  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of Virginia             Health Sciences Center  |---
---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---
All power corrupts and obsolete power corrupts obsoletely." - Ted Nelson

_______________
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________