예제 #1
0
def showerr(errdata):
    global errmap
    global datamapaaa
    global idinta
    if (datamapaaa != -1):
        if (errmap != -1):
            if (idinta != -1):
                fastmmap.writesharedstring(
                    datamapaaa,
                    fastmmap.getsharedstring(datamapaaa) + ",stopaq:")
                fastmmap.writesharedstring(datamaperrfinalb, ",stopaq:")
                fastmmap.write(errmap, "-" + errdata + "_")
예제 #2
0
def pushvalgui(xstring, ystring):
    global globalfreq
    global globaltemp
    global globalstat
    global errmap
    global datamapaaa
    global datamapaaab
    global idinta
    if (datamapaaa != -1):
        if (errmap != -1):
            if (idinta != -1):
                if (len(xstring.split(" ")) == len(ystring.split(" "))):
                    fastmmap.writesharedstring(
                        datamapaaab, ";buffer:" + str(xstring) + "?" +
                        str(ystring) + "final")
                else:
                    #print xstring
                    #print ystring
                    print "pushval(xstring,ystring) error,\n\txstring.split(" ") and ystring.split(" ") must have the same length."
                fastmmap.writesharedstring(
                    datamapaaa,
                    ";frequency:" + str(globalfreq) + ",deviceinfo:" +
                    str(globaltemp) + "--int-info-seperator--     " +
                    str(globalstat) + " Dropped spectra: " + str(dropspec))
예제 #3
0
def sendcalibrationdata():
	fastmmap.writesharedstring(fastmmapmqid,str(imoncalibration.getxaxiscalibrateddata()))
예제 #4
0
파일: tests.py 프로젝트: luisvmf/FastMmapMQ
import fastmmap
#help(fastmmap)
mapa = fastmmap.createmmap("testshm", "rwx------")
mapb = fastmmap.connectmmap("python", "testshm")
while (True):
    a = fastmmap.write(mapa, "test 1")
    if (a == 0):
        break
print fastmmap.read(mapb, 0)
fastmmap.write(mapb, "test 2")
fastmmap.write(mapa, "test 3")
print fastmmap.read(mapb, 0)
fastmmap.write(mapa, "test 3")
print fastmmap.read(mapb, 1)
fastmmap.write(mapa, "test 3")
print fastmmap.read(mapb, 0)
print fastmmap.getsharedstring(mapa)
print fastmmap.getsharedstring(mapb)
fastmmap.writesharedstring(mapb, "Test")
print fastmmap.getsharedstring(mapa)
print fastmmap.getsharedstring(mapb)
예제 #5
0
def multiprocessingmainworker(instid):
    from imonpreferences import *
    import imonio
    mmapb = fastmmap.connectmmap("spectrareadd", "imonv6b" + instid)
    while (mmapb == -1):
        mmapb = fastmmap.connectmmap("spectrareadd", "imonv6b" + instid)
        time.sleep(0.1)
    aquisitionstatus = 0  #0 if aquisition is not running.
    #1 if aquisition is running.
    nspectra = 0  #Number of spectra measured in current aquisition.
    commanddata = ["False", "False", "False", "False", "False", "False"]
    timelastup = 0
    initialized = 0
    lastcommanddata = ["null", "null", "null", "null", "null", "null"]
    checkaborttime = 0
    timelastabort = 0
    while (True):
        if (initialized == 0):
            if (imonio.isopen() == True):
                imonio.escapeaquisition()
                time.sleep(0.1)
                print "escok"
                imonio.initdecodingmmap(instid)
                print "initok"
                imonio.sendcalibrationdata()
                print "sendok"
                initialized = 1
        if (imonio.isopen() == True):
            try:
                if (abs(time.time() - timelastup) > 0.1):
                    commanddata = fastmmap.getsharedstring(mmapb).split("-")
                    timelastup = time.time()
                if (commanddata[1] == "True"):
                    if (aquisitionstatus == 0):
                        try:
                            if (initialized == 0):
                                if (imonio.isopen() == True):
                                    imonio.escapeaquisition()
                                    time.sleep(0.1)
                                    print "escok"
                                    imonio.initdecodingmmap(instid)
                                    print "initok"
                                    imonio.sendcalibrationdata()
                                    print "sendok"
                                    initialized = 1
                            imonio.sendcalibrationdata()
                            tint = int(float(commanddata[3]))
                            if (tint < 3):
                                tint = 3
                            if (tint > 9854):
                                tint = 3
                            freq = int(float(commanddata[2]))
                            realfreq = 100
                            if (freq == 1):
                                realfreq = 30
                            if (freq == 2):
                                realfreq = 100
                            if (freq == 3):
                                realfreq = 500
                            if (freq == 4):
                                realfreq = 1000
                            if (freq == 5):
                                realfreq = 2000
                            if (freq == 6):
                                realfreq = 3000
                            if (freq == 7):
                                realfreq = 4000
                            if (freq == 8):
                                realfreq = 5000
                            if (freq == 9):
                                realfreq = 5999
                            null = imonio.checkchangedcommanddata(
                                commanddata, lastcommanddata)
                            nspectraonerun = realfreq * timespectraonerun
                            imonio.requestaquisition(realfreq, tint,
                                                     nspectraonerun)
                            aquisitionstatus = 1
                        except Exception as e:
                            print e
                            null = None
                        nspectra = 0
                    else:
                        countinit = nspectra
                        while (nspectra < nspectraonerun):
                            if (nspectra < dropspectraafterrestart):
                                imonio.readonespectra(1)
                                print "drop restart"
                            else:
                                imonio.readonespectra(0)
                                imonio.forcesenddata()
                            nspectra = nspectra + 1
                            if (abs((float(nspectra * timespectraonerun) /
                                     float(nspectraonerun)) - checkaborttime) >
                                    checkchangedparamabortinterval):
                                checkaborttime = (
                                    float(nspectra * timespectraonerun) /
                                    float(nspectraonerun))
                                commanddata = fastmmap.getsharedstring(
                                    mmapb).split("-")
                                if (imonio.checkchangedcommanddata(
                                        commanddata, lastcommanddata)):
                                    if (abs(timelastabort - time.time()) >
                                            abortmininterval):
                                        print "escape"
                                        imonio.escapeaquisition()
                                        nspectra = nspectraonerun
                                        imonio.forcesenddata()
                                        timelastabort = time.time()
                            if (nspectra - countinit > 500):
                                break
                        if (nspectra >= nspectraonerun):
                            aquisitionstatus = 0
                else:
                    if (aquisitionstatus == 1):
                        #------------------------
                        imonio.escapeaquisition()
                        aquisitionstatus = 0
                    #-------------------------
                    else:
                        commanddata = fastmmap.getsharedstring(mmapb).split(
                            "-")
                        fastmmap.writesharedstring(
                            mmapb,
                            str(commanddata[0]) + "-" + str(commanddata[1]) +
                            "-" + str(commanddata[2]) + "-" +
                            str(commanddata[3]) + "-" + str(commanddata[4]) +
                            "-False")
                        if (commanddata[5] == "True"):
                            print "Driver measure single"
                            time.sleep(0.07)
                            imonio.sendcalibrationdata()
                            time.sleep(0.07)
                            nspectraonerun = 50
                            tint = int(float(commanddata[3]))
                            if (tint < 3):
                                tint = 3
                            if (tint > 9854):
                                tint = 3
                            imonio.requestaquisition(100, tint, 50)
                            nspectra = 0
                            countinit = nspectra
                            while (nspectra < nspectraonerun):
                                imonio.readonespectra(0)
                                imonio.forcesenddata()
                                nspectra = nspectra + 1
                                if (nspectra - countinit > 500):
                                    break
                            imonio.forcesenddata()
                        else:
                            time.sleep(0.1)
            except Exception as e:
                print e
        else:
            commanddata = fastmmap.getsharedstring(mmapb).split("-")
            #print commanddata
            if (len(commanddata) < 5):
                commanddata = [
                    "False", "False", "False", "False", "False", "False"
                ]
            if (commanddata[1] == "True"):
                print "not open"
                fastmmap.write(mmapb, "e")
            if (commanddata[5] == "True"):
                print "not open"
                fastmmap.write(mmapb, "e")
                fastmmap.writesharedstring(
                    mmapb,
                    str(commanddata[0]) + "-" + str(commanddata[1]) + "-" +
                    str(commanddata[2]) + "-" + str(commanddata[3]) + "-" +
                    str(commanddata[4]) + "-False")
            time.sleep(0.1)
예제 #6
0
def mainloop(meas, single, par):
    global multiproccessingpool
    global mmapb
    global mmapc
    global mmapd
    global queue
    global timelastcal
    global strxdata
    global lastsingle
    global connectedfinal
    global instid
    global mmaperror
    global errorcurrent
    if (single == True):
        errorcurrent = 0
    if (len(fastmmap.read(mmapb, 0).split("e")) > 1):
        if (errorcurrent == 0):
            print "detected error"
            seterr("Error. Port not open.")
            fastmmap.writesharedstring(
                mmapb, "no-" + str(False) + "-" + str(par[0]) + "-" +
                str(par[1]) + "-" + str(par[2]) + "-" + str(single))
            errorcurrent = time.time()
            return pushval()
        else:
            if (abs(time.time() - errorcurrent) > 5):
                errorcurrent = 0
            return False
    if (connectedfinal == 0):
        fastmmap.writesharedstring(
            mmapb, "no-" + str(meas) + "-" + str(par[0]) + "-" + str(par[1]) +
            "-" + str(par[2]) + "-" + str(single))
        if (mmapc == -1):
            mmapc = fastmmap.connectmmap("spectrareadd", "imdec" + instid)
            time.sleep(0.1)
        if (mmapc == -1):
            return False
        if (mmapd == -1):
            mmapd = fastmmap.connectmmap("spectrareadd", "funcwave" + instid)
            time.sleep(0.1)
        if (mmapd == -1):
            return False
        connectedfinal = 1
    if (abs(time.time() - timelastcal) > 0.1):
        fastmmap.writesharedstring(
            mmapb, "no-" + str(meas) + "-" + str(par[0]) + "-" + str(par[1]) +
            "-" + str(par[2]) + "-" + str(single))
        dataarr = [[0], "---"]
        while (dataarr == [[0], "---"]):
            try:
                dataarr = eval(fastmmap.getsharedstring(mmapd))
            except:
                null = None
        if (len(dataarr[0]) > 100):
            strxdata = ' '.join(str(x) for x in dataarr[0])
            v = strxdata
            while (v[0] == " "):
                v = v[1:]
            datvect = v.split(" ")
            datastr = ""
            i = 0
            #print datvect
            while (i < npix):
                if (i > 1):
                    datastr = datastr + " " + datvect[i]
                i = i + 1
            while (datastr[0] == " "):
                datastr = datastr[1:]
            strxdata = datastr
        setinfo(u"CCD temperature: " + str(dataarr[1]) + u" \u00B0C")
        timelastcal = time.time()
    if (single == True):
        if (meas == False):
            fastmmap.writesharedstring(
                mmapb, "no-" + str(meas) + "-" + str(par[0]) + "-" +
                str(par[1]) + "-" + str(par[2]) + "-" + str(single))
            setxdata(strxdata)
            a = ""
            while (len(a) < 25):
                a = fastmmap.read(mmapc, 0)
                time.sleep(0.1)
            a = a.split("?")
            i = 0
            for v in a:
                try:
                    if (i < 5):
                        while (v[0] == " "):
                            v = v[1:]
                        datvect = v.split(" ")
                        datastr = ""
                        i = 0
                        #print datvect
                        while (i < npix):
                            if (i > 1):
                                datastr = datastr + " " + datvect[i]
                            i = i + 1
                        while (datastr[0] == " "):
                            datastr = datastr[1:]
                        setydata(datastr)
                    i = i + 1
                except:
                    null = None
            return pushval()
    if (meas == True) or (single == True):
        setxdata(strxdata)
        a = fastmmap.read(mmapc, 0)
        #print a[len(a)-2]
        #del a[len(a)-1]
        while (len(a) < 10) and (len(queue) < 1):
            time.sleep(0.02)
            a = a + fastmmap.read(mmapc, 0)
        a = a.split("?")
        for v in a:
            try:
                while (v[0] == " "):
                    v = v[1:]
                datvect = v.split(" ")
                datastr = ""
                i = 0
                while (i < npix):
                    if (i > 1):
                        datastr = datastr + " " + datvect[i]
                    i = i + 1
                while (datastr[0] == " "):
                    datastr = datastr[1:]
                queue.append(datastr)
            except Exception as e:
                null = None
                #print e
        try:
            setydata(queue[0])
            del (queue[0])
        except:
            return False
        return pushval()
    else:
        time.sleep(0.3)
        return False