• 0

python soft doesn't have the same behaviour as waveforms


Posted (edited)


I'm trying to use the UART of my Analog Discovery 2 in python. I've had a look at the example and just ran it.

At first, I thought it worked. But then I realized it was okay only for the first frame. After increasing the sleeping before the print (see the pics just under), the values are more often correct, but there's still a lot of unexpected results. (see the pics just under ).



The thing is, when I use Waveforms, it works(see the pic just under). Also I thought of a problem with the SDK, even if I don't really think so.


Could someone help me?



Edited by berguenstein

Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @berguenstein

Here you have a UART - RX example file:

This should work properly.
The 1ms sleep is only to reduce the CPU load. For high UART rate, to maximize USB bandwidth usage and data streaming throughput it can be removed.

while True:
    dwf.FDwfDigitalUartRx(hdwf, rgRX, c_int(sizeof(rgRX)-1), byref(cRX), byref(fParity)) # read up to 8k chars at once
    if cRX.value > 0:
        rgRX[cRX.value] = 0 # add zero ending
        sz = rgRX.value.decode()
        #sz = sz.replace('\r', '\n') # replace CarriageReturn or other custom line ending to LineFeed, in case it is needed
        print(sz, end = '', flush=True) # works with CR+LF or LF
    if fParity.value != 0:
        print("Parity error {}".format(fParity.value))


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now