• 0
berguenstein

python soft doesn't have the same behaviour as waveforms

Question

Posted (edited)

Hi,

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 ).

 code_python.png

result_python.png

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.

result_waveforms.png

Could someone help me?

Thanks,

Marc

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:
Digital_Uart_RX.py

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:
    time.sleep(0.001)
    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