-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantenna.py
74 lines (70 loc) · 3.23 KB
/
antenna.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import socket, time
from MDSplus import Device, Data, Action, Dispatch, Method, makeArray, Range, Signal, Window, Dimension
import tcp_comm
class ANTENNA(Device):
'''Device to talk to Labview and integrate it into MDSplus better
'''
parts=[{'path':':HOSTIP','type':'text','value':'150.203.179.4:8051','options':('no_write_shot',)}]
parts.append({'path':':INIT_ACTION','type':'action',
'valueExpr':"Action(Dispatch('CAMAC_SERVER45_1','INIT',50,None),Method(None,'INIT',head))",
'options':('no_write_shot',)})
parts.append({'path':':STORE_ACTION','type':'action',
'valueExpr':"Action(Dispatch('CAMAC_SERVER45_1','STORE',50,None),Method(None,'STORE',head))",
'options':('no_write_shot',)})
parts.append({'path':':RFTUNE1','type':'numeric','value':0})
parts.append({'path':':RFTUNE2','type':'numeric','value':0})
parts.append({'path':':RFTUNE3','type':'numeric','value':0})
parts.append({'path':':RFTUNE4','type':'numeric','value':0})
parts.append({'path':':CONFIG','type':'numeric','value':0})
def init(self, arg):
'''initialise the labview device over a socket
SH:20Mar2013
'''
try:
error = None
start_time = time.time()
print '####################################################'
print 'Antenna init has started : MDSplus Device, SH 6Nov2013'
self.shot = self.getTree().shot
self.tree_loc = self.getPath()
ip, port = self.hostip.record.split(':')
self.ip = ip
self.port = int(port)
tcp = tcp_comm.tcp_ip_connection(self.ip, self.port, 'INIT', self.tree_loc, self.shot)
tcp.send_receive()
print(' finished in {:.2f}s'.format(time.time() - start_time))
#return 1
except Exception,e:
#Catch exceptions, then throw another exception so the dispatcher fails on this item
if error is not None:
e=error
print "%s" % (str(e),)
print(' finished in {:.2f}s'.format(time.time() - start_time))
raise RuntimeError('!!! EXCEPTION - %s'%(str(e)))
INIT = init
def store(self, arg):
'''tell the labview device it is time to store
SH : 20Mar2013
'''
try:
error = None
print '####################################################'
print 'Antenna store has started : MDSplus Device, SH 6Nov2013'
self.shot = self.getTree().shot
start_time = time.time()
self.tree_loc = self.getPath()
ip, port = self.hostip.record.split(':')
self.ip = ip
self.port = int(port)
tcp = tcp_comm.tcp_ip_connection(self.ip, self.port, 'STORE', self.tree_loc, self.shot)
tcp.send_receive()
print(' finished in {:.2f}s'.format(time.time() - start_time))
#return 1
except Exception,e:
if error is not None:
e=error
print "%s\n" % (str(e),)
print(' finished in {:.2f}s'.format(time.time() - start_time))
raise RuntimeError('!!! EXCEPTION - %s'%(str(e)))
#return 0
STORE = store