Skip to content

Commit

Permalink
pxi6733: fix crash when samples are all the same
Browse files Browse the repository at this point in the history
When samples are all the same, min = max, which PyDAQmx does not like.
This avoids the following crash reported by Kathie:

C:\Users\rabi\artiq\artiq\frontend [master]> python .\artiq_rpctool.py ::1 3256
call load_sample_values 100000 'np.array([0.0,0.0],dtype=float)'
Traceback (most recent call last):
  File ".\artiq_rpctool.py", line 112, in <module>
    main()
  File ".\artiq_rpctool.py", line 107, in main
    call_method(remote, args.method, args.args)
  File ".\artiq_rpctool.py", line 79, in call_method
    ret = method(*[eval(arg) for arg in args])
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\artiq-
0.0+dev-py3.4.egg\artiq\protocols\pc_rpc.py", line 142, in proxy
    return self.__do_rpc(name, args, kwargs)
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\artiq-
0.0+dev-py3.4.egg\artiq\protocols\pc_rpc.py", line 134, in __do_rpc
    return self.__do_action(obj)
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\artiq-
0.0+dev-py3.4.egg\artiq\protocols\pc_rpc.py", line 128, in __do_action
    raise RemoteError(obj["message"])
artiq.protocols.pc_rpc.RemoteError: Traceback (most recent call last):
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\artiq-
0.0+dev-py3.4.egg\artiq\protocols\pc_rpc.py", line 476, in _handle_connection_cr

    ret = method(*obj["args"], **obj["kwargs"])
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\artiq-
0.0+dev-py3.4.egg\artiq\devices\pxi6733\driver.py", line 117, in load_sample_val
ues
    byref(num_samps_written), None)
  File "<string>", line 3, in WriteAnalogF64
  File "<string>", line 2, in function
  File "C:\Users\rabi\AppData\Local\Continuum\Anaconda3\lib\site-packages\pydaqm
x-1.3.1-py3.4.egg\PyDAQmx\DAQmxFunctions.py", line 28, in mafunction
    raise DAQError(error,errBuff.value.decode("utf-8"), f.__name__)
PyDAQmx.DAQmxFunctions.DAQError: Minimum is greater than or equal to the maximum
. Ensure the maximum value is greater than the minimum value. If using a custom
scale, ensure that the scaled maximum is greater than the scaled minimum.
Property: DAQmx_AO_Min
Corresponding Value:  0.0

Property: DAQmx_AO_Max
Corresponding Value:  0.0

Channel Name: Dev1/ao1

Task Name: _unnamedTask<4>

Status Code: -200082
 in function DAQmxWriteAnalogF64
  • Loading branch information
fallen committed Aug 19, 2015
1 parent c3f3763 commit da1398b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion artiq/devices/pxi6733/driver.py
Expand Up @@ -93,7 +93,7 @@ def load_sample_values(self, sampling_freq, values):
values = values.flatten()
t = self.daq.Task()
t.CreateAOVoltageChan(self.channels, b"",
min(values), max(values),
min(values), max(values)+1,
self.daq.DAQmx_Val_Volts, None)

channel_number = (c_ulong*1)()
Expand Down

4 comments on commit da1398b

@sbourdeauducq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is an arbitrary scale and can be very large if the samples are small. I'd apply this workaround only when min=max.

@jordens
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's irrelevant. It is a 16 bit DAC with fixed output range.

But what might become relevant (not here and 6733 through) is the fact that min and max should not be automatically derived from the values. For cards that have variable output range, they could change the range depending on the output which may not be what one wants or what is expected.

@fallen
Copy link
Contributor Author

@fallen fallen commented on da1398b Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordens so you think we should allow one to use an output range (min/max pair) which does not correspond to the sample values?

@jordens
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For 6733, you can safely (if your experiment can survive that range) set min=-10 and max=10 (but i have seen funny things at +10V, suspecting signed integer effects) globally. For other cards this can be different.

Please sign in to comment.