Jump to content
  • 0

python soft doesn't have the same behaviour as waveforms


berguenstein

Question

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

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

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

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...