当前位置: 首页>>代码示例>>Python>>正文


Python Detector.setParam方法代码示例

本文整理汇总了Python中Detector.Detector.setParam方法的典型用法代码示例。如果您正苦于以下问题:Python Detector.setParam方法的具体用法?Python Detector.setParam怎么用?Python Detector.setParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Detector.Detector的用法示例。


在下文中一共展示了Detector.setParam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DetectorThunk

# 需要导入模块: from Detector import Detector [as 别名]
# 或者: from Detector.Detector import setParam [as 别名]
def DetectorThunk(conn,dir='C:/PAPA Control/',datacount=1000):
    """An infinite loop for controlling the detector

    Keyword arguments:
    conn -- a connection stream for communicating with the main process
    dir -- the directory in which to save data
    datacount -- the number of data points to attempts to read at a time

    The function loops through, either sleeping or recording data.  It polls
    its communication stream and expects a two element tuple.  The first
    element is an event code and the second is a tuple with the arguments for
    the event.

    """
    det = Detector() #detector object
    running = False
    paused = False
    runnumber = -1
    stream = None
    count = 0
    while True:
        if (not running) and (not conn.poll()):
            sleep(0.01)
            continue
        if conn.poll():
            cmd,args=conn.recv()
            if cmd==QUIT:
                break
            elif cmd==START:
                if runnumber<=0:
                    logging.error("Error: Invalid Run #")
                    continue
                if not running:
                    stream = open(dir+("%04d"%runnumber)+'.pel','wb')
                    stream.write(det.makeHeader())
                    det.start()
                    running = True
                    count=0
            elif cmd==STOP:
                if running:
                    det.stop()
                    det.clear()
                    running = False
                    stream.close()
                    stream=None
                    continue
            elif cmd==PAUSE:
                logging.info("Pausing Detector")
                det.stop()#Do NOT clear
                running = False
                paused = True
            elif cmd==RESUME:
                if paused:
                    logging.info("Resuming")
                    det.start()
                    running = True
                else:
                    logging.warning("Cannot resume: detector not paused")
            elif cmd==RUNNUMBER:
                runnumber = args[0]
                conn.send("Run # set to %d"%runnumber)
            elif cmd==DIRECTORY:
                dir = args[0]
            elif cmd == N_COUNT:
                conn.send(count/2)#Correction Needed for 64 Bit Mode
            elif cmd==PARAM:
                opt,val=args
                det.setParam(opt,val)
            elif cmd == QUERY:
                conn.send(det.status[args[0]])
                #print det.status[args[0]]

            else:
                logging.warning("Did not recognize command %d"%cmd)
        if running:
            if stream is None: continue
            try:
                #Get the number of data points and the data
                #note that num is the number of 32 bit data
                #points given by the detector, which may or
                #may not be the actual  number of neutrons,
                #depending on  if the  detector is in 32 or
                #64 bit mode
                (num,data)=det.read(datacount)
            except RuntimeError,(err):
                logging.error(err)
                break
            count += num
            #Pull only the actual data from the buffer
            if num < datacount:
                data=data[:num]
            stream.write(data.tostring())
            if num < datacount:
                stream.flush()
                sleep(0.01)
开发者ID:rprospero,项目名称:PAPA-Control,代码行数:97,代码来源:DetectorProcess.py


注:本文中的Detector.Detector.setParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。