Hi All

I was playing with the tutorial 3 to obtain the graphs.

https://raw.githubusercontent.com/casper-astro/tutorials_devel/master/tut3/tut3.py

By deduction I added on the arte_3.py script, the acc_num software
register, that is inside the design I am using. I'm doing this to obtain
the graphs from the IBOB-spectrometer with python.

I have still doubts about this part, I dont know if this code It is
properly programmed :

d = s.recvfrom(4096)

datatupple=struct.unpack('<l', d)

What do you think about the arte_3.py script?

Best Regards

Rolando Paz
#!/usr/bin/env python
"""
Primera prueba de graficar los datos de la IBOB, configurada
como un espectrometro de 1024 canales y 200Mhz de ancho de banda
16/05/2015
Rolando Paz 
"""

import numpy as np
import math, struct, socket, sys, pylab   
import matplotlib.pyplot as plt

# IP_IBOB  = 169.254.128.32
# IP_MY_PC = 169.254.128.10

HOST = '169.254.128.32'
PORT = 6969
print '\nConnecting to iBOB...',

# Datagram (udp) socket
try :
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    print 'Socket created'
except socket.error, msg :
    print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' 
+ msg[1]
    sys.exit()

# Connect socket to remote host and port
try:
    s.connect((HOST, PORT))
except socket.error , msg:
    print 'Connect failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()
    
print 'Socket connect complete'
 
# Now receive data from IBOB
d = s.recvfrom(4096)  # buffer size is 1045 bytes

print d

def get_data():
    #get the data...    
    acc_num = s.send("regread acc_num\n")
    #time.sleep(.1)
    datatupple=struct.unpack('<l', d) # unpack as individual signed 32 bit 
quanta
    
    modo=[]

    for i in range(1024):
        modo.append(datatupple[i])
    return acc_num, modo

print 'Data Obtained...'

def plot_spectrum():
    plt.clf()
    acc_num, modo = get_data()

    matplotlib.pylab.plot(modo)
    #matplotlib.pylab.semilogy(modo)
    matplotlib.pylab.title('Integration number %i.'%acc_num)
    matplotlib.pylab.ylabel('Power (arbitrary units)')
    matplotlib.pylab.ylim(0)
    matplotlib.pylab.grid()
    matplotlib.pylab.xlabel('Channel')
    matplotlib.pylab.xlim(0,1024)
    fig.canvas.draw()
    fig.canvas.manager.window.after(100, plot_spectrum)

Attachment: spec_arte.pdf
Description: Adobe PDF document

Reply via email to