Exemple #1
0
def connection_cb(pvname, conn, **kw):
    logger.debug("PV '%s' connected: %s", pvname, conn)
    
    datastore.save_conn_status(pvname, conn)
    if not conn:
        # save PV data with PV value as None/null
        update_id = uuid.uuid1()
        datastore.save_update(update_id, timestamp=time.time(), 
                pvname=pvname, value=None) 
Exemple #2
0
def epics_periodic(state, pvname, period):
    """ Invoked every time a period for a scanned PV is due """
    logger.debug("Periodic scan for PV '%s' with period %f secs", pvname, period)
    # get the pv's value
    pv = state.get('pv')
    if pv:
        if pv.connected:
            #generate the id for the update
            update_id = uuid.uuid1()
            data = _gather_pv_data(pv)
            datastore.save_update(update_id, **data) 
        else: # not connected
            logger.warn("Non-connected PV '%s'. Saving with 'null' value", pvname)
            # save PV data with PV value as None/null
            update_id = uuid.uuid1()
            datastore.save_update(update_id, timestamp=time.time(), pvname=pvname, value=None) 
    else:
        logger.error("Missing data in 'state' for '%s'", pvname)
Exemple #3
0
def subscription_cb(**kw):
    """ Internally called when a new value arrives for a subscribed PV. """
    logger.debug("PV callback invoked: %(pvname)s changed to value %(value)s at %(timestamp)s" % kw)

    pv = kw['cb_info'][1]
    pvname = kw['pvname']
    value = kw['value']

    max_f = pv.mode.max_freq 
    last_arch_time = getattr(pv, 'last_arch_time', None)
    now = pv.timestamp
    # archive iff
    # 1) we are below max frequency
    # AND
    # 2) the change in value is >= delta
    if last_arch_time:
        freq = 1/(now - last_arch_time)
        if max_f and freq > max_f: # if max_f is false, it always passes
            #logger.warn("Values for '%s' arriving faster than %f Hz: %f Hz", pvname, max_f, freq)
            return
        
        # here, we've passed the frequency test
        last_value = getattr(pv, 'last_value', None)
        if last_value:
            d = abs( last_value - value )
            if d < pv.mode.delta:
                logger.debug("Value '%r' below delta (%r) for '%s'", value, pv.mode.delta, pvname)
                return
    
    # if there's no previous recorded "frequency", archive
    # likewise for value

    # if we've made it this far, archive
    setattr(pv, 'last_arch_time', now)
    setattr(pv, 'last_value', value)

    #generate the id for the update
    update_id = uuid.uuid1()
    data = _gather_pv_data(pv)

    datastore.save_update(update_id, **data)