Generate "User Provided" waveform with QA403

Hello,

I’m kindly asking for support on the following matter.

I would like use the Generator to output a “User Provided” waveform
with the QA403.

According to the Wiki (DAC Output Block Diagram · QuantAsylum/QA40x Wiki · GitHub) it should be possible to supply a pair of Base64 encoded strings which define the waveform(s).

Looking at the REST interface description I can not find a matching call
to choose a “User Provided” mode and a way to supply the waveform data.

What am I missing? Do I overlook the obvious?

Thank you and kind regards
Peter

Hi @Peter_T, take a look at the C# code that does this in the QA402_REST_TEST repo. Around line 176 you’ll see the DoAcquisition() that takes the left/right waveforms you want to send out. You can see the Base64 encoding into one big string, and then that string is passed to the Post() call around line 332.

And in the Post() function, that strings gets turned into a Post body application/json.

Hi Matt,

thank you very much for the swift support!

It wasn’t clear to me that the output data is part of the acquisition call …

Thanks again
Peter

Hi,

I am still having trouble generating a user defined waveform.
The REST API call I use from python looks like this but I do not get an output:

http://localhost:9402/Acquisition/{ “Left”:“ABCD…”, “Right”:“ABCD…” }

where “ABCD…” stands for the encoded string.

  • is the call correctly formatted?
  • the length of the waveform array is equal to the buffersize - is that correct?

Since the waveform arrays are transmitted every time the acquisition is started
the time between each acquisition is relatively large. Is there a way to upload
the waveform once and then repeatedly use it?

  1. My goal is to generate single or multiple sharp pulse on the generator output.
    Is there a way to achieve this with the on board commands? I did not find a way …

Looking forward to any advice!

Kind regards
Peter

Hi @Peter_T, there’s not a way to tell the analyzer to buffer the last buffer.

How large are the waveforms you are sending, and how long is it taking to process the waveforms? There will be two parts to this: The time required to digest the BASE64 data, and the time required to send the data. To the caller (aka your code), you can’t really know how long each took. But remember that doing a send/receive on a 64K buffer at 48K sample rate will take (64K/48)=1.36 seconds. And on a 128K buffer it will take twice as long. This is the physical time to send the buffer to the DAC. There’s no way to shorten this. But if you time the total time for the POST to return, you can then subtract the fixed transmission time and learn the processing time.

My guess is the processing time is a very small part of the equation. The reason being is that decoding BASE64 and sticking it into the body of a POST request is a pretty common operation and Microsoft has ensured C# is quite good there.

Hi Matt,

thanks for clarification regarding the timings.

Could you please also reply to my questions regarding the REST API string and the buffer size and
if there is a way to eventually generate pulse with the on board generator functions …

Thanks for taking the time to answer my questions!
Peter

Hi @Peter_T, if you look at the code in the github link I posted above, you’ll see this the base64 encoded string goes into the body of the put request. This is because the max length of a URL is something like 2K or so. You cannot send large amounts of data via the URL as you are doing.

If you can run Visual Studio, the github repo should be easily cloned, and then you can single step the building of the REST command and add whatever debug you want. And then replicate that via CURL.

Hi Matt,

thank you for your reply. Since I am using LINUX a can not run C#.

Nevertheless your advice enabled me to write the following python code to do
want I needed. Maybe someone else finds it useful …

Best regards
Peter

def encode_array_to_mime64(double_array):

    # Convert the numpy array to bytes
    arr_bytes = double_array.tobytes()

    # Encode the byte array to base64   
    base64_bytes = base64.b64encode(arr_bytes)
    
    # Decode base64 bytes to a UTF-8 string
    base64_utf8_str = base64_bytes.decode('utf-8')

    return base64_utf8_str

# encode numpy array to mime64 data
encoded_excitation=encode_array_to_mime64(excitation)

# format JSON body
data={ "Left": f"{encoded_excitation}", "Right": f"{encoded_excitation}" }

# send request with JSON payload
resp = requests.post('http://localhost:9402/Acquisition',json=data)

Thanks @Peter_T for the code!