Hi,
I want to fulfill a goal that when running camonitor command, PV name
TEST:PING in the terminal window print "Disconnect!" or "OK!" alternatively.
However, I failed, "self.setParam('PING',a)" seems only run once in the code and in terminal window only print one result.
I have posted the code in the following lines.
Could you give me some suggestions and any help will be appreciated.
Zhefu
#===============================
#!/usr/bin/env python
import os
import threading
import time
from pcaspy import Driver, SimpleServer
prefix = 'TEST:'
pvdb = {
'PING' : {
'type':'enum',
'enums':['Disconnect!','OK!']
},
}
class myDriver(Driver):
def __init__(self):
super(myDriver, self).__init__()
tid=threading.Thread(target=self.determine)
tid.setDaemon(True)
tid.start()
def determine(self):
a=os.system("ping -c 1 -w 1 127.0.0.1")
if (a==0):
while True:
self.setParam('PING',a)
a=not a
time.sleep(5)
if __name__ == '__main__':
server = SimpleServer()
server.createPV(prefix, pvdb)
driver = myDriver()
# process CA transactions
while True:
server.process(0.1)