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)
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)
#nt_table: complies with NTTable Normative Type #note: Unless the PvObject's 'values' field is created with an ordered dict, the ordering will be lost. ntTablePV = PvObject( { 'labels': [STRING], 'value': OrderedDict([('id_field', [INT]), ('name_field', [STRING]), ('description_field', [STRING])]) }, 'epics:nt/NTTable:1.0') ntTablePV['labels'] = ['ID', 'Name', 'Description'] #every field under "value" must have the same length (number of elements) ntTablePV.setStructure({ 'id_field': [1, 2, 3, 4], 'name_field': ["Einstein", "Bohr", "Schroedinger", "Watson & Crick"], 'description_field': [ "It's All Relative", "Fun Things to Do with Atoms", "Fun Things to Do with Cats", "D.N.A." ] }) #table: a table-like pv that contains a "value" which is a structure #tablePV is not an NTTable because "dingus" is a structure, not a scalar type #Only the "value" field is displayed; the meta-data field is ignored dingus_types = OrderedDict([('Name', [STRING]), ('Quality', [DOUBLE])]) value_types = OrderedDict([('OK', [BOOLEAN]), ('Dingus', dingus_types)]) tablePV = PvObject({'meta_data': STRING, 'value': value_types}) tablePV['meta_data'] = 'Some example meta-data stuff' dingus = {'Name': ["Thing1", "Thing2", "Thing3"], 'Quality': [90, 50, 75]} value = {'OK': [True, False, True], 'Dingus': dingus} tablePV.setStructure('value', value)