当前位置:网站首页>pyepics --Auto-saving: simple save/restore PVs

pyepics --Auto-saving: simple save/restore PVs

2022-06-09 16:56:00 yuyuyuliang00

autosave The module is PVs Simple is provided save/restore function , Have function save_pvs() and restore_pvs() And one. AutoSaver class . These are similar to those used for IOCs Of synApps Of autosave modular , In that module , They use a description of what to save PVs Compatible request file, And a compatible that holds the saved value save file. Currently, channel access is used for reading and writing , And there is no need to work with a single IOC Related to .

This module needs to be installed pyparsing package . This is a fairly common third party Python package , Included in many package managers , Or use something like easy_install or pip install , Or from PyPI download .

Request and Save The file is designed to be compatible synApps autosave. Be careful : Macro replacement is supported file command , So you can have one like this Request:

# My.req
file "SimpleMotor.req", P=IOC:, Q=m1

This SimpleMotor.req File for :

# SimpleMotor.req
$(P)$(Q).VAL
$(P)$(Q).DIR
$(P)$(Q).FOFF

It can be used for a SimpleMotor Many examples of . But not used to find request File automation mechanism . You will need to include these in your working directory or specify an absolute path .

There is such a document , Just use :

import epics.autosave
epics.autosave.save_pvs("My.req", "my_values.sav")

The corresponding... Will be saved PVs To the file my_values.sav. After a while , These values can be restored with the following :

import epics.autosave
epics.autosave.restore_pvs("my_values.sav")

The saved file will be associated with autosave The mechanism saves files in almost the same format , also restore_pvs() Functions can be used from autosave Of save File read and restore values . Be careful : Purpose and standard here autosave The purpose of the module (autosave Modules are designed to hold values , Make in IOC Initialization at startup PVs) Very different . Using the function here will perform a test on the saved value caput().

autosave.save_pvs(request_file, save_file)

Save in request_file The current values listed in to save_file.

Parameters :

  1. request_file: Read the... To be saved PVs Of Request The name of the document
  2. save_file: Write the values to be saved to this file .

As mentioned above ,request_file According to from synApps Of autosave The rules of the module .

autosave.restore_pvs(save_file)

from save_file Read the value and set the corresponding PVs Restore them .

Parameters :

save_file: Read the saved value from the file with this name

Be careful :restore_pvs() Will restore all values it can , Skip any values that it cannot recover .

Autosaver class

Autosaver Class is a convenient way : Repeat save in one request Listed in the file PVs, Without having to reconnect all PVs.Autosaver Retain PV Connect , And provide a save current PV Value to a file save(). Default , Name that file from this request file and the current time . This makes you do things like this :

#!/usr/bin/env python
# save PVs from a request file once per minute
import time
from epics.autosave import AutoSaver
my_saver = AutoSaver("My.req")

# save all PVs every minute for a day
t0 = time.time()
while True:
    if time.localtime().tm_sec < 5:
        my_saver.save()
        time.sleep(30 - time.localtime().tm_sec)
    if time.time() - t0 > 86400.0:
        break
    time.sleep(0.5)

This will be like My_2017Oct02_141800.sav Name of the file saved PVs.

class autosave.AutoSaver(request_file)

Create an automation based on a request file Saver.

Parameters :

request_file: Name of the request file .

AutoSaver There are two ways :read_request_file() Read a request file , and save() Save results .

autosave.read_request_file(request_file)

Read and parse request file , To begin PV Connect .

Parameters :

request_file: Name of the request file .

autosave.save(save_file=None, verbose=False)

Read the current PV value , Write save file .

Parameters :

  1. save_file: Save the name of the file or None. If None, The file and timestamp of the requested file will be used ( Turn into seconds ) To build a file name . Be careful : There is no need to check the rewritten file .
  2. verbose: Whether to print the results to the screen [ Default False]

Supported file types

It can be used autosave Routine saves and restores all scalars PV value . Some are right waveform( Array ) Data support . for example , Containing a long string waveform Can be saved and restored . Besides , Can be saved and restored in waveform Array of values in . For array data , The results may not be fully compatible autosave modular .

Example

A use autosave A simple example of a module :

import epics.autosave
# save values
epics.autosave.save_pvs("my_request_file.req",
                        "/tmp/my_recent_save.sav")

# wait 30 seconds
time.sleep(30)

# restore those values back
epics.autosave.restore_pvs("/tmp/my_recent_save.sav")
原网站

版权声明
本文为[yuyuyuliang00]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091630103500.html