Beispiel #1
0
    def __init__(self,
                 dev,
                 no,
                 subdev,
                 fd,
                 devrange,
                 aref=aref_ground,
                 calibrate=False,
                 configpath=None,
                 maxbuffer=131072):
        self.no = no
        self.dev = dev
        self.subdev = subdev
        self.fd = fd
        self.devrange = devrange
        self.aref = aref
        if calibrate:
            sys.stdout.write("NICOMEDI: Parsing calibration file... ")
            sys.stdout.flush()

            calib = c.comedi_parse_calibration_file(configpath)

            if calib is None or calib == 0:
                sys.stdout.write("FAIL\n")
            else:
                self.convpoly = c.comedi_polynomial_t()
                conv = c.comedi_get_softcal_converter( \
                    self.subdev, self.no, self.devrange, c.COMEDI_TO_PHYSICAL,
                    calib, self.convpoly)
                c.comedi_cleanup_calibration(calib)
                if conv < 0:
                    sys.stdout.write("FAIL\n")
                else:
                    sys.stdout.write("success\n")
            sys.stdout.flush()
            self.convpoly_order = int(self.convpoly.order.real)
            self.convpoly_expansion_origin = self.convpoly.expansion_origin.real
            c_coeff = ctypes.c_double * (int(self.convpoly.order.real) + 1)
            c_coeff = c_coeff.from_address(int(self.convpoly.coefficients))
            self.convpoly_coefficients = np.array(
                [coeff.real for coeff in c_coeff])
        else:
            self.convpoly = None
        self.maxdata = c.comedi_get_maxdata(self.dev, self.subdev, self.no)
        if self.maxdata == 0:
            comedi_errcheck()
        self.prange = c.comedi_get_range(self.dev, self.subdev, self.no,
                                         self.devrange)
        if self.prange == 0 or self.prange is None:
            comedi_errcheck()
        self.maxbuffer = c.comedi_get_max_buffer_size(self.dev, self.subdev)
        if self.maxbuffer == -1:
            comedi_errcheck()
        self.buffer = c.comedi_get_buffer_size(self.dev, self.subdev)
        sys.stdout.write("NICOMEDI: Buffer size: %d\n" % self.buffer)
        sys.stdout.flush()
    def setup_adc(self):
        self.subdevice=0 #Always the case here
        self.dev = c.comedi_open('/dev/comedi0')
        if not self.dev: 
            self.logger.error("Error openning Comedi device")
            return -1
        
        self.file_device = c.comedi_fileno(self.dev)
        if not self.file_device:
            self.logger.error("Error obtaining Comedi device file descriptor")
            return -1

        self.buffer_size = c.comedi_get_buffer_size(self.dev, self.subdevice)
        temp_msg = "Debug size: %i" % self.buffer_size
        self.logger.info(temp_msg)
        self.map = mmap.mmap(self.file_device,self.buffer_size,mmap.MAP_SHARED, mmap.PROT_READ)
Beispiel #3
0
    def __init__(self, dev, no, subdev, fd, devrange, aref=aref_ground, 
                 calibrate=False, configpath=None, maxbuffer=131072):
        self.no = no
        self.dev = dev
        self.subdev = subdev
        self.fd = fd
        self.devrange = devrange
        self.aref = aref
        if calibrate:
            sys.stdout.write("NICOMEDI: Parsing calibration file... ")
            sys.stdout.flush()

            calib = c.comedi_parse_calibration_file(configpath)

            if calib is None or calib==0:
                sys.stdout.write("FAIL\n")
            else:
                self.convpoly = c.comedi_polynomial_t()
                conv = c.comedi_get_softcal_converter( \
                    self.subdev, self.no, self.devrange, c.COMEDI_TO_PHYSICAL,
                    calib, self.convpoly)
                c.comedi_cleanup_calibration(calib)
                if conv < 0:
                    sys.stdout.write("FAIL\n")
                else:
                    sys.stdout.write("success\n")
            sys.stdout.flush()
            self.convpoly_order = int(self.convpoly.order.real)
            self.convpoly_expansion_origin = self.convpoly.expansion_origin.real
            c_coeff = ctypes.c_double * (int(self.convpoly.order.real)+1)
            c_coeff = c_coeff.from_address(int(self.convpoly.coefficients))
            self.convpoly_coefficients = np.array([
                coeff.real for coeff in c_coeff])
        else:
            self.convpoly = None
        self.maxdata = c.comedi_get_maxdata(self.dev, self.subdev, self.no)
        if self.maxdata == 0:
            comedi_errcheck()
        self.prange = c.comedi_get_range(self.dev, self.subdev, self.no, self.devrange)
        if self.prange == 0 or self.prange is None:
            comedi_errcheck()
        self.maxbuffer = c.comedi_get_max_buffer_size(self.dev, self.subdev)
        if self.maxbuffer == -1:
            comedi_errcheck()
        self.buffer = c.comedi_get_buffer_size(self.dev, self.subdev)
        sys.stdout.write("NICOMEDI: Buffer size: %d\n" % self.buffer)
        sys.stdout.flush()
Beispiel #4
0
    def __init__(self, dev, no, subdev, fd, devrange, aref=aref_ground, 
                 calibrate=False, configpath=None, maxbuffer=131072):
        self.no = no
        self.dev = dev
        self.subdev = subdev
        self.fd = fd
        self.devrange = devrange
        self.aref = aref
        if calibrate:
            sys.stdout.write("NICOMEDI: Parsing calibration file... ")
            sys.stdout.flush()

            calib = c.comedi_parse_calibration_file(configpath)

            if calib is None or calib==0:
                sys.stdout.write("FAIL\n")
            else:
                self.convpoly = c.comedi_polynomial_t()
                conv = c.comedi_get_softcal_converter( \
                    self.subdev, self.no, self.devrange, c.COMEDI_TO_PHYSICAL,
                    calib, self.convpoly)
                c.comedi_cleanup_calibration(calib)
                if conv < 0:
                    sys.stdout.write("FAIL\n")
                else:
                    sys.stdout.write("success\n")
            sys.stdout.flush()
        else:
            self.convpoly = None
        self.maxdata = c.comedi_get_maxdata(self.dev, self.subdev, self.no)
        if self.maxdata == 0:
            comedi_errcheck()
        self.prange = c.comedi_get_range(self.dev, self.subdev, self.no, self.devrange)
        if self.prange == 0 or self.prange is None:
            comedi_errcheck()
        self.maxbuffer = c.comedi_get_max_buffer_size(self.dev, self.subdev)
        if self.maxbuffer == -1:
            comedi_errcheck()
        self.buffer = c.comedi_get_buffer_size(self.dev, self.subdev)
        sys.stdout.write("NICOMEDI: Buffer size: %d\n" % self.buffer)
        sys.stdout.flush()
    "invalid source",
    "source conflict",
    "invalid argument",
    "argument conflict",
    "invalid chanlist"]


#wrappers include a "chanlist" object (just an Unsigned Int array) for holding the chanlist information
mylist = c.chanlist(nchans) #create a chanlist of length nchans

#now pack the channel, gain and reference information into the chanlist object
#N.B. the CR_PACK and other comedi macros are now python functions
for index in range(nchans):
    mylist[index]=c.cr_pack(chans[index], gains[index], aref[index])

size = c.comedi_get_buffer_size(dev, subdevice)
print "buffer size is ", size

map = mmap.mmap(fd, size, mmap.MAP_SHARED, mmap.PROT_READ)
print "map = ", map

def dump_cmd(cmd):
    print "---------------------------"
    print "command structure contains:"
    print "cmd.subdev : ", cmd.subdev
    print "cmd.flags : ", cmd.flags
    print "cmd.start :\t", cmd.start_src, "\t", cmd.start_arg
    print "cmd.scan_beg :\t", cmd.scan_begin_src, "\t", cmd.scan_begin_arg
    print "cmd.convert :\t", cmd.convert_src, "\t", cmd.convert_arg
    print "cmd.scan_end :\t", cmd.scan_end_src, "\t", cmd.scan_end_arg
    print "cmd.stop :\t", cmd.stop_src, "\t", cmd.stop_arg
Beispiel #6
0
cmdtest_messages = [
    "success", "invalid source", "source conflict", "invalid argument",
    "argument conflict", "invalid chanlist"
]

nchans = len(chans)  #number of channels

#wrappers include a "chanlist" object (just an Unsigned Int array) for holding the chanlist information
mylist = c.chanlist(nchans)  #create a chanlist of length nchans

#now pack the channel, gain and reference information into the chanlist object
#N.B. the CR_PACK and other comedi macros are now python functions
for index in range(nchans):
    mylist[index] = c.cr_pack(chans[index], gains[index], aref[index])

size = c.comedi_get_buffer_size(dev, subdevice)
print("buffer size is ", size)
map = mmap.mmap(fd, size, mmap.MAP_SHARED, mmap.PROT_READ)
print("map = ", map)


def dump_cmd(cmd):
    print("---------------------------")
    print("command structure contains:")
    print("cmd.subdev : ", cmd.subdev)
    print("cmd.flags : ", cmd.flags)
    print("cmd.start :\t", cmd.start_src, "\t", cmd.start_arg)
    print("cmd.scan_beg :\t", cmd.scan_begin_src, "\t", cmd.scan_begin_arg)
    print("cmd.convert :\t", cmd.convert_src, "\t", cmd.convert_arg)
    print("cmd.scan_end :\t", cmd.scan_end_src, "\t", cmd.scan_end_arg)
    print("cmd.stop :\t", cmd.stop_src, "\t", cmd.stop_arg)