Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading state of PIO0-3 via ctrl_transfer() fails #146

Open
StefanMack opened this issue Jun 7, 2020 · 4 comments
Open

Reading state of PIO0-3 via ctrl_transfer() fails #146

StefanMack opened this issue Jun 7, 2020 · 4 comments

Comments

@StefanMack
Copy link

StefanMack commented Jun 7, 2020

Hi Alexandra,
thank you for the great pysmu package. The ADC and DAC functions of the libsmu python examples work fine. The ADALM1000 is an ideal tool for university teaching electrical engineering labs. Especially nowadays during Corona we can give the ADALM1000 to the students for a take home lab!

Setting the PIO0-3 (e.g. device.ctrl_transfer(0x40, 0x51, PIO_0, 0, 0, 0, 100)) also works fine, by I do not manage to read the PIO0-3 state.

The following code fails on Python 3.69, Ubuntu Linux 18.04 LTS with error:

print(list(state))
TypeError: ord() expected string of length 1, but int found

import time
from pysmu import Session

# assign digital pins
PIO_0 = 28
PIO_1 = 29
PIO_2 = 47
PIO_3 = 3 

try:
    session = Session(ignore_dataflow=True, queue_size=10000)
    if session.devices:
        dev = session.devices[0]
        while True:
            # get state of PIO0
            state = dev.ctrl_transfer(0xc0, 0x91, PIO_3, 0, 0, 1, 100)
            print(list(state))
            time.sleep(1)
    else:
        print('no devices attached')
    
except KeyboardInterrupt:
    print()
    print('Strg + C erkannt...')
    
finally:
    pass

I guess it has something to to with the following statement in the libsmu.pyx function definition of ctrl_transfer():

if bm_request_type & 0x80 == 0x80:
    return map(ord, data)

To me it seems that the map() function causes trouble for Python 3.
Is there any work around? Or how and where can I change the implementation of the ctrl_transfer() function?

@AlexandraTrifan
Copy link
Contributor

Hi,

Let us take a look and we will come back with a fix as soon as possible.
We are working on a new release for some bug fixes, we will take a look at this and add this too.

-Alexandra

@AlexandraTrifan
Copy link
Contributor

Hi,

This causes trouble only for Python3. One idea would be to change the return map(ord, data) to return bytearray(data).
Would this work for you?

-Alexandra

@StefanMack
Copy link
Author

Hi Alexandra,

I installed libsmu and the python bindings on Ubuntu 18.04. Where can I find the file libsmu.pyx to test the changes suggested by you?

-Stefan

@AlexandraTrifan
Copy link
Contributor

Hi,

We are sorry for the delay. We added the fix for libsmu.pyx on master. We will prepare a new release soon. We're just working on fixing the nightly builds on Appveyor and migrating the linux builds.
Here is the link to the commit that fixes the bindings: aaad9af

-Alexandra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants