Exemple #1
0
def createImage(id, nx, ny, colorMode, extraFieldsPvObject=None):
    timeStamp = getTimeStamp()
    if extraFieldsPvObject:
        nda = pva.NtNdArray(extraFieldsPvObject.getStructureDict())
    else:
        nda = pva.NtNdArray()
    nda['uniqueId'] = id
    dims = [
        pva.PvDimension(nx, 0, nx, 1, False),
        pva.PvDimension(ny, 0, ny, 1, False)
    ]
    nda['codec'] = pva.PvCodec('pvapyc', pva.PvInt(14))
    nda['dimension'] = dims
    nda['descriptor'] = 'PvaPy Simulated Image'
    nda['compressedSize'] = nx * ny
    nda['uncompressedSize'] = nx * ny
    nda['timeStamp'] = timeStamp
    nda['dataTimeStamp'] = timeStamp
    attrs = [pva.NtAttribute('ColorMode', pva.PvInt(0))]
    nda['attribute'] = attrs
    nda['value'] = {
        'ubyteValue': np.random.randint(0, 256, size=nx * ny, dtype=np.uint8)
    }
    nda.set(extraFieldsPvObject)
    return nda
Exemple #2
0
    def search(self, x):
        try:
            query = x.getString("entity")
            name = x.getString("name")
        except (pva.FieldNotFound, pva.InvalidRequest):
            return pva.PvString("error")

        if name == "error":
            return pva.PvInt(1000)

        org_value = ENTITIES if str(name) == "entity" else []

        value = [val for val in org_value if val.startswith(query)]

        pv = pva.PvObject({"value": [pva.STRING]},
                          "epics:nt/NTScalarArray:1.0")
        pv["value"] = value

        return pv
Exemple #3
0
    def get(self, x):
        try:
            entity = x.getString("entity")
            starttime = x.getString("starttime")
            endtime = x.getString("endtime")
        except (pva.FieldNotFound, pva.InvalidRequest):
            return pva.PvString("error")

        param1 = int(x.getString("param1")) if x.hasField("param1") else 0

        str_sec = self.is_to_unixtime_seconds(starttime)
        end_sec = self.is_to_unixtime_seconds(endtime)

        if entity == "table":
            table = self.get_table(entity, str_sec, end_sec, param1)
        elif entity == "error":
            table = pva.PvInt(1000)
        else:
            table = self.get_timesrie(entity, str_sec, end_sec, param1)

        return table
Exemple #4
0
    def annotation(self, x):
        try:
            entity = x.getString("entity")
            starttime = x.getString("starttime")
            endtime = x.getString("endtime")
        except (pva.FieldNotFound, pva.InvalidRequest):
            return pva.PvString("error")

        if entity == "error":
            return pva.PvInt(1000)

        str_sec = self.is_to_unixtime_seconds(starttime)
        end_sec = self.is_to_unixtime_seconds(endtime)

        time = [(int(end_sec) + int(str_sec)) // 2 * 1000, end_sec * 1000]
        title = [entity, entity + "2"]
        tags = ["test1,test2", "test1"]
        text = ["test text", "test text2"]

        vals = {
            "column0": [pva.ULONG],
            "column1": [pva.STRING],
            "column2": [pva.STRING],
            "column3": [pva.STRING]
        }
        table = pva.PvObject({
            "labels": [pva.STRING],
            "value": vals
        }, "epics:nt/NTTable:1.0")
        table.setScalarArray("labels", ["time", "title", "tags", "text"])
        table.setStructure("value", {
            "column0": time,
            "column1": title,
            "column2": tags,
            "column3": text
        })

        return table
Exemple #5
0
    def __init__(self):
        pva.PvaServer.__init__(self)
        self.booleanPv = pva.PvBoolean()
        self.addRecord(self.BOOLEAN_CHANNEL_NAME, self.booleanPv)

        self.bytePv = pva.PvByte()
        self.addRecord(self.BYTE_CHANNEL_NAME, self.bytePv)

        self.ubytePv = pva.PvUByte()
        self.addRecord(self.UBYTE_CHANNEL_NAME, self.ubytePv)

        self.shortPv = pva.PvShort()
        self.addRecord(self.SHORT_CHANNEL_NAME, self.shortPv)

        self.ushortPv = pva.PvUShort()
        self.addRecord(self.USHORT_CHANNEL_NAME, self.ushortPv)

        self.intPv = pva.PvInt()
        self.addRecord(self.INT_CHANNEL_NAME, self.intPv)

        self.uintPv = pva.PvUInt()
        self.addRecord(self.UINT_CHANNEL_NAME, self.uintPv)

        self.longPv = pva.PvLong()
        self.addRecord(self.LONG_CHANNEL_NAME, self.longPv)

        self.ulongPv = pva.PvULong()
        self.addRecord(self.ULONG_CHANNEL_NAME, self.ulongPv)

        self.floatPv = pva.PvFloat()
        self.addRecord(self.FLOAT_CHANNEL_NAME, self.floatPv)

        self.doublePv = pva.PvDouble()
        self.addRecord(self.DOUBLE_CHANNEL_NAME, self.doublePv)

        self.stringPv = pva.PvString('')
        self.addRecord(self.STRING_CHANNEL_NAME, self.stringPv)
Exemple #6
0
pv['value.column0'] = [0.1, 0.2, 0.3, 0.4, 0.5]
pv['value.column1'] = [1.1, 1.2, 1.3, 1.4, 1.5]
pv['value.column2'] = [2.1, 2.2, 2.3, 2.4, 2.5]
print('ADDED COLUMN DATA TO PV OBJECT')
print(pv)
print('============================')

attr1 = pva.PvObject(ATTR_STRUCTURE)
attr1['name'] = 'MY ATTR 1'
attr1['descriptor'] = 'very long description'
attr1['value'] = pva.PvDouble(13)
print('CREATED ATTR1')
print(attr1)
print('============================')

attr1.setUnion('value', pva.PvInt(14))
print('MODIFIED ATTR1')
print(attr1)
print('============================')

attr2 = pva.PvObject(ATTR_STRUCTURE)
attr2['name'] = 'MY ATTR 2'
attr2['descriptor'] = 'very long description'
attr2.setUnion('value', pva.PvInt(1124))
print('CREATED ATTR2')
print(attr2)
print('============================')

attrs = [attr1, attr2]
pv['attribute'] = attrs
print('MODIFIED PV OBJECT WITH ATTRS')