Unknown exception. Status code:504 in Moku Pro

Moku model: Moku Pro
Operating system: Ubuntu
Software version: 587

Bug or support request description:

I have tried Multi-instrument mode in Moku and I keep getting ‘Unknown exception. Status code:504’ error. I am using the latest MOKU API Python version.

I don’t know why I’m getting this error. Any idea?

Hi @bonhardt ,

To debug this issue on our end, would you please attach your code and the full error message? Thanks.

Best regards,
Hank

Here is the code:

import matplotlib.pyplot as plt
from moku.instruments import MultiInstrument
from moku.instruments import ArbitraryWaveformGenerator,Oscilloscope


from Msequence import msequence,repeat_bits
import numpy as np
import matplotlib.pyplot as plt


polynomial_coefficients = [8,6]
m_sequence_output = msequence(polynomial_coefficients)

plt.figure(14)
plt.plot(m_sequence_output[1])
plt.title('Square wave fed to Moku Pro')
plt.ylabel('Amplitude')
plt.xlabel('Time')
plt.grid(True)
plt.show()


m= MultiInstrument('192.168.73.1', platform_id=4, force_connect=True)

try:
    wg=m.set_instrument(1, ArbitraryWaveformGenerator)
    osc=m.set_instrument(2, Oscilloscope)
    
    connections= [dict(source="Input1", destination="Slot1InA"), 
                  dict(source="Slot1OutA", destination="Slot2InA"),
                  dict(source="Slot1OutA", destination="Slot2InB"),
                  dict(source="Slot2OutA", destination="Output1")
                  ]
    print(m.set_connections(connections=connections))
    
    wg.generate_waveform(channel=1, sample_rate='Auto',
                        lut_data=list(m_sequence_output[1]), frequency=10e3,
                        amplitude=1)
    osc.set_timebase(-5e2, 5e-2, strict=False)
    data=osc.get_data(timeout=60, wait_reacquire=True, wait_complete=True)
    
    
    plt.ion()
    plt.show()
    plt.grid(b=True)
    plt.ylim([-1,1])
    plt.xlim([data['time'][0], data['time'][-1]])
    
    line1, = plt.plot([])
    line2, = plt.plot([])
    
    ax=plt.gca()
    
    while True:
        data=osc.get_data()
        line1.set_ydata(data['Ch1'])
        line2.set_ydata(data['Ch2'])
        line1.set_xdata(data['time'])
        line2.set_xdata(data['time'])
        plt.pause(0.001)

 
    
    
except Exception as e:
    raise e
    
finally:
    m.relinquish_ownership()

and the error:


  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "/home/bonhardt/Desktop/PHD_2022/DI PROJECT/DI python code/Multi_instruments_FEB24.py", line 74, in <module>
    raise e

  File "/home/bonhardt/Desktop/PHD_2022/DI PROJECT/DI python code/Multi_instruments_FEB24.py", line 48, in <module>
    data=osc.get_data(timeout=60, wait_reacquire=True, wait_complete=True)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/instruments/_oscilloscope.py", line 547, in get_data
    return self.session.post(

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 14, in func_wrapper
    return self.resolve(response)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 167, in resolve
    self.handle_http_error(response)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 110, in handle_http_error
    raise exceptions.MokuException(

MokuException: Unknown exception. Status code:504

Here is the code:

import matplotlib.pyplot as plt
from moku.instruments import MultiInstrument
from moku.instruments import ArbitraryWaveformGenerator,Oscilloscope


from Msequence import msequence,repeat_bits
import numpy as np
import matplotlib.pyplot as plt


polynomial_coefficients = [8,6]
m_sequence_output = msequence(polynomial_coefficients)

plt.figure(14)
plt.plot(m_sequence_output[1])
plt.title('Square wave fed to Moku Pro')
plt.ylabel('Amplitude')
plt.xlabel('Time')
plt.grid(True)
plt.show()


m= MultiInstrument('192.168.73.1', platform_id=4, force_connect=True)

try:
    wg=m.set_instrument(1, ArbitraryWaveformGenerator)
    osc=m.set_instrument(2, Oscilloscope)
    
    connections= [dict(source="Input1", destination="Slot1InA"), 
                  dict(source="Slot1OutA", destination="Slot2InA"),
                  dict(source="Slot1OutA", destination="Slot2InB"),
                  dict(source="Slot2OutA", destination="Output1")
                  ]
    print(m.set_connections(connections=connections))
    
    wg.generate_waveform(channel=1, sample_rate='Auto',
                        lut_data=list(m_sequence_output[1]), frequency=10e3,
                        amplitude=1)
    osc.set_timebase(-5e4, 5e-4, strict=False)
    data=osc.get_data(timeout=60, wait_reacquire=True, wait_complete=True)
    
    
    plt.ion()
    plt.show()
    plt.grid(b=True)
    plt.ylim([-1,1])
    plt.xlim([data['time'][0], data['time'][-1]])
    
    line1, = plt.plot([])
    line2, = plt.plot([])
    
    ax=plt.gca()
    
    while True:
        data=osc.get_data()
        line1.set_ydata(data['Ch1'])
        line2.set_ydata(data['Ch2'])
        line1.set_xdata(data['time'])
        line2.set_xdata(data['time'])
        plt.pause(0.001)

 
    
    
except Exception as e:
    raise e
    
finally:
    m.relinquish_ownership()

and the error:


  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "/home/bonhardt/Desktop/PHD_2022/DI PROJECT/DI python code/Multi_instruments_FEB24.py", line 74, in <module>
    raise e

  File "/home/bonhardt/Desktop/PHD_2022/DI PROJECT/DI python code/Multi_instruments_FEB24.py", line 48, in <module>
    data=osc.get_data(timeout=60, wait_reacquire=True, wait_complete=True)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/instruments/_oscilloscope.py", line 547, in get_data
    return self.session.post(

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 14, in func_wrapper
    return self.resolve(response)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 167, in resolve
    self.handle_http_error(response)

  File "/home/bonhardt/anaconda3/lib/python3.9/site-packages/moku/session.py", line 110, in handle_http_error
    raise exceptions.MokuException(

MokuException: Unknown exception. Status code:504

Hi @bonhardt ,

I can see that the get_data call produced this issue. Were you able to run the the single oscilloscope Python example?

I am looking forward to hearing you back. Thanks.

Best regards,
Hank

Hi Hank,
The Oscilloscope example works perfectly fine.

I managed to solve the problem. The problem was with setting the timebase of the oscillator.

I got rid of the error by setting the timebase similar to the frequency range of the waveform generator.

i.e

 wg.generate_waveform(channel=1, sample_rate='Auto',
                        lut_data=list(m_sequence_output[1]), frequency=100e6,
                        amplitude=1)
    osc.set_timebase(-5e-8, 5e-8, strict=False)

Hi Reinhardt @bonhardt ,

Thank you very much for working on that. Please allow me to explain the reason why you got the Error 504 issue.

The timebase length in your code was longer than 10,000 seconds, it will be coerced to 100 seconds long.

    osc.set_timebase(-5e4, 5e-4, strict=False)

Please note that, Moku:Pro will need a time longer than 100 seconds to obtain a complete frame. But you specified the timeout parameter as 60 seconds, Moku:Pro will not be able to return the complete frame and return a Error 504 message.

    data=osc.get_data(timeout=60, wait_reacquire=True, wait_complete=True)

In your resolution, you limited the timebase length. The get_data is able to return a frame now. It is not necessary to set the timebase similar to the frequency of the waveform generator, but it is required to not choose a timebase too large.

Thank you for your patinece and time.

Best regards,
Hank