paulscherrerinstitute / pcaspy

Portable Channel Access Server in Python
BSD 3-Clause "New" or "Revised" License
32 stars 24 forks source link

Change the timestamp of PV #54

Closed hinxx closed 1 year ago

hinxx commented 6 years ago

Can I change the PV timestamp to an arbitrary value before PV update is posted? I'm trying to use pscapy as a softIOC proxy between real IOCs with MRF EVR timestamped PVs and other CA clients. In this scenario I would like to keep the source PV timestamp and slap it onto pcaspy PV.

xiaoqiangwang commented 6 years ago

Not in the public API. The timestamp is updated each time setParam is called. But you can update it after setParam and before updatePVs. self.pvDB[reason].time = my_new_time

my_new_time can be manipulated

>>> ts = pcaspy.cas.epicsTimeStamp()
>>> ts.secPastEpoch
905179260
>>> ts.secPastEpoch = 905179220
hinxx commented 6 years ago

Thanks for the help. I overloaded the setParam(self, reason, value) and added this code to the reason of interest:

            ts = epicsTimeStamp()
            ts.secPastEpoch = 905179220
            ts.nsec = 0
            self.pvDB[reason].time = ts
CarlosCumming commented 5 years ago

I need to do the exact same thing for exactly the same reason (bridge from epics -> older stuff). It would be nice if this was more official, not hackish as it is.

xiaoqiangwang commented 5 years ago

I have in mind adding such an API setParamTimestamp(reason, timestamp) in analog to setParamStatus. But I couldn't decide on two things, so I left it out.

I would like to hear your opinions on this.

hinxx commented 5 years ago

How about allowing both, epicsTimeStamp and time.time() double, as arguments? The serParamTimestamp method would check for the type and assume epoch accordingly, depending on the timestamp data type.

CarlosCumming commented 5 years ago

I'm fine either way, as long as it's documented. It s/b easy to switch from time.time() -> epicsTimeStamp.

xiaoqiangwang commented 1 year ago

With the 0.8 release the pcaspy.Driver.setParam takes a keyword argument timestamp. It should be of pcaspy.cas.epicsTimeStamp type.

And there are helper methods fromPosixTimeStamp to convert from a POSIX timestamp.