JaneliaSciComp / NIDAQ.jl

National Instruments Data Acquisition Interface
Other
47 stars 16 forks source link

Error when adding a analogue channel from a cDAQ module #11

Closed halars closed 6 years ago

halars commented 6 years ago

I'm having trouble adding analogue channels of a NI module. I have one device (Dev1) and one chassis (Dev2) with a module (Dev2Mod1)., connected. Output from getproperties:

julia> getproperties()["DevNames"][1]
3-element Array{SubString{String},1}:
 "Dev1"
 "Dev2"
 "Dev2Mod1"

Here are the outputs from analog_input_channels for each element:

julia> analog_input_channels("Dev1")
8-element Array{String,1}:
 "Dev1/ai0"
 "Dev1/ai1"
 "Dev1/ai2"
 "Dev1/ai3"
 "Dev1/ai4"
 "Dev1/ai5"
 "Dev1/ai6"
 "Dev1/ai7"

julia> analog_input_channels("Dev2")
1-element Array{String,1}:
 ""

julia> analog_input_channels("Dev2Mod1")
4-element Array{String,1}:
 "Dev2Mod1/ai0"
 "Dev2Mod1/ai1"
 "Dev2Mod1/ai2"
 "Dev2Mod1/ai3"

Trying to add channel 1 from Dev1 is successful:

julia> t = analog_input("Dev1/ai0")
NIDAQ.AITask(Ptr{Void} @0x000000000370a8a0)

But trying to add channel 1 for Dev2Mod1 is unsuccessful.

julia> t2 = analog_input("Dev2Mod1/ai0")
ERROR: NIDAQmx: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Stacktrace:
 [1] #catch_error#1(::Base.#error, ::Function, ::Int32, ::String) at C:\Users\lars\.julia\v0.6\NIDAQ\src\NIDAQ.jl:96
 [2] catch_error(::Int32) at C:\Users\lars\.julia\v0.6\NIDAQ\src\NIDAQ.jl:89
 [3] #analog_input#3(::String, ::Void, ::Function, ::NIDAQ.AITask, ::String) at C:\Users\lars\.julia\v0.6\NIDAQ\src\analog.jl:25
 [4] (::NIDAQ.#kw##analog_input)(::Array{Any,1}, ::NIDAQ.#analog_input, ::NIDAQ.AITask, ::String) at .\<missing>:0
 [5] #analog_input#2 at C:\Users\lars\.julia\v0.6\NIDAQ\src\analog.jl:15 [inlined]
 [6] analog_input(::String) at C:\Users\lars\.julia\v0.6\NIDAQ\src\analog.jl:14

I suspect no device/driver issues as there is no issue when using Matlab and its DAQ interface.

How should one add such a channel?

bjarthur commented 6 years ago

i think NI-DAQmx limits you to only one task of any type at a given time. try this:

t = analog_input("Dev1/ai0")
analog_input(t, "Dev2Mod1/ai0")
halars commented 6 years ago

Unfortunately that does not help. Both your suggestion, and just creating one task (t = analog_input("Dev2Mod1/ai0")), fails, with the same error.

bjarthur commented 6 years ago

following the relevant code, i wonder what analog_input_ranges("Dev2Mod1") returns.

halars commented 6 years ago

following the relevant code, i wonder what analog_input_ranges("Dev2Mod1") returns.

1x2 Array{Float64,2}:
-5.0  5.0
halars commented 6 years ago

I tested with another module (here called Dev2Mod2", which have selectable gains. And the task can be created without any error.

julia> analog_input_ranges("Dev2Mod2")
4x2 Array{Float64,2}:
  -0.2 0.2
  -1.0 1.0
  -5.0 5.0
 -10.0 10.0
halars commented 6 years ago

But yet another module which only have one range, also didn't fail. Dev2Mod1 = 9234 (does not work), single range Dev2Mod2 = 9205 (works), multiple ranges Dev2Mod3 = 9215 (works), single range

Could it be a issue with the selectable AC/DC coupling?

bjarthur commented 6 years ago

the terminal configuration defaults to differential. do these three devices all support that?

halars commented 6 years ago

No, NI 9234 uses 'PseudoDifferential', but also have four measurement types: Voltage, Accelerometer, Microphone and IEPE (all are voltages though) And three coupling options: AC, DC and IEPE

halars commented 6 years ago

I've tried "referenced single-ended", "non-referenced single-ended" and "differential" with no discernible difference in error output.

bjarthur commented 6 years ago

ahah, can you try modifying the code to include pseudo-diff?

halars commented 6 years ago

Yes, now it works! Thanks :)

bjarthur commented 6 years ago

glad i could help. could you please submit a PR so we can share the solution with others?

halars commented 6 years ago

Ok