dstp_data_fit.py

Go to the documentation of this file.
00001 """A shakedown application for the use of the dstp server.  Maybe out of date"""
00002 _rcsid="$Id: dstp_data_fit.py,v 1.4 2003/05/30 13:31:55 mendenhall Release-20030716 $"
00003 
00004 import sys
00005 import os
00006 
00007 sys.path.append(os.path.join(os.path.dirname(__file__),"data acquisition")) #look in 'data acquisition' folder for needed routines, too
00008 
00009 import time
00010 import threading
00011 import array
00012 import traceback
00013 import Numeric
00014 import math
00015 
00016 import nati_dstp_basics
00017 import tagged_data
00018 import dstp_async
00019 
00020 
00021 nati_dstp_basics.UseNumericArray(1) #use Numeric.array instead of array.array as standard format
00022 
00023 print "go!"
00024 
00025 s=dstp_async.DSTPServer()
00026 
00027 data=tagged_data.tagged_data_system() #create a data cache with neatly nameable elements 
00028 
00029 #define data types in the cache, and what device is responsible for them, and what format they have:
00030 #data.define_field(<visible_name>, <device>, <internal name on device>, <sample object for this field>, <writable>
00031 #note that for DSTP devices, the <internal name on device> much match the DSTP URL given in labVIEW (not case sensitive)
00032 data.define_field("XY", s, ("xyvals", [array.array('d',[]), array.array('d',[])]), writable=0)
00033 data.define_field("fitparms", s, ("parms", [0,array.array('d'),0.0,array.array('d')]), writable=1)
00034 data.define_field("quit_server", s, ("quit_server", 0), writable=0)
00035 
00036 #create a routine to listen for shutdown commands
00037 def quit_server(string):
00038     if data.quit_server:
00039         s.close()
00040 #tell the server to pass shutdown commands to this routine
00041 s.listen("quit_server", quit_server)
00042 
00043 try:
00044     loopcount=0
00045 
00046     def run_fit(string):
00047         global loopcount
00048         
00049         try:
00050             #note that arrays get passed flattened, and with the original dimensioning info in a tuple with the array.  I will fix this later.
00051             (xl,x),(yl,y)=data.XY
00052             
00053             #print x,y 
00054             loopcount += 1 #make sure each time we send data, this is different, so LabVIEW notices the change
00055             
00056             y*=7.0 #bogus data processing (put real fitting here)
00057             
00058             data.fitparms=[loopcount,y,math.sqrt(Numeric.sum((y-1)*(y-1))), y-1] #send computed results back to LabVIEW
00059 
00060         except: #clean up on errors
00061             traceback.print_exc() #dump what went wrong, then close the server so we can edit the program
00062             s.close()       
00063             
00064     #tell the server that any time new data appears in 'xyvals' to call 'run_fit'
00065     s.listen("xyvals", run_fit)
00066     
00067     #start server 
00068     s.serve()   
00069         
00070 finally: #clean up on exit or errors
00071     s.close()
00072     time.sleep(1)

Generated on Wed Nov 21 10:18:31 2007 for analysis by  doxygen 1.5.4