Exemple #1
0
    def onclick(self,event):
        try:
            if event.button==1: #left click
                pass
            if event.button==2: #middle click
                msg = mq.Message({'id': MSG_ID_MOUSE_M_CLICK, 'event':event, 'shift':self.keyShift, 'yscale':self.yscale})
                if self.keyShift:# if shift is held, turn off threshold2
                    self.otherlines[2].set_visible(False)
                else:
                    self.hline2 = event.ydata
                    self.otherlines[2].set_visible(True) # starts off being hidden, so now show it!
                    self.otherlines[2].set_data( [self.min_x, self.max_x], [self.hline2, self.hline2] )
            if event.button==3: #right click

                msg = mq.Message({'id': MSG_ID_MOUSE_R_CLICK, 'event':event, 'xscaling':self.xscaling, 'yscale':self.yscale})
                self.mq_publisher.publish(msg)

                self.vline = event.xdata
                self.otherlines[0].set_visible(True)
                self.otherlines[0].set_data( [self.vline, self.vline], [self.min_y, self.max_y] ) # vertical line showing trigger time
                self.hline = event.ydata
                self.otherlines[1].set_data( [self.min_x, self.max_x], [self.hline, self.hline] ) # horizontal line showing trigger threshold
            print(('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % ('double' if event.dblclick else 'single', event.button, event.x, event.y, event.xdata, event.ydata)))
            return
        except TypeError: pass
Exemple #2
0
    def pickline(self,theline):
        # on the pick event, find the orig line corresponding to the
        # legend proxy line, and toggle the visibility
        origline,legline,channum = self.lined[theline]
        if self.db: print(("picked",theline,"for channum",channum))
        if hasattr(self,'selectedlegline'):
            if self.selectedorigline.get_visible(): self.selectedlegline.set_linewidth(2.0)
            else: self.selectedlegline.set_linewidth(1.0)
        legline.set_linewidth(4.0)
        self.selectedlegline=legline; self.selectedorigline=origline # remember them so we can set it back to normal later when we pick something else
        if channum < HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD: # it's an ADC channel (not a max10adc channel or other thing)
            if self.db: print("picked a real ADC channel")
            msg = mq.Message({'id': MSG_ID_SELECT_CHANNEL, 'selectedchannel': channum})
            self.mq_publisher.publish(msg)
            if self.keyShift:
                msg = mq.Message({'id': MSG_ID_SELECT_TRIGGER_CHANNEL, 'triggerchannel': channum})
                self.mq_publisher.publish(msg)

        else:
            if self.db: print("picked a max10 ADC channel")
            self.selectedmax10channel=channum - HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD
Exemple #3
0
import message_queue
import pika

if __name__ == '__main__':

    adapter = message_queue.AMQPAdapter(host='127.0.0.1')
    # Configurate queue
    adapter.configurate_queue(queue='python.publish.test')
    # Instantiate publisher
    publisher = message_queue.Publisher(adapter)

    # Create a new message
    message = message_queue.Message({
        'id':
        12345,
        'message':
        'welcome to integration system class'
    })

    # Publish message
    publisher.publish(message)
Exemple #4
0
        self.hi_there = Button(frame, text="Hello", command=self.say_hi)
        self.hi_there.pack(side=LEFT)

    def say_hi(self):
        print("hi there, everyone!")


adapter1 = mq.Adapter('queue1')
adapter2 = mq.Adapter('queue1')

subscriber = mq.Subscriber(adapter1)

publisher = mq.Publisher(adapter2)

message_to_send = mq.Message({'id': 12345, 'message': 'test publish'})

publisher.publish(message_to_send)
message_content = subscriber.consume().get_content_body()
print("message id:", message_content['id'])
message = subscriber.consume()
if (message):
    message_content = message.get_content_body()
    print("message id:", message_content['id'])

publisher.publish(message_to_send)
message = subscriber.consume()
if (message):
    message_content = message.get_content_body()
    print("message id:", message_content['id'])
import message_queue
import pika

if __name__ == '__main__':
    # Instantiate the AMQP adapter with the host configuration
    adapter = message_queue.AMQPAdapter(host='127.0.0.1')

    # Configurate queue
    adapter.configurate_queue(queue='python.publish.test')

    # Instantiate publisher
    publisher = message_queue.Publisher(adapter)

    # Publish message
    for i in xrange(10000):
        message = message_queue.Message({'id': i, 'message': 'test publish'})

        publisher.publish(message)
Exemple #6
0
 def adjustvertical(self, direction):
     msg = mq.Message({'id': MSG_ID_ADJUST, 'direction':int(direction), 'shift': self.keyShift, 'control':self.keyControl})
     self.mq_publisher.publish(msg)
Exemple #7
0
 def telldownsample(self, direction):
     msg = mq.Message({'id': MSG_ID_DOWNSAMPLE, 'direction':direction, 'shift': self.keyShift})
     self.mq_publisher.publish(msg)
Exemple #8
0
 def toggleautorearm(self):
     msg = mq.Message({'id': MSG_ID_TOGGLE_AUTO_REARM})
     self.mq_publisher.publish(msg)
Exemple #9
0
 def toggleuseexttrig(self):
     msg = mq.Message({'id': MSG_ID_TOGGLE_EXT_TRIG})
     self.mq_publisher.publish(msg)
Exemple #10
0
    def oversamp(self):
        #tell it to toggle oversampling for this channel

        msg = mq.Message({'id': MSG_ID_OVERSAMPLE})
        self.mq_publisher.publish(msg)
Exemple #11
0
    def __init__(self, parent, controller, hos):
        tk.Frame.__init__(self,parent)
        self.hos = hos
        self.mq_adapter = mq.Adapter('main_queue')
        self.mq_publisher = mq.Publisher(self.mq_adapter)
        self.ydatarefchan=-1 #the reference channel for each board, whose ydata will be subtracted from other channels' ydata on the board
        self.dologicanalyzer = False
        self.sincresample=0 # amount of resampling to do (sinx/x)
        self.domaindrawing=True
        self.domeasure=True
        self.xdata=np.arange(HAAS_NUM_SAMPLES)
        self.xydata=np.empty([HAAS_NUM_CHAN_PER_BOARD*HAAS_NUM_BOARD,2,HAAS_NUM_SAMPLES-1],dtype=float)
        self.Vrms=np.zeros(HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD, dtype=float) # the Vrms for each channel
        self.Vmean=np.zeros(HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD, dtype=float) # the Vmean for each channel
        self.gain=np.ones(HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD, dtype=int) # 1 is low gain, 0 is high gain (x10)
        self.supergain=np.ones(HAAS_NUM_BOARD*HAAS_NUM_CHAN_PER_BOARD, dtype=int) # 1 is normal gain, 0 is super gain (x100)
        self.xdata2=np.arange(HAAS_NUM_SAMPLES*2) # for oversampling
        self.xdata4=np.arange(HAAS_NUM_SAMPLES*4) # for over-oversampling


        # >>>>>>>>>>>>>>>>>>>>>>>>>
        self.yscale = 7.5 # Vpp for full scale
        # if self.minfirmwareversion>=15: #v9.0 boards
        #     self.yscale*=1.1 # if we used 10M / 1.1M / 11k input resistors
        self.min_y = -self.yscale/2. #-4.0 #0 ADC
        self.max_y = self.yscale/2. #4.0 #256 ADC

        self.chtext = "Ch." #the text in the legend for each channel
        self.lines = []
        self.fitline1 = -1 # set to >-1 to draw a risetime fit
        self.logicline1 = -1 # to remember which is the first logic analyzer line
        self.otherlines = []
        self.texts = []
        # self.xydataslow=np.empty([len(HAAS_MAX10ADCCHANS),2,HAAS_NSAMP],dtype=float)
        # if self.domaindrawing: self.on_launch_draw()

        # >>>>>>>>>>>>>>>>>>>>>>>>>
        self.grid(row=1, column=0, columnspan=4, sticky="nsew")
        self.db = True
        ###Matplotlib

        self.fig = Figure(figsize=(5, 5), dpi=100)
        self.ax = self.fig.add_subplot(111)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2*pi*t)

        self.ax.plot(t, s)

        fr = tk.Frame(self)
        fr.grid(row=0, column=0,  rowspan=7, sticky='nsew')
        self.grid_rowconfigure(0, weight=1)
        self.grid_rowconfigure(1, weight=3)
        self.grid_rowconfigure(2, weight=1)
        self.grid_rowconfigure(3, weight=1)
        self.grid_rowconfigure(4, weight=1)
        self.grid_rowconfigure(5, weight=1)
        self.grid_rowconfigure(6, weight=1)

        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)
        self.grid_columnconfigure(2, weight=1)


        self.canvas = FigureCanvasTkAgg(self.fig, master=fr)
        self.canvas.draw()
        self.canvas.get_tk_widget().pack()

        toolbar = NavigationToolbar2Tk(self.canvas, fr)
        toolbar.update()
        self.canvas._tkcanvas.pack()

        textbox_width = tk.Label(self, text="Width, mm:")
        textbox_width.grid(row=0, column=1, columnspan=2, sticky='nsew')
        # textbox_width.insert('end', "Width, mm:")

        self.width_text = StringVar()
        self.width_text.set('--.-')

        # measured_width = tk.Label(self, text="--.-", bg='lavender', font=("Helvetica", 20))
        measured_width = tk.Label(self, textvariable=self.width_text, bg='lavender', font=("Helvetica", 20))
        measured_width.grid(row=1, column=1, columnspan=2, padx=5, pady=5, sticky='nsew')
        # measured_width.insert('end', "10.0")

        textbox_ps_on_off = tk.Label(self, text="PS:")
        textbox_ps_on_off.grid(row=2, column=1, rowspan=2, sticky='nsew')
        # textbox_ps_on_off.insert('end', "PS:")

        button_ps_on = tk.Button(self, text="ON",
                            command=lambda: controller.on_key_press())
        button_ps_on.grid(row=2, column=2, padx=5, pady=5, sticky='nsew')

        button_ps_off = tk.Button(self, text="OFF",
                            command=lambda: controller.on_key_press())
        button_ps_off.grid(row=3, column=2, padx=5, pady=5, sticky='nsew')

        textbox_hv_on_off = tk.Label(self, text="HV:")
        textbox_hv_on_off.grid(row=4, column=1, rowspan=2, sticky='nsew')
        # textbox_hv_on_off.insert('end', "HV:")

        button_hv_on = tk.Button(self, text="ON",
                            command=lambda: self.mq_publisher.publish(mq.Message({'id': MSG_ID_HV_ON})))

        button_hv_on.grid(row=4, column=2, padx=5, pady=5, sticky='nsew')

        button_hv_off = tk.Button(self, text="OFF",
                            command=lambda: self.mq_publisher.publish(mq.Message({'id': MSG_ID_HV_OFF})))
        button_hv_off.grid(row=5, column=2, padx=5, pady=5,  sticky='nsew')

        button_pulse = tk.Button(self, text="PULSE",
                            command=lambda: self.mq_publisher.publish(mq.Message({'id': MSG_ID_PULSE_ON})))
        button_pulse.grid(row=6, column=1, columnspan=2, padx=5, pady=5, sticky='nsew')


        ###Lab
        textbox1 = tk.Entry(self)
        textbox1.grid(row=7, column=0, columnspan=3, sticky='nsew')
        textbox1.insert('end', "Hello Emat!")
Exemple #12
0
 def onpress(self,event): # a key was pressed
         if self.keyResample:
             try:
                 self.sincresample=int(event.key)
                 print(("resample now",self.sincresample))
                 if self.sincresample>0: self.xydata=np.empty([num_chan_per_board*HAAS_NUM_BOARD,2,self.sincresample*(HAAS_NUM_SAMPLES-1)],dtype=float)
                 else: self.xydata=np.empty([num_chan_per_board*HAAS_NUM_BOARD,2,1*(HAAS_NUM_SAMPLES-1)],dtype=float)
                 self.prepareforsamplechange();
                 self.keyResample=False; return
             except ValueError: pass
         elif self.keysettriggertime:
             if event.key=="enter":
                 self.settriggertime(self.triggertimethresh)
                 self.keysettriggertime=False; return
             else:
                 self.triggertimethresh=10*self.triggertimethresh+int(event.key)
                 print(("triggertimethresh",self.triggertimethresh)); return
         elif self.keySPI:
             if event.key=="enter":
                 self.tellSPIsetup(self.SPIval)
                 self.keySPI=False; return
             else:
                 self.SPIval=10*self.SPIval+int(event.key)
                 print(("SPIval",self.SPIval)); return
         elif self.keyi2c:
             if event.key=="enter":
                 self.sendi2c(self.i2ctemp)
                 self.keyi2c=False; return
             else:
                 self.i2ctemp=self.i2ctemp+event.key
                 print(("i2ctemp",self.i2ctemp)); return
         elif self.keyLevel:
             if event.key=="enter":
                 self.keyLevel=False
                 s=self.leveltemp.split(",")
                 #print "Got",int(s[0]),int(s[1])
                 self.selectedchannel=int(s[0])
                 self.chanlevel[self.selectedchannel] = int(s[1])
                 self.rememberdacvalue()
                 self.setdacvalue()
                 return
             else:
                 self.leveltemp=self.leveltemp+event.key
                 print(("leveltemp",self.leveltemp)); return
         elif event.key=="r": self.mq_publisher.publish(mq.Message({'id': MSG_ID_TOGGLE_ROLL_TRIG})); return
         elif event.key=="p": self.paused = not self.paused;print(("paused",self.paused)); return
         elif event.key=="P": self.getone = not self.getone;print(("get one",self.getone)); return
         elif event.key=="a": self.average = not self.average;print(("average",self.average)); return
         elif event.key=="h": self.togglehighres(); return
         elif event.key=="e": self.toggleuseexttrig(); return
         elif event.key=="A": self.toggleautorearm(); return
         elif event.key=="U": self.toggledousb(); return
         elif event.key=="O": self.oversamp(); return # self.prepareforsamplechange(); return
         elif event.key=="ctrl+o": self.overoversamp(); self.prepareforsamplechange(); return
         elif event.key==">": self.refsinchan=self.selectedchannel; self.oldchanphase=-1.; self.reffreq=0;
         elif event.key=="t": self.fallingedge=not self.fallingedge;self.settriggertype(self.fallingedge);print(("trigger falling edge toggled to",self.fallingedge)); return
         elif event.key=="g": self.dogrid=not self.dogrid;print(("dogrid toggled",self.dogrid)); self.ax.grid(self.dogrid); return
         elif event.key=="ctrl+g": self.ax.xaxis.set_major_locator(plt.MultipleLocator( (self.max_x*1000/1024-self.min_x*1000/1024)/8./5. )); return
         elif event.key=="G": self.ax.yaxis.set_major_locator(plt.MultipleLocator(0.2)); return
         elif event.key=="x": self.tellswitchgain(self.selectedchannel)
         elif event.key=="ctrl+x":
             for chan in range(num_chan_per_board*HAAS_NUM_BOARD): self.tellswitchgain(chan)
         elif event.key=="X": self.togglesupergainchan(self.selectedchannel)
         elif event.key=="ctrl+X":
             for chan in range(num_chan_per_board*HAAS_NUM_BOARD): self.selectedchannel=chan; self.togglesupergainchan(chan)
         elif event.key=="F": self.fftchan=self.selectedchannel; self.dofft=True; self.keyShift=False; return
         elif event.key=="/": self.setacdc();return
         elif event.key=="I": self.testi2c(); return
         elif event.key=="c": self.readcalib(); return
         elif event.key=="C": self.storecalib(); return
         elif event.key=="D": self.decode(); return
         elif event.key=="ctrl+r":
             if self.ydatarefchan<0: self.ydatarefchan=self.selectedchannel
             else: self.ydatarefchan=-1
         elif event.key=="|": print("starting autocalibration");self.autocalibchannel=0;
         elif event.key=="W": self.domaindrawing=not self.domaindrawing; self.domeasure=self.domaindrawing; print(("domaindrawing now",self.domaindrawing)); return
         elif event.key=="M": self.domeasure=not self.domeasure; print(("domeasure now",self.domeasure)); self.drawtext(); return
         elif event.key=="m": self.domarkers(); return
         elif event.key=="Y":
             if self.selectedchannel+1>=len(self.dooversample): print("can't do XY plot on last channel")
             else:
                 if self.dooversample[self.selectedchannel]==self.dooversample[self.selectedchannel+1]:
                     self.doxyplot=True; self.xychan=self.selectedchannel; print(("doxyplot now",self.doxyplot,"for channel",self.xychan)); return;
                 else: print("oversampling settings must match between channels for XY plotting")
             self.keyShift=False
         elif event.key=="Z": self.recorddata=True; self.recorddatachan=self.selectedchannel; self.recordedchannel=[]; print(("recorddata now",self.recorddata,"for channel",self.recorddatachan)); self.keyShift=False; return;
         elif event.key=="right": self.telldownsample(DIR_RIGHT); return
         elif event.key=="left": self.telldownsample(DIR_LEFT); return
         elif event.key=="shift+right": self.telldownsample(DIR_RIGHT); return
         elif event.key=="shift+left": self.telldownsample(DIR_LEFT); return
         elif event.key=="up": self.adjustvertical(DIR_UP); return
         elif event.key=="down": self.adjustvertical(DIR_DOWN); return
         elif event.key=="shift+up": self.adjustvertical(DIR_UP); return
         elif event.key=="shift+down": self.adjustvertical(DIR_DOWN); return
         elif event.key=="ctrl+up": self.adjustvertical(DIR_UP); return
         elif event.key=="ctrl+down": self.adjustvertical(DIR_DOWN); return
         elif event.key=="?": self.togglelogicanalyzer(); return
         elif event.key=="d": self.tellminidisplaychan(self.selectedchannel);return
         elif event.key=="R": self.keyResample=True;print("now enter amount to sinc resample (0-9)");return
         elif event.key=="T": self.keysettriggertime=True;self.triggertimethresh=0;print("now enter time over/under thresh, then enter");return
         elif event.key=="S": self.keySPI=True;self.SPIval=0;print("now enter SPI code, then enter");return
         elif event.key=="i": self.keyi2c=True;self.i2ctemp="";print("now enter byte in hex for i2c, then enter:");return
         elif event.key=="L": self.keyLevel=True;self.leveltemp="";print("now enter [channel to set level for, level] then enter:");return
         elif event.key=="shift": self.keyShift=True;return
         elif event.key=="alt": self.keyAlt=True;return
         elif event.key=="control": self.keyControl=True;return
         elif event.key=="tab":
             for l in self.lines:
                 self.togglechannel(l)
             self.figure.canvas.draw()
             return;
         try:
             print(('key=%s' % (event.key)))
             print(('x=%d, y=%d, xdata=%f, ydata=%f' % (event.x, event.y, event.xdata, event.ydata)))
         except TypeError: pass