コード例 #1
0
ファイル: main.py プロジェクト: joshStillerman/MARTE-Docker
 def sendY_M(self):
     print('sendY_M')
     print('sendStream')
     print('sendStream(shot, name, time, data)', 0, 'Y_M',
           MDSplus.Float32(self.sim_time),
           MDSplus.Float64Array(self.y_m[self.sim_index, :]))
     sendStream(0, 'Y_M', MDSplus.Float32(self.sim_time),
                MDSplus.Float64Array(self.y_m[self.sim_index, :]))
     print('send setpoint')
     MDSplus.Event.stream(0, 'SETPOINT', MDSplus.Float32(self.sim_time),
                          MDSplus.Float64(self.set_point[self.sim_index]))
     self.sim_index += 1
     print('set label')
     self.ui.Y_Mlabel.setText(str(self.y_m[self.sim_index, 0]))
     self.sim_time += .01
     print('done')
コード例 #2
0
def writedata(data, dims, nodepath, expt, shot):
    """ data: list of images """
    """ dims: array of double seconds based on T1 """
    tree = _mds.Tree(expt, shot)
    node = tree.getNode(nodepath)
    node.deleteData()
    for i in range(len(data)):
        dim = _mds.Float64Array(dims[i])
        dim.setUnits('s')
        node.makeSegment(dims[i], dims[i], dim, _mds.makeArray(data[i]), -1)
コード例 #3
0
    def _Fp2Mds(self):
        """
        Store the Fast Reciprocating probe into the
        appropriate MDSplus Tree
        """

        # density
        if self._Plunge1:
            dummy = self.saveTree.getNode(r'\FP_1PL_EN')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.enU1,
                                 self.tU1))
            dummy.setUnits('m-3')

            dummy = self.saveTree.getNode(r'\FP_1PL_ENERR')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)",
                                 self.enU1Err, self.tU1))
            dummy.setUnits('m-3')
            # temperature
            dummy = self.saveTree.getNode(r'\FP_1PL_TE')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.teU1,
                                 self.tU1))
            dummy.setUnits('eV')

            try:
                dummy = self.saveTree.getNode(r'\FP_1PL_TEERR')
                dummy.putData(
                    mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)",
                                     self.teU1Err, self.tU1))
                dummy.setUnits('eV')
            except:
                pass
            # jsat
            dummy = self.saveTree.getNode(r'\FP_1PL_JS')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.jsU1,
                                 self.tU1))
            dummy.setUnits('Am-2')
            # floating potentials
            dummy = self.saveTree.getNode(r'\FP_1PL_VFT')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfTU1,
                                 self.tU1))
            dummy.setUnits('V')

            dummy = self.saveTree.getNode(r'\FP_1PL_VFM')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfMU1,
                                 self.tU1))
            dummy.setUnits('V')

            dummy = self.saveTree.getNode(r'\FP_1PL_VFB')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfBU1,
                                 self.tU1))
            dummy.setUnits('V')
            # rho
            dummy = self.saveTree.getNode(r'\FP_1PL_RHO')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.rhoU1,
                                 self.tU1))
            # R-Rsep
            dummy = self.saveTree.getNode(r'\FP_1PL_RRSEP')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.drUsU1,
                                 self.tU1))
            dummy.setUnits('m')
            # R-Rsep time
            dummy = self.saveTree.getNode(r'\FP_1PL_RRSEPT')
            dt = numpy.diff(self.RRsepT1Time).mean()
            timeS = numpy.round(dt / (10**numpy.floor(
                numpy.log10(dt)))).astype('|S4') + '*1e' + numpy.floor(
                    numpy.log10(dt)).astype('|S2')
            string = 'Build_Signal(Build_With_Units($VALUE,"m"),$, Build_Dim(Build_Window(0,' + \
                         str(self.RRsepT1Time.size - 1) + ',' + \
                     str(self.RRsepT1Time.min()) + '),*:*:' + timeS + '))'
            expr = mds.Data.compile(string, mds.Float64Array(self.RRsepT1))
            dummy.putData(expr)
            dummy.setUnits('m')

            # Rho time
            dummy = self.saveTree.getNode(r'\FP_1PL_RHOT')
            dt = numpy.diff(self.RhoT1Time).mean()
            timeS = numpy.round(dt / (10**numpy.floor(
                numpy.log10(dt)))).astype('|S4') + '*1e' + numpy.floor(
                    numpy.log10(dt)).astype('|S2')
            string = 'Build_Signal(Build_With_Units($VALUE,"rho"),$, Build_Dim(Build_Window(0,' + \
                         str(self.RhoT1Time.size - 1) + ',' + \
                     str(self.RhoT1Time.min()) + '),*:*:' + timeS + '))'
            expr = mds.Data.compile(string, mds.Float64Array(self.RhoT1))
            dummy.putData(expr)
            dummy.setUnits(' ')
        if self._Plunge2:
            dummy = self.saveTree.getNode(r'\FP_2PL_EN')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.enU2,
                                 self.tU2))
            dummy.setUnits('m-3')

            dummy = self.saveTree.getNode(r'\FP_2PL_ENERR')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)",
                                 self.enU2Err, self.tU2))
            dummy.setUnits('m-3')
            # temperature
            dummy = self.saveTree.getNode(r'\FP_2PL_TE')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.teU2,
                                 self.tU2))
            dummy.setUnits('eV')
            try:
                dummy = self.saveTree.getNode(r'\FP_2PL_TEERR')
                dummy.putData(
                    mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)",
                                     self.teU2Err, self.tU2))
                dummy.setUnits('eV')
            except:
                pass

            # jsat
            dummy = self.saveTree.getNode(r'\FP_2PL_JS')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.jsU2,
                                 self.tU2))
            dummy.setUnits('Am-2')
            # floating potentials
            dummy = self.saveTree.getNode(r'\FP_2PL_VFT')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfTU2,
                                 self.tU2))
            dummy.setUnits('V')

            dummy = self.saveTree.getNode(r'\FP_2PL_VFM')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfMU2,
                                 self.tU2))
            dummy.setUnits('V')

            dummy = self.saveTree.getNode(r'\FP_2PL_VFB')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.vfBU2,
                                 self.tU2))
            dummy.setUnits('V')
            # rho
            dummy = self.saveTree.getNode(r'\FP_2PL_RHO')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.rhoU2,
                                 self.tU2))
            # R-Rsep
            dummy = self.saveTree.getNode(r'\FP_2PL_RRSEP')
            dummy.putData(
                mds.Data.compile("BUILD_SIGNAL(($VALUE), $1, $2)", self.drUsU2,
                                 self.tU2))
            dummy.setUnits('m')

            # R-Rsep time
            dummy = self.saveTree.getNode(r'\FP_2PL_RRSEPT')
            dt = numpy.diff(self.RRsepT2Time).mean()
            timeS = numpy.round(dt / (10**numpy.floor(
                numpy.log10(dt)))).astype('|S4') + '*1e' + numpy.floor(
                    numpy.log10(dt)).astype('|S2')
            string = 'Build_Signal(Build_With_Units($VALUE,"m"),$, Build_Dim(Build_Window(0,' + \
                         str(self.RRsepT2Time.size - 1) + ',' + \
                     str(self.RRsepT2Time.min()) + '),*:*:' + timeS + '))'
            expr = mds.Data.compile(string, mds.Float64Array(self.RRsepT2))
            dummy.putData(expr)
            dummy.setUnits('m')

            # Rho time
            dummy = self.saveTree.getNode(r'\FP_2PL_RHOT')
            dt = numpy.diff(self.RhoT2Time).mean()
            timeS = numpy.round(dt / (10**numpy.floor(
                numpy.log10(dt)))).astype('|S4') + '*1e' + numpy.floor(
                    numpy.log10(dt)).astype('|S2')
            string = 'Build_Signal(Build_With_Units($VALUE,"rho"),$, Build_Dim(Build_Window(0,' + \
                         str(self.RhoT2Time.size - 1) + ',' + \
                     str(self.RhoT2Time.min()) + '),*:*:' + timeS + '))'
            expr = mds.Data.compile(string, mds.Float64Array(self.RhoT2))
            dummy.putData(expr)
            dummy.setUnits(' ')
コード例 #4
0
class BNC845(MDSplus.Device):
    """Control functions for the BNC generator supplied by FZ Juelich, based on BNCCommunication.py by A. Kraemer-Flecken ([email protected]).  Can be tested with script sim_bncgen from the MDSplusW7X project."""
    parts = [
        {
            'path': ':HOST',
            'type': 'TEXT',
            'options': ('no_write_shot', ),
            'value': '192.168.0.100'
        },
        {
            'path': ':PORT',
            'type': 'NUMERIC',
            'options': ('no_write_shot', ),
            'value': 18
        },
        {
            'path': ':TRIG_SRC',
            'type': 'TEXT',
            'options': ('no_write_shot', ),
            'value': 'external'
        },
        {
            'path': ':TRIG_SLOPE',
            'type': 'TEXT',
            'options': ('no_write_shot', ),
            'value': 'pos'
        },
        {
            'path': ':BLANKING',
            'type': 'NUMERIC',
            'options': ('no_write_shot', ),
            'value': 0
        },  # on/off
        {
            'path': ':POWER',
            'type': 'NUMERIC',
            'options': ('no_write_shot', ),
            'value': 10
        },  # dBm
        {
            'path': ':OFFSET',
            'type': 'NUMERIC',
            'options': ('no_write_shot', ),
            'value': 30
        },  # MHz
        {
            'path': ':SWEEPS',
            'type': 'NUMERIC',
            'options': ('no_write_shot', ),
            'value': 3
        },
        {
            'path':
            ':STEPS',
            'type':
            'NUMERIC',
            'options': ('no_write_shot', ),
            'value':
            MDSplus.Float64Array([[5000, 23.2], [10000, 23.4], [15000, 23.6],
                                  [20000, 23.8], [25000, 24.0], [30000, 24.2],
                                  [35000, 24.4], [40000, 24.6], [45000, 24.8]])
        },  # ms, GHz
        {
            'path':
            ':DEINI_ACTION',
            'type':
            'ACTION',
            'options': ('no_write_shot', ),
            'valueExpr':
            "Action(Dispatch('MAIN_SERVER', 'DEINIT', 1, None), Method(None, 'off',  head))"
        },
        {
            'path':
            ':INIT_ACTION',
            'type':
            'ACTION',
            'options': ('no_write_shot', ),
            'valueExpr':
            "Action(Dispatch('MAIN_SERVER', 'INIT',   1, None), Method(None, 'init', head))"
        },
        {
            'path': ':INIT_LOG',
            'type': 'TEXT',
            'options': ('no_write_model', 'write_once')
        },
        {
            'path': ':INIT_CONFIG',
            'type': 'TEXT',
            'options': ('no_write_model', 'write_once')
        }
    ]

    def init(self, disable_rf=None):

        #### read config nodes ####

        try:
            host = self.host.data()
            port = self.port.data()
            trig_src = self.trig_src.data()
            trig_slope = self.trig_slope.data()
            blanking = self.blanking.data()
            power = self.power.data()
            offset = self.offset.data()
            sweeps = self.sweeps.data()
            steps = self.steps.data()
        except:
            print('One or more configs is missing or invalid.')
            return 0

        delay = 0.0  # constant, not confirgurable

        #### build buffers ####

        freq_buf = ''
        power_buf = ''
        delay_buf = ''
        dwell_buf = ''

        if len(steps.shape) < 2:
            steps = steps.reshape(1, 2)

        N = steps.shape[0]
        for i in range(N):
            dwell = (steps[i][0] -
                     steps[i - 1][0] if i > 0 else steps[i][0]) / 1e3
            freq = steps[i][1] * 1e9 / 2.0

            freq_buf += (', ' if i > 0 else '') + str(freq)
            power_buf += (', ' if i > 0 else '') + str(power)
            delay_buf += (', ' if i > 0 else '') + str(delay)
            dwell_buf += (', ' if i > 0 else '') + str(dwell)

        #### program BNC ####

        log = str(datetime.datetime.utcnow()) + '\n'  # first line of INIT_LOG

        (sock, remote_ip) = bnc_connect(host, port)
        log += 'Connected to %s (%s)\n' % (host, remote_ip)

        ans = bnc_talk(sock, '*TST?')
        if '0' in ans:
            log += 'All tests passed sucessfully.\n'
        else:
            log += 'One or more tests failed.'
            sock.close()
            self.init_log.putData(log)
            return 0

        all_ok = True

        ans = bnc_talk(sock, '*IDN?')
        config = 'Identification: ' + ans + '\n'  # first line of INIT_CONFIG

        ans = bnc_talk(sock, 'syst:vers?')
        config += 'SCPI version number: ' + ans + '\n'

        ans = bnc_talk(sock, 'freq:mode fix')
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'BNC sweep mode stopped: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, ':list:freq ' + freq_buf)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set frequencies: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, ':list:freq?')
        freq_list = ans.split(',')

        ans = bnc_talk(sock, ':list:power ' + power_buf)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set power: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, ':list:power?')
        power_list = ans.split(',')

        ans = bnc_talk(sock, ':list:delay ' + delay_buf)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set delay time: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, ':list:delay?')
        delay_list = ans.split(',')

        ans = bnc_talk(sock, ':list:dwell ' + dwell_buf)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set dwell time: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, ':list:dwell?')
        dwell_list = ans.split(',')

        if len(freq_list) == N and len(power_list) == N and len(
                delay_list) == N and len(dwell_list) == N:
            config += 'Frequency/power/delay/duration settings:\n'
            for i in range(N):
                config += '  Step %d:  %s [GHz]  %s [dBm]  %s [s]  %s [s]\n' % (
                    i, freq_list[i], power_list[i], delay_list[i],
                    dwell_list[i])

        ans = bnc_talk(sock, 'sour:list:count ' + str(sweeps))
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Repetition rate set: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'sour:list:count?')
        config += 'Repetition is set to: ' + ans + '\n'

        ans = bnc_talk(sock, 'sour2:coup on')
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Source 2 coupled to source 1: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'sour2:coup?')
        config += 'Source 2 coupled to source 1: ' + \
            ('Yes' if '1' in ans else 'No') + '\n'

        ans = bnc_talk(sock, 'sour2:coup:offset %0.6fe6' % offset)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set source 2 offset: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'sour2:coup:offset?')
        config += 'Offset of source 2 is set to: ' + ans + '\n'

        ans = bnc_talk(sock, 'trigger:type normal')
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set trigger type: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'trigger:source ' + trig_src)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set trigger source: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'trigger:source?')
        config += 'Trigger is set to: ' + ans + '\n'

        ans = bnc_talk(sock, 'trigger:slope ' + trig_slope)
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set trigger slope: ' + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'trigger:slope?')
        config += 'Triggered slope: ' + ans + '\n'

        ans = bnc_talk(sock,
                       'output:blanking ' + ('on' if blanking != 0 else 'off'))
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'RF output blanking ' + \
            ('on: ' if blanking != 0 else 'off: ') + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'output:blanking?')
        config += 'RF output blanking: ' + \
            ('Yes' if '1' in ans else 'No') + '\n'

        ans = bnc_talk(
            sock, 'output:state ' + ('off' if disable_rf != None else 'on'))
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Output ' + ('disabled: ' if disable_rf != None else
                            'enabled: ') + ans + bnc_report(ok) + '\n'

        ans = bnc_talk(sock, 'freq:mode list')
        (ok, all_ok) = bnc_check(ans, all_ok)
        log += 'Set frequencies to list mode: ' + ans + bnc_report(ok)

        ans = bnc_talk(sock, 'freq:mode?')
        config += 'Frequency mode set to: ' + ans

        sock.close()

        self.init_log.putData(log)
        self.init_config.putData(config)

        return 1 if all_ok else 0

    def off(self, arg):
        (sock, remote_ip) = bnc_connect(self.host.data(), self.port.data())

        ans = bnc_talk(sock, 'output:state off')
        (ok, all_ok) = bnc_check(ans, True)

        sock.close()
        return ok
コード例 #5
0
        def GetModelParameterData(ParameterStruct, numOfParameters):

            paramList = []

            for paramIdx in range(numOfParameters):

                # name is retrieved
                retrievedName = WrapperLib.WCAPI_GetModelParameterName(
                    ParameterStruct, paramIdx)
                retrievedName = retrievedName.decode("utf-8")

                # type is retrieved
                retrievedTypeIdx = WrapperLib.WCAPI_GetModelParameterDataTypeIdx(
                    ParameterStruct, paramIdx)
                retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId(
                    DataTypeMap, retrievedTypeIdx)

                retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName(
                    DataTypeMap, retrievedTypeIdx)
                retrievedCTypename = retrievedCTypename.decode("utf-8")

                if retrievedSLIdType == 0:
                    MARTe2Typename = 'float64'
                    pythonTypename = ctypes.c_double
                elif retrievedSLIdType == 1:
                    MARTe2Typename = 'float32'
                    pythonTypename = ctypes.c_float
                elif retrievedSLIdType == 2:
                    MARTe2Typename = 'int8'
                    pythonTypename = ctypes.c_int8
                elif retrievedSLIdType == 3:
                    MARTe2Typename = 'uint8'
                    pythonTypename = ctypes.c_uint8
                elif retrievedSLIdType == 4:
                    MARTe2Typename = 'int16'
                    pythonTypename = ctypes.c_int16
                elif retrievedSLIdType == 5:
                    MARTe2Typename = 'uint16'
                    pythonTypename = ctypes.c_uint16
                elif retrievedSLIdType == 6:
                    MARTe2Typename = 'int32'
                    pythonTypename = ctypes.c_int32
                elif retrievedSLIdType == 7:
                    MARTe2Typename = 'uint32'
                    pythonTypename = ctypes.c_uint32
                elif retrievedSLIdType == 8:
                    MARTe2Typename = 'bool'
                    pythonTypename = ctypes.c_bool
                else:
                    raise Exception('Unsupported parameter datatype.')

                # actual parameter value is retrieved
                paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx(
                    ParameterStruct, paramIdx)
                paramDataAddr = WrapperLib.WCAPI_GetDataAddress(
                    DataAddrMap, paramAddrIdx)
                paramPointer = ctypes.cast(paramDataAddr,
                                           ctypes.POINTER(pythonTypename))

                # dimensions are retrieved
                dimIdx = WrapperLib.WCAPI_GetModelParameterDimensionIdx(
                    ParameterStruct, paramIdx)

                dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex(
                    DimensionMap,
                    dimIdx)  # Starting position in the dimensionArray
                dimNum = WrapperLib.WCAPI_GetNumDims(
                    DimensionMap, dimIdx
                )  # Number of elements in the dimensionArray referring to this signal

                currDimension = []
                for currIdx in range(dimNum):
                    currDimension.append(DimensionArray[dimArrayIdx + currIdx])

                if currDimension[0] == 1 and currDimension[1] == 1:  # scalar
                    dimension = 0
                    mdsplusValue = paramPointer[0]
                elif currDimension[0] == 1:  # vector
                    dimension = currDimension[0] * currDimension[1]
                    valueList = []
                    for idx in range(dimension):
                        valueList.append(paramPointer[idx])
                else:
                    # matrix or column vector (MARTe2 sees column vectors as matrices)
                    dimension = currDimension
                    idx = 0
                    valueList = []
                    valueRow = []
                    for nRow in range(currDimension[0]):
                        for nCol in range(currDimension[1]):
                            valueRow.append(paramPointer[idx])
                            idx = idx + 1
                        valueList.append(valueRow)
                        valueRow = []

                if currDimension[0] != 1 or currDimension[1] != 1:
                    if retrievedSLIdType == 0:
                        mdsplusValue = MDSplus.Float32Array(valueList)
                    elif retrievedSLIdType == 1:
                        mdsplusValue = MDSplus.Float64Array(valueList)
                    elif retrievedSLIdType == 2:
                        mdsplusValue = MDSplus.Int8Array(valueList)
                    elif retrievedSLIdType == 3:
                        mdsplusValue = MDSplus.Uint8Array(valueList)
                    elif retrievedSLIdType == 4:
                        mdsplusValue = MDSplus.Int16Array(valueList)
                    elif retrievedSLIdType == 5:
                        mdsplusValue = MDSplus.Uint16Array(valueList)
                    elif retrievedSLIdType == 6:
                        mdsplusValue = MDSplus.Int32Array(valueList)
                    elif retrievedSLIdType == 7:
                        mdsplusValue = MDSplus.Uint32Array(valueList)
                    else:
                        raise Exception('Unsupported parameter datatype.')

                # retrieved data is saved to a dictionary
                paramDict = dict(name='Parameters.' + retrievedName,
                                 type=MARTe2Typename,
                                 dimensions=dimension,
                                 value=mdsplusValue)

                # dictionary is appended to the MDSplus-style list
                paramList.append(paramDict)

            return paramList
コード例 #6
0
ファイル: MARTE2_SIMULINK.py プロジェクト: KambaVVV/mdsplus
        def GetModelParameterFields(structTypeIdx, ParameterStruct, paramIdx, baseParName, paramList, recLev  ):
            if recLev == 10:
              raise Exception
            
            numFields = WrapperLib.WCAPI_GetDataTypeNumElements(
                DataTypeMap, structTypeIdx)
            elementMapIndex = WrapperLib.WCAPI_GetDataTypeElemMapIndex(
                DataTypeMap, structTypeIdx)
          # actual parameter value is retrieved
            paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx(
                ParameterStruct, paramIdx)
            paramDataAddr = WrapperLib.WCAPI_GetDataAddress(
                DataAddrMap, paramAddrIdx)
            #print('NUM FIELDS: '+str(numFields))
            for fieldIdx in range(numFields):
                fieldName = WrapperLib.WCAPI_GetElementName(
                    ElementMap, elementMapIndex + fieldIdx)
                fieldName = fieldName.decode("utf-8")
                #print('FIELD: '+baseParName+'-'+fieldName)
                fieldOffset = WrapperLib.WCAPI_GetElementOffset(
                    ElementMap, elementMapIndex + fieldIdx)
                  
                fieldTypeIdx = WrapperLib.WCAPI_GetElementDataTypeIdx(
                    ElementMap, elementMapIndex + fieldIdx)
                #print('fieldTypeIdx: '+str(fieldTypeIdx))
                fieldSLIdType = WrapperLib.WCAPI_GetDataTypeSLId(
                    DataTypeMap, fieldTypeIdx)
                #print('fieldSLIdType: '+str(fieldSLIdType))
                if fieldSLIdType == 0:
                    fieldMARTe2Typename = 'float64'
                    fieldPythonTypename = ctypes.c_double
                elif fieldSLIdType == 1:
                    fieldMARTe2Typename = 'float32'
                    fieldPythonTypename = ctypes.c_float
                elif fieldSLIdType == 2:
                    fieldMARTe2Typename = 'int8'
                    fieldPythonTypename = ctypes.c_int8
                elif fieldSLIdType == 3:
                    fieldMARTe2Typename = 'uint8'
                    fieldPythonTypename = ctypes.c_uint8
                elif fieldSLIdType == 4:
                    fieldMARTe2Typename = 'int16'
                    fieldPythonTypename = ctypes.c_int16
                elif fieldSLIdType == 5:
                    fieldMARTe2Typename = 'uint16'
                    fieldPythonTypename = ctypes.c_uint16
                elif fieldSLIdType == 6:
                    fieldMARTe2Typename = 'int32'
                    fieldPythonTypename = ctypes.c_int32
                elif fieldSLIdType == 7:
                    fieldMARTe2Typename = 'uint32'
                    fieldPythonTypename = ctypes.c_uint32
                elif fieldSLIdType == 8:
                    fieldMARTe2Typename = 'uint8'
                    fieldPythonTypename = ctypes.c_int8
                elif fieldSLIdType == 254:
                    fieldEnumType =  WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, fieldTypeIdx)
                    if fieldEnumType == 0:
                        fieldMARTe2Typename = 'float64'
                        fieldPythonTypename = ctypes.c_double
                    elif fieldEnumType == 1:
                        fieldMARTe2Typename = 'float32'
                        fieldPythonTypename = ctypes.c_float
                    elif fieldEnumType == 2:
                        fieldMARTe2Typename = 'int8'
                        fieldPythonTypename = ctypes.c_int8
                    elif fieldEnumType == 3:
                        fieldMARTe2Typename = 'uint8'
                        fieldPythonTypename = ctypes.c_uint8
                    elif fieldEnumType == 4:
                        fieldMARTe2Typename = 'int16'
                        fieldPythonTypename = ctypes.c_int16
                    elif fieldEnumType == 5:
                        fieldMARTe2Typename = 'uint16'
                        fieldPythonTypename = ctypes.c_uint16
                    elif fieldEnumType == 6:
                        fieldMARTe2Typename = 'int32'
                        fieldPythonTypename = ctypes.c_int32
                    elif fieldEnumType == 7:
                        fieldMARTe2Typename = 'uint32'
                        fieldPythonTypename = ctypes.c_uint32
                    else:
                        print('type '+str(fieldEnumType))
                        raise Exception('Unsupported Enum datatype.')
                else: #NESTED STRUCTURES!!!!!!!!!!!!!!!!
                    #print('TYPE '+str(fieldSLIdType) + '   '+str(fieldTypeIdx))
                    GetModelParameterFields(fieldTypeIdx, ParameterStruct, paramIdx, baseParName + '-'+fieldName, paramList, recLev+1)
                    continue #no direct data associated
        # field dimensions
                # dimensions are retrieved
                fieldDimIdx = WrapperLib.WCAPI_GetElementDimensionIdx(
                    ElementMap, elementMapIndex + fieldIdx)

                fieldDimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex(
                    DimensionMap, fieldDimIdx)  # Starting position in the dimensionArray
                # Number of elements in the dimensionArray referring to this signal
                fieldDimNum = WrapperLib.WCAPI_GetNumDims(
                    DimensionMap, fieldDimIdx)
                #print('fieldDimNum: '+ str(fieldDimNum))
                currDimension = []
                for currIdx in range(fieldDimNum):
                    currDimension.append(
                        DimensionArray[fieldDimArrayIdx + currIdx])
                if currDimension[0] == 1 and currDimension[1] == 1:
                    fieldDimension = 0
                elif currDimension[0] == 1 or currDimension[1] == 1:
                    fieldDimension = [
                        currDimension[0]*currDimension[1]]
                else:
                    fieldDimension = currDimension

                currParAddress = paramDataAddr + fieldOffset
                paramPointer = ctypes.cast(
                  currParAddress, ctypes.POINTER(fieldPythonTypename))


                if currDimension[0] == 1 and currDimension[1] == 1:  # scalar
                    dimension = 0
                    mdsplusValue = paramPointer[0]
                elif currDimension[0] == 1:  # vector
                    dimension = currDimension[0]*currDimension[1]
                    valueList = []
                    for idx in range(dimension):
                        valueList.append(paramPointer[idx])
                else:
                    # matrix or column vector (MARTe2 sees column vectors as matrices)
                    dimension = currDimension
                    idx = 0
                    valueList = []
                    valueRow = []
                    for nRow in range(currDimension[0]):
                        for nCol in range(currDimension[1]):
                            valueRow.append(paramPointer[idx])
                            idx = idx + 1
                        valueList.append(valueRow)
                        valueRow = []
                        
                if currDimension[0] != 1 or currDimension[1] != 1:
                    if fieldSLIdType == 0:
                        mdsplusValue = MDSplus.Float32Array(valueList)
                    elif fieldSLIdType == 1:
                        mdsplusValue = MDSplus.Float64Array(valueList)
                    elif fieldSLIdType == 2:
                        mdsplusValue = MDSplus.Int8Array(valueList)
                    elif fieldSLIdType == 3:
                        mdsplusValue = MDSplus.Uint8Array(valueList)
                    elif fieldSLIdType == 4:
                        mdsplusValue = MDSplus.Int16Array(valueList)
                    elif fieldSLIdType == 5:
                        mdsplusValue = MDSplus.Uint16Array(valueList)
                    elif fieldSLIdType == 6:
                        mdsplusValue = MDSplus.Int32Array(valueList)
                    elif fieldSLIdType == 7:
                        mdsplusValue = MDSplus.Uint32Array(valueList)
                    elif fieldSLIdType == 8:
                        mdsplusValue = MDSplus.Uint8Array(valueList)
                    else:
                        raise Exception('Unsupported parameter datatype.')
                      
                paramDict = dict(name=baseParName+'-'+fieldName,
                            type=fieldMARTe2Typename, dimensions=fieldDimension, value=mdsplusValue)
              # dictionary is appended to the MDSplus-style list
                paramList.append(paramDict)
コード例 #7
0
ファイル: MARTE2_SIMULINK.py プロジェクト: KambaVVV/mdsplus
        def GetModelParameterData(ParameterStruct, numOfParameters):

            paramList = []

            for paramIdx in range(numOfParameters):

                # name is retrieved
                retrievedName = WrapperLib.WCAPI_GetModelParameterName(
                    ParameterStruct, paramIdx)
                retrievedName = retrievedName.decode("utf-8")
                #print('retrievedname: ', retrievedName)

                # type is retrieved
                retrievedTypeIdx = WrapperLib.WCAPI_GetModelParameterDataTypeIdx(
                    ParameterStruct, paramIdx)
                #print('retrievedTypeIdx: ', str(retrievedTypeIdx))
                retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId(
                    DataTypeMap, retrievedTypeIdx)
                #print('retrievedSLIdType: ', str(retrievedSLIdType))
                #retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName(
                #    DataTypeMap, retrievedTypeIdx)
                #retrievedCTypename = retrievedCTypename.decode("utf-8")
                #print('retrievedCTypename: '+retrievedCTypename)

                if retrievedSLIdType == 0:
                    MARTe2Typename = 'float64'
                    pythonTypename = ctypes.c_double
                elif retrievedSLIdType == 1:
                    MARTe2Typename = 'float32'
                    pythonTypename = ctypes.c_float
                elif retrievedSLIdType == 2:
                    MARTe2Typename = 'int8'
                    pythonTypename = ctypes.c_int8
                elif retrievedSLIdType == 3:
                    MARTe2Typename = 'uint8'
                    pythonTypename = ctypes.c_uint8
                elif retrievedSLIdType == 4:
                    MARTe2Typename = 'int16'
                    pythonTypename = ctypes.c_int16
                elif retrievedSLIdType == 5:
                    MARTe2Typename = 'uint16'
                    pythonTypename = ctypes.c_uint16
                elif retrievedSLIdType == 6:
                    MARTe2Typename = 'int32'
                    pythonTypename = ctypes.c_int32
                elif retrievedSLIdType == 7:
                    MARTe2Typename = 'uint32'
                    pythonTypename = ctypes.c_uint32
                elif retrievedSLIdType == 8:
                    MARTe2Typename = 'uint8'
                    pythonTypename = ctypes.c_bool
                elif retrievedSLIdType == 254:
                    fieldEnumType =  WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, retrievedTypeIdx)
                    if fieldEnumType == 0:
                        MARTe2Typename = 'float64'
                        pythonTypename = ctypes.c_double
                    elif fieldEnumType == 1:
                        MARTe2Typename = 'float32'
                        pythonTypename = ctypes.c_float
                    elif fieldEnumType == 2:
                        MARTe2Typename = 'int8'
                        pythonTypename = ctypes.c_int8
                    elif fieldEnumType == 3:
                        pythonTypename = ctypes.c_uint8
                        MARTe2Typename = 'uint8'
                    elif fieldEnumType == 4:
                        MARTe2Typename = 'int16'
                        pythonTypename = ctypes.c_int16
                    elif fieldEnumType == 5:
                        pythonTypename = ctypes.c_uint16
                        MARTe2Typename = 'uint16'
                    elif fieldEnumType == 6:
                        pythonTypename = ctypes.c_int32
                        MARTe2Typename = 'int32'
                    elif fieldEnumType == 7:
                        pythonTypename = ctypes.c_uint32
                        MARTe2Typename = 'uint32'
                    else:
                        print('type '+str(fieldEnumType))
                        raise Exception('Unsupported Enum datatype.')
                elif retrievedSLIdType == 255:
                    pass
                else:
                    raise Exception('Unsupported parameter datatype.')
                  
                if retrievedSLIdType != 255:  
                    # actual parameter value is retrieved
                    paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx(
                        ParameterStruct, paramIdx)
                    paramDataAddr = WrapperLib.WCAPI_GetDataAddress(
                        DataAddrMap, paramAddrIdx)
                    paramPointer = ctypes.cast(
                        paramDataAddr, ctypes.POINTER(pythonTypename))

                    # dimensions are retrieved
                    dimIdx = WrapperLib.WCAPI_GetModelParameterDimensionIdx(
                        ParameterStruct, paramIdx)

                    dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex(
                        DimensionMap, dimIdx)  # Starting position in the dimensionArray
                    # Number of elements in the dimensionArray referring to this signal
                    dimNum = WrapperLib.WCAPI_GetNumDims(
                        DimensionMap,       dimIdx)

                    currDimension = []
                    for currIdx in range(dimNum):
                        currDimension.append(DimensionArray[dimArrayIdx + currIdx])

                    if currDimension[0] == 1 and currDimension[1] == 1:  # scalar
                        dimension = 0
                        mdsplusValue = paramPointer[0]
                    elif currDimension[0] == 1:  # vector
                        dimension = currDimension[0]*currDimension[1]
                        valueList = []
                        for idx in range(dimension):
                            valueList.append(paramPointer[idx])
                    else:
                        # matrix or column vector (MARTe2 sees column vectors as matrices)
                        dimension = currDimension
                        idx = 0
                        valueList = []
                        valueRow = []
                        for nRow in range(currDimension[0]):
                            for nCol in range(currDimension[1]):
                                valueRow.append(paramPointer[idx])
                                idx = idx + 1
                            valueList.append(valueRow)
                            valueRow = []

                    if currDimension[0] != 1 or currDimension[1] != 1:
                        if retrievedSLIdType == 0:
                            mdsplusValue = MDSplus.Float32Array(valueList)
                        elif retrievedSLIdType == 1:
                            mdsplusValue = MDSplus.Float64Array(valueList)
                        elif retrievedSLIdType == 2:
                            mdsplusValue = MDSplus.Int8Array(valueList)
                        elif retrievedSLIdType == 3:
                            mdsplusValue = MDSplus.Uint8Array(valueList)
                        elif retrievedSLIdType == 4:
                            mdsplusValue = MDSplus.Int16Array(valueList)
                        elif retrievedSLIdType == 5:
                            mdsplusValue = MDSplus.Uint16Array(valueList)
                        elif retrievedSLIdType == 6:
                            mdsplusValue = MDSplus.Int32Array(valueList)
                        elif retrievedSLIdType == 7:
                            mdsplusValue = MDSplus.Uint32Array(valueList)
                        else:
                            raise Exception('Unsupported parameter datatype.')

                    # retrieved data is saved to a dictionary
                    paramDict = dict(name='Parameters.'+retrievedName,
                                    type=MARTe2Typename, dimensions=dimension, value=mdsplusValue)

                    # dictionary is appended to the MDSplus-style list
                    paramList.append(paramDict)
                else: #retrievedSLIdType == 255  SRUCTURED PARAMETERS
                    GetModelParameterFields(retrievedTypeIdx, ParameterStruct, paramIdx, 'Parameters.'+retrievedName, paramList, 1)  
                  
                    #numFields = WrapperLib.WCAPI_GetDataTypeNumElements(
                        #DataTypeMap, retrievedTypeIdx)
                    #elementMapIndex = WrapperLib.WCAPI_GetDataTypeElemMapIndex(
                        #DataTypeMap, retrievedTypeIdx)
                  ## actual parameter value is retrieved
                    #paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx(
                        #ParameterStruct, paramIdx)
                    #paramDataAddr = WrapperLib.WCAPI_GetDataAddress(
                        #DataAddrMap, paramAddrIdx)
                    #print('NUM FIELDS: '+str(numFields))
                    #for fieldIdx in range(numFields):
                        #fieldName = WrapperLib.WCAPI_GetElementName(
                            #ElementMap, elementMapIndex + fieldIdx)
                        #fieldName = fieldName.decode("utf-8")
                        #print('FIELD: '+fieldName)
                        #fieldOffset = WrapperLib.WCAPI_GetElementOffset(
                            #ElementMap, elementMapIndex + fieldIdx)
                         
                        #fieldTypeIdx = WrapperLib.WCAPI_GetElementDataTypeIdx(
                            #ElementMap, elementMapIndex + fieldIdx)
                        #fieldSLIdType = WrapperLib.WCAPI_GetDataTypeSLId(
                            #DataTypeMap, fieldTypeIdx)
                        #if fieldSLIdType == 0:
                            #fieldMARTe2Typename = 'float64'
                            #fieldPythonTypename = ctypes.c_double
                        #elif fieldSLIdType == 1:
                            #fieldMARTe2Typename = 'float32'
                            #fieldPythonTypename = ctypes.c_float
                        #elif fieldSLIdType == 2:
                            #fieldMARTe2Typename = 'int8'
                            #fieldPythonTypename = ctypes.c_int8
                        #elif fieldSLIdType == 3:
                            #fieldMARTe2Typename = 'uint8'
                            #fieldPythonTypename = ctypes.c_uint8
                        #elif fieldSLIdType == 4:
                            #fieldMARTe2Typename = 'int16'
                            #fieldPythonTypename = ctypes.c_int16
                        #elif fieldSLIdType == 5:
                            #fieldMARTe2Typename = 'uint16'
                            #fieldPythonTypename = ctypes.c_uint16
                        #elif fieldSLIdType == 6:
                            #fieldMARTe2Typename = 'int32'
                            #fieldPythonTypename = ctypes.c_int32
                        #elif fieldSLIdType == 7:
                            #fieldMARTe2Typename = 'uint32'
                            #fieldPythonTypename = ctypes.c_uint32
                        #elif fieldSLIdType == 8:
                            #fieldMARTe2Typename = 'bool'
                            #fieldPythonTypename = ctypes.c_int8
                        #elif fieldSLIdType == 254:
                            #fieldEnumType =  WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, fieldTypeIdx)
                            #if fieldEnumType == 0:
                                #fieldMARTe2Typename = 'float64'
                                #fieldPythonTypename = ctypes.c_double
                            #elif fieldEnumType == 1:
                                #fieldMARTe2Typename = 'float32'
                                #fieldPythonTypename = ctypes.c_float
                            #elif fieldEnumType == 2:
                                #fieldMARTe2Typename = 'int8'
                                #fieldPythonTypename = ctypes.c_int8
                            #elif fieldEnumType == 3:
                                #fieldMARTe2Typename = 'uint8'
                                #fieldPythonTypename = ctypes.c_uint8
                            #elif fieldEnumType == 4:
                                #fieldMARTe2Typename = 'int16'
                                #fieldPythonTypename = ctypes.c_int16
                            #elif fieldEnumType == 5:
                                #fieldMARTe2Typename = 'uint16'
                                #fieldPythonTypename = ctypes.c_uint16
                            #elif fieldEnumType == 6:
                                #fieldMARTe2Typename = 'int32'
                                #fieldPythonTypename = ctypes.c_int32
                            #elif fieldEnumType == 7:
                                #fieldMARTe2Typename = 'uint32'
                                #fieldPythonTypename = ctypes.c_uint32
                            #else:
                                #print('type '+str(fieldEnumType))
                                #raise Exception('Unsupported Enum datatype.')
                        #else:
                            #print('type '+str(fieldSLIdType))
                            #raise Exception('Unsupported nested structures.')
                ## field dimensions
                       ## dimensions are retrieved
                        #fieldDimIdx = WrapperLib.WCAPI_GetElementDimensionIdx(
                            #ElementMap, elementMapIndex + fieldIdx)

                        #fieldDimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex(
                            #DimensionMap, fieldDimIdx)  # Starting position in the dimensionArray
                        ## Number of elements in the dimensionArray referring to this signal
                        #fieldDimNum = WrapperLib.WCAPI_GetNumDims(
                            #DimensionMap, fieldDimIdx)

                        #currDimension = []
                        #for currIdx in range(fieldDimNum):
                            #currDimension.append(
                                #DimensionArray[fieldDimArrayIdx + currIdx])
                        #if currDimension[0] == 1 and currDimension[1] == 1:
                            #fieldDimension = 0
                        #elif currDimension[0] == 1 or currDimension[1] == 1:
                            #fieldDimension = [
                                #currDimension[0]*currDimension[1]]
                        #else:
                            #fieldDimension = currDimension

                        #currParAddress = paramDataAddr + fieldOffset
                        #paramPointer = ctypes.cast(
                          #currParAddress, ctypes.POINTER(fieldPythonTypename))

 
                        #if currDimension[0] == 1 and currDimension[1] == 1:  # scalar
                            #dimension = 0
                            #mdsplusValue = paramPointer[0]
                        #elif currDimension[0] == 1:  # vector
                            #dimension = currDimension[0]*currDimension[1]
                            #valueList = []
                            #for idx in range(dimension):
                                #valueList.append(paramPointer[idx])
                        #else:
                            ## matrix or column vector (MARTe2 sees column vectors as matrices)
                            #dimension = currDimension
                            #idx = 0
                            #valueList = []
                            #valueRow = []
                            #for nRow in range(currDimension[0]):
                                #for nCol in range(currDimension[1]):
                                    #valueRow.append(paramPointer[idx])
                                    #idx = idx + 1
                                #valueList.append(valueRow)
                                #valueRow = []
                                
                        #if currDimension[0] != 1 or currDimension[1] != 1:
                            #if fieldSLIdType == 0:
                                #mdsplusValue = MDSplus.Float32Array(valueList)
                            #elif fieldSLIdType == 1:
                                #mdsplusValue = MDSplus.Float64Array(valueList)
                            #elif fieldSLIdType == 2:
                                #mdsplusValue = MDSplus.Int8Array(valueList)
                            #elif fieldSLIdType == 3:
                                #mdsplusValue = MDSplus.Uint8Array(valueList)
                            #elif fieldSLIdType == 4:
                                #mdsplusValue = MDSplus.Int16Array(valueList)
                            #elif fieldSLIdType == 5:
                                #mdsplusValue = MDSplus.Uint16Array(valueList)
                            #elif fieldSLIdType == 6:
                                #mdsplusValue = MDSplus.Int32Array(valueList)
                            #elif fieldSLIdType == 7:
                                #mdsplusValue = MDSplus.Uint32Array(valueList)
                            #else:
                                #raise Exception('Unsupported parameter datatype.')
                              
                        #paramDict = dict(name='Parameters.'+retrievedName+'-'+fieldName,
                                    #type=fieldMARTe2Typename, dimensions=fieldDimension, value=mdsplusValue)
                     ## dictionary is appended to the MDSplus-style list
                        #paramList.append(paramDict)
                 #endif STRUCTURED PARAMETER
            #endfor parameters
            #print('PARAMETRI FATTI')
            return paramList