def test_StructureArray(self): STRUCTURE = { 's': STRING, 'i': INT, 'ru': ({ 'i': INT, 'd': DOUBLE, 's': STRING }, ), 'vu': (), 'st': { 'i': INT, 'd': DOUBLE, 's': STRING }, } size = TestUtility.getRandomListSize() pv = PvObject({'v': [STRUCTURE]}) structureList = [] for i in range(0, size): pv2 = PvObject(STRUCTURE) value = TestUtility.getRandomString() pv2['s'] = value value = TestUtility.getRandomInt() pv2['i'] = value value = TestUtility.getRandomInt() unionPv = PvObject({'i': INT}, {'i': value}) pv2['ru'] = unionPv value = TestUtility.getRandomString() pv2['vu'] = PvString(value) value = TestUtility.getRandomInt() pv2['st.i'] = value value = TestUtility.getRandomString() pv2['st.s'] = value value = TestUtility.getRandomDouble() pv2['st.d'] = value structureList.append(pv2) pv['v'] = structureList sa = pv['v'] for i in range(0, size): pv2 = sa[i] assert (pv2['s'] == structureList[i]['s']) assert (pv2['i'] == structureList[i]['i']) ru = pv2['ru'][0] assert (ru['i'] == structureList[i]['ru'][0]['i']) vu = pv2['vu'][0] assert (vu['value'] == structureList[i]['vu'][0]['value']) assert (pv2['st']['i'] == structureList[i]['st.i']) assert (pv2['st']['s'] == structureList[i]['st.s']) assert (pv2['st']['d'] == structureList[i]['st.d'])
def updateValue(pv): name = pv['value'] #print("updating table for name '%s'" % name) newPV = PvObject(tableStructDict, copy(tablePV.get()), "epics:nt/NTTable:1.0") value = newPV['value'] if name is '': value['id'] = [] value['name'] = names value['title'] = [] for i in range(0, len(names)): value['id'].append(i + 1) value['title'].append(titles[i]) elif name in ids: value['id'] = ids[name] value['name'] = [name] * len(value['id']) value['title'] = [] for id in value['id']: value['title'].append(titles[id - 1]) else: value['id'] = [0] value['name'] = [None] value['title'] = [None] #print("value = %s" % str(value)) newPV['value'] = value server.update('table', newPV)
def test_ScalarArray(self): value = TestUtility.getRandomInt() size = TestUtility.getRandomListSize() valueList = [value] * size pv = PvObject({'vl': [INT]}, {'vl': valueList}) vl = pv['vl'] assert (len(vl) == len(valueList)) assert (vl[0] == valueList[0]) assert (vl[-1] == valueList[-1]) value = TestUtility.getRandomInt() size = TestUtility.getRandomListSize() valueList = [value] * size pv['vl'] = valueList vl = pv['vl'] assert (len(vl) == len(valueList)) assert (vl[0] == valueList[0]) assert (vl[-1] == valueList[-1]) value = TestUtility.getRandomInt() size = TestUtility.getRandomListSize() valueList = [value] * size pv.setScalarArray(valueList) vl = pv.getScalarArray() assert (len(vl) == len(valueList)) assert (vl[0] == valueList[0]) assert (vl[-1] == valueList[-1])
def createImage(uniqueId, data, sizes, typecode=None): image = PvObject(ndarray, {'uniqueId' : uniqueId},'NTNDArray:1.0') #note: not truly 'epics:nt/NTNDArray:1.0' (not compliant with normative types), #so a simple 'NTNDArray:1.0' is used to identify it as an image setImage(image, data, typecode) setDimensions(image, sizes) return image
def test_Double(self): a = np.random.uniform(-9223372036854775808, 9223372036854775808, size=100) pv = PvObject({'a': [DOUBLE]}, {'a': a}) a2 = pv['a'] c = a == a2 assert (c.all())
def test_Long(self): a = np.random.randint(-9223372036854775808, 9223372036854775808, size=100, dtype=np.int64) pv = PvObject({'a': [LONG]}, {'a': a}) a2 = pv['a'] c = a == a2 assert (c.all())
def test_ULong(self): a = np.random.randint(0, 18446744073709551616, size=100, dtype=np.uint64) pv = PvObject({'a': [ULONG]}, {'a': a}) a2 = pv['a'] c = a == a2 assert (c.all())
def test_Float(self): a = np.random.uniform(-9223372036854775808, 9223372036854775808, size=100) a = a.astype(np.float32) pv = PvObject({'a': [FLOAT]}, {'a': a}) a2 = pv['a'] c = a == a2 assert (c.all())
def test_Boolean(self): value = TestUtility.getRandomBoolean() pv = PvObject({'v': BOOLEAN}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomBoolean() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomBoolean() pv.setBoolean(value) assert (pv.getBoolean() == value)
def test_String(self): value = TestUtility.getRandomString() pv = PvObject({'v': STRING}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomString() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomString() pv.setString(value) assert (pv.getString() == value)
def test_Double(self): value = TestUtility.getRandomDouble() pv = PvObject({'v': DOUBLE}, {'v': value}) TestUtility.assertDoubleEquality(pv['v'], value) value = TestUtility.getRandomDouble() pv['v'] = value TestUtility.assertDoubleEquality(pv['v'], value) value = TestUtility.getRandomDouble() pv.setDouble(value) TestUtility.assertDoubleEquality(pv.getDouble(), value)
def test_Float(self): value = TestUtility.getRandomFloat() pv = PvObject({'v': FLOAT}, {'v': value}) TestUtility.assertFloatEquality(pv['v'], value) value = TestUtility.getRandomFloat() pv['v'] = value TestUtility.assertFloatEquality(pv['v'], value) value = TestUtility.getRandomFloat() pv.setFloat(value) TestUtility.assertFloatEquality(pv.getFloat(), value)
def test_ULong(self): value = TestUtility.getRandomULong() pv = PvObject({'v': ULONG}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomULong() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomULong() pv.setULong(value) assert (pv.getULong() == value)
def test_Int(self): value = TestUtility.getRandomInt() pv = PvObject({'v': INT}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomInt() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomInt() pv.setInt(value) assert (pv.getInt() == value)
def test_UByte(self): value = TestUtility.getRandomUByte() pv = PvObject({'v': UBYTE}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomUByte() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomUByte() pv.setUByte(value) assert (pv.getUByte() == value)
def test_UShort(self): value = TestUtility.getRandomUShort() pv = PvObject({'v': USHORT}, {'v': value}) assert (pv['v'] == value) value = TestUtility.getRandomUShort() pv['v'] = value assert (pv['v'] == value) value = TestUtility.getRandomUShort() pv.setUShort(value) assert (pv.getUShort() == value)
def test_RestrictedUnion(self): value = TestUtility.getRandomInt() unionPv = PvObject({'i': INT}, {'i': value}) pv = PvObject({'v': ({ 'i': INT, 'f': FLOAT, 's': STRING }, )}, {'v': unionPv}) u = pv['v'][0] assert (u['i'] == value) value = TestUtility.getRandomString() unionPv = PvObject({'s': STRING}, {'s': value}) pv['v'] = unionPv u = pv['v'][0] assert (u['s'] == value) value = TestUtility.getRandomFloat() unionPv = PvObject({'f': FLOAT}, {'f': value}) pv.setUnion(unionPv) u = pv['v'][0] TestUtility.assertFloatEquality(u['f'], value)
def test_Structure(self): pv = PvObject({ 's': STRING, 'i': INT, 'ru': ({ 'i': INT, 'd': DOUBLE, 's': STRING }, ), 'vu': (), 'st': { 'i': INT, 'd': DOUBLE, 's': STRING }, }) value = TestUtility.getRandomString() pv['s'] = value assert (pv['s'] == value) value = TestUtility.getRandomInt() pv['i'] = value assert (pv['i'] == value) value = TestUtility.getRandomInt() unionPv = PvObject({'i': INT}, {'i': value}) pv['ru'] = unionPv u = pv['ru'][0] assert (u['i'] == value) value = TestUtility.getRandomString() pv['vu'] = PvString(value) u = pv['vu'][0] assert (u['value'] == value) value = TestUtility.getRandomInt() pv['st.i'] = value assert (pv['st.i'] == value)
def test_RestrictedUnionArray(self): size = TestUtility.getRandomListSize() pv = PvObject({'v': [({'i': INT, 's': STRING, 'd': DOUBLE}, )]}) unionList = [] for i in range(0, size): if i % 3 == 0: value = TestUtility.getRandomInt() unionList.append(PvObject({'i': INT}, {'i': value})) elif i % 3 == 1: value = TestUtility.getRandomString() unionList.append(PvObject({'s': STRING}, {'s': value})) else: value = TestUtility.getRandomDouble() unionList.append(PvObject({'d': DOUBLE}, {'d': value})) pv['v'] = unionList ul = pv['v'] for i in range(0, size): uli = ul[i][0] if 'i' in uli: assert (uli['i'] == unionList[i]['i']) elif 's' in uli: assert (uli['s'] == unionList[i]['s']) else: TestUtility.assertDoubleEquality(uli['d'], unionList[i]['d']) unionList.reverse() pv.setUnionArray(unionList) ul = pv['v'] for i in range(0, size): uli = ul[i][0] if 'i' in uli: assert (uli['i'] == unionList[i]['i']) elif 's' in uli: assert (uli['s'] == unionList[i]['s']) else: TestUtility.assertDoubleEquality(uli['d'], unionList[i]['d'])
def test_VariantUnion(self): value = TestUtility.getRandomInt() pv = PvObject({'v': ()}, {'v': PvInt(value)}) u = pv['v'][0] assert (u['value'] == value) value = TestUtility.getRandomString() pv['v'] = PvString(value) u = pv['v'][0] assert (u['value'] == value) value = TestUtility.getRandomFloat() pv.setUnion(PvFloat(value)) u = pv['v'][0] TestUtility.assertFloatEquality(u['value'], value)
def createImage(uniqueId, data, sizes, typecode=None, offsets=repeat(0), binnings=repeat(1), reverses=repeat(False), codec={}, attribute=[{}]): image = PvObject(ntndarray, {'uniqueId': uniqueId}, 'epics:nt/NTNDArray:1.0') setCodec(image, codec) #setAttribute(image, attribute) setImage(image, data, typecode) setDimensions(image, sizes, offsets, binnings, reverses) return image
def test_VariantUnionArray(self): size = TestUtility.getRandomListSize() pv = PvObject({'v': [()]}) unionList = [] for i in range(0, size): value = TestUtility.getRandomInt() unionList.append(PvInt(value)) pv['v'] = unionList ul = pv['v'] for i in range(0, size): uli = ul[i][0] assert (uli['value'] == unionList[i]['value']) unionList.reverse() pv.setUnionArray(unionList) ul = pv.getUnionArray() for i in range(0, size): uli = ul[i] assert (uli['value'] == unionList[i]['value'])
def startPvaServer(): roachsets = PvObject({ 'atU6': INT, 'atU7': INT, 'atU28': INT, 'bbloop': INT, 'rfloop': INT, 'extLO': INT, 'centfreq': DOUBLE, 'spanfreq': DOUBLE, 'isconnected': INT, 'status': STRING }) roachconn = PvInt(0) roachdisconn = PvInt(0) roachsweep = PvInt(0) pvaServer = PvaServer('DP:roach1:settings', roachsets) pvaServer.addRecord('DP:roach1:connect', roachconn) pvaServer.addRecord('DP:roach1:disconnect', roachdisconn) pvaServer.addRecord('DP:roach1:sweep', roachsweep)
# Example of pvAccess Server in Python from time import sleep from pvaccess import PvObject, INT, PvaServer print("This serves pva://pair") print("") print("Try") print(" pvinfo pair") print(" pvget -m -r \"x, y\" pair") print("") print("or open examples/displays/PVA_Server.bob") print("") pv = PvObject({'x': INT, 'y': INT}) server = PvaServer('pair', pv) x = 1 while True: pv['x'] = x pv['y'] = 2 * x print(x, 2 * x) server.update(pv) sleep(1) x = x + 1
highWarningLimit = 6 highAlarmLimit = 8 lowAlarmSeverity = 2 lowWarningSeverity = 1 highWarningSeverity = 1 highAlarmSeverity = 2 messages = ["NO_ALARM", "LOLO", "LO", "HI", "HIHI"] #get an int structure, and add the optional fields timeStamp and alarm rampStructure = PvInt().getStructureDict() rampStructure['timeStamp'] = timeStamp.getStructureDict() rampStructure['alarm'] = alarm.getStructureDict() #create an int PV with value 0 ramp = PvObject(rampStructure, {'value': 0}, 'epics:nt/NTScalar:1.0') server = PvaServer('ramp', ramp) while True: #update ramp value dict instead of ramp, so all values update at once rampValue = ramp.get() #print(str(rampValue)) value = rampValue['value'] rampValue['value'] = (value + 1) % 10 fraction, secs = math.modf(time.time()) timeStamp.setSecondsPastEpoch(long(secs)) timeStamp.setNanoseconds(int(fraction * 1000000000)) rampValue['timeStamp'] = timeStamp.get()
#!/usr/bin/env python # # This example can be used to demonstrate pvaPy server/client channel # monitoring # # Run server.py in one window, and client.py in another one. # import time from pvaccess import ULONG from pvaccess import PvObject from pvaccess import PvaServer if __name__ == '__main__': pv = PvObject({'c': ULONG}) server = PvaServer('counter', pv) c = 0 startTime = time.time() while True: c += 1 pv = PvObject({'c': ULONG}, {'c': c}) server.update(pv) if c % 100000 == 0: currentTime = time.time() runtime = currentTime - startTime updateRateKHz = c / runtime / 1000.0 print('Runtime: %.2f; Counter: %9d, Rate: %.2f [kHz]' % (runtime, c, updateRateKHz))
for id in value['id']: value['title'].append(titles[id - 1]) else: value['id'] = [0] value['name'] = [None] value['title'] = [None] #print("value = %s" % str(value)) newPV['value'] = value server.update('table', newPV) # create PVs tableStructDict = { 'labels': [STRING], 'value': dict(OrderedDict([('id', [UINT]), ('name', [STRING]), ('title', [STRING])])) } tablePV = PvObject(tableStructDict, "epics:nt/NTTable:1.0") tablePV['labels'] = ['ID', 'Name', 'Title'] namePV = PvString('') # create server server = PvaServer('table', tablePV) server.addRecord('name', namePV, updateValue) try: raw_input("\nEnter anything to quit\n") except NameError as ex: input("\nEnter anything to quit\n")
#!/usr/bin/env python # # This example can be used to demonstrate pvaPy server with multiple channels. # import time from pvaccess import ULONG from pvaccess import STRING from pvaccess import PvObject from pvaccess import PvaServer if __name__ == '__main__': server = PvaServer() pv = PvObject({'c': ULONG}) server.addRecord('c', pv) pv2 = PvObject({'c2': STRING}) server.addRecord('c2', pv2) print('CHANNELS: %s' % server.getRecordNames()) c = 0 startTime = time.time() while True: c += 1 pv = PvObject({'c': ULONG}, {'c': c}) server.update('c', pv) pv2 = PvObject({'c2': STRING}, {'c2': str(c)}) server.update('c2', pv2) if c % 100000 == 0: currentTime = time.time() runtime = currentTime - startTime updateRateKHz = c / runtime / 1000.0
#!/usr/bin/env python import time from pvaccess import PvObject, PvaServer, INT, Channel def echo(x): print('Got value: %s' % x) data = PvObject({'value': INT}, {'value': 1}) data2 = PvObject({'value': INT}, {'value': 2}) print("Starting Server") server = PvaServer('foo', data, echo) channel = Channel('foo') print("Attempting get") print(channel.get()) print("Attempting put") channel.put(data2) print("Put done") print(channel.get()) print("Stopping server") server.stop() time.sleep(3) print("Starting server") server.start() time.sleep(3)
from pvaccess import PvObject, STRING, DOUBLE, NtTable import pvaccess pvObject = PvObject({ 'labels': [STRING], 'value': { 'column0': [DOUBLE], 'column1': [DOUBLE], 'column2': [DOUBLE] } }) pvObject.setScalarArray('labels', ['x', 'y', 'z']) pvObject.setStructure( 'value', { 'column0': [0.1, 0.2, 0.3], 'column1': [1.1, 1.2, 1.3], 'column2': [2.1, 2.2, 2.3] }) table3 = NtTable(pvObject) print table3 rpc = pvaccess.RpcClient('table') request = table3 rpc.invoke(request)