AnsweredAssumed Answered

Using iio.py with M2K

Question asked by dmercer Employee on Jul 15, 2017
Latest reply on Jul 17, 2017 by dmercer

HI:

I'm trying to test out some of the iio.py Python bindings on M2K.

 

As a first experiment I'm attempting to turn on and adjust the outputs of the User Power Supplies.

 

I know that the M2K iio device will be ad5627 which has two output channels.
I can find the device in the context by:

 

contexts = iio.scan_contexts()
uri = next(iter(contexts), None)
ctx = iio.Context(uri)
#
ad5627 = ctx.find_device("ad5627")

 

To test if this works I do:

 

print ad5627.id, ad5627.name

 

I can find the first voltage0 channel with:

 

for chan in ad5627.channels:
    if chan.id == "voltage0" and chan.output:
        print "channel id " + str(chan.id)
        print "channel direction " + str(chan.output)

 

From here on I'm not getting very much farther. I can print out the power down state but don't know exactly how to change it to False. Or how to set the DAC value.

 

In the C++ code for Scopy I found these calls to iio but I don't see the equivalent in iio.py.

 

/* Power down DACs by default */
iio_channel_attr_write_bool(ch1w, "powerdown", true);
iio_channel_attr_write_bool(ch2w, "powerdown", true);

 

/* Set the default values */
iio_channel_attr_write_longlong(ch1w, "raw", 0LL);
iio_channel_attr_write_longlong(ch2w, "raw", 0LL);

 

and this to set the DAC value:

 

void PowerController::dac1_set_value(double value)
{
    long long val = value * 4095.0 / (5.02 * 1.2);

 

    iio_channel_attr_write_longlong(ch1w, "raw", val);

 

    if (in_sync) {
        value = -value * ui->trackingRatio->value() / 100.0;
        ui->valueNeg->setValue(value);
        dac2_set_value(value);
    }
}

 

Any help in reproducing this in Python would be a huge help! I'm sure there will be more things I don't understand as well.

Thanks

 

Doug

Outcomes