55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import java.time.format.DateTimeFormatter as DateTimeFormatter
|
|
import java.time.Instant as Instant
|
|
import java.time.LocalDateTime as LocalDateTime
|
|
import java.time.ZoneOffset as ZoneOffset
|
|
|
|
#with Channel("ABORF-A0-HVPS:I", monitored=False) as ch:
|
|
# print ch.read()
|
|
|
|
class Channel:
|
|
def __init__(self,channel_name, monitored, polling):
|
|
self.channel_name=channel_name
|
|
self.monitored= monitored
|
|
self.polling = polling
|
|
|
|
def __enter__(self):
|
|
self.channel=GenericChannel(self.channel_name,self.channel_name)
|
|
self.channel.setMonitored(self.monitored)
|
|
self.channel.setPolling(self.polling)
|
|
self.channel.initialize()
|
|
return self.channel
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
self.channel.close()
|
|
|
|
|
|
timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
|
|
|
|
def get_time_str(timestamp):
|
|
instant = Instant.ofEpochMilli(timestamp)
|
|
currentTime = LocalDateTime.ofInstant(instant, ZoneOffset.systemDefault())
|
|
return currentTime.format(timeFormatter);
|
|
|
|
|
|
def write_archive(f, timestamp, value):
|
|
print f + " " + get_time_str(timestamp) + " " + str(value)
|
|
|
|
|
|
class ChannelListener (DeviceListener):
|
|
def onCacheChanged(self, ch, value, former, timestamp, valueChange):
|
|
write_archive(ch.name, timestamp, value)
|
|
|
|
val=None
|
|
with Channel("ABORF-A0-HVPS:I", True, 0) as ch:
|
|
#val = ch.update()
|
|
#val=ch.takeTimestamped()
|
|
#write_archive(ch.name, val.timestamp, val.value)
|
|
channel_listener = ChannelListener()
|
|
ch.addListener(channel_listener)
|
|
ch.update()
|
|
val=ch.take()
|
|
time.sleep(10.0)
|
|
|
|
|
|
|
|
|