Skip to content

Commit

Permalink
Merge branch 'bomber8013-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Apr 21, 2019
2 parents af439b8 + cb1e6de commit 190fb1d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/NIDAQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export analog_input_channels, analog_output_channels
export digital_input_channels, digital_output_channels
export counter_input_channels, counter_output_channels

export RSE, NRSE, Differential, PseudoDifferential

const NIDAQmx = "C:\\Windows\\System32\\nicaiu.dll"
const SafeCstring = Ref{UInt8}

Expand Down
19 changes: 9 additions & 10 deletions src/analog.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
analog_input_configs = Dict{AbstractString,Number}(
"referenced single-ended" => Val_RSE,
"non-referenced single-ended" => Val_NRSE,
"pseudo-differential" => Val_PseudoDiff,
"differential" => Val_Diff )
@enum TerminalConfig::Cuint RSE=Val_RSE NRSE=Val_NRSE Differential=Val_Diff PseudoDifferential=Val_PseudoDiff


"""
`analog_input(channel, config, range) -> task`
Expand All @@ -11,22 +8,22 @@ analog_input_configs = Dict{AbstractString,Number}(
create an analog input channel, and a new task if one is not specified
"""
function analog_input(channel::String; terminal_config="differential", range=nothing)
function analog_input(channel::String; terminal_config::TerminalConfig=Differential, range=nothing)
t = AITask()
analog_input(t, channel, terminal_config=terminal_config, range=range)
t
end

function analog_input(t::AITask, channel::String;
terminal_config="differential", range=nothing)
terminal_config::TerminalConfig=Differential, range=nothing)
if range==nothing
device::String = split(channel,'/')[1]
range=float(analog_input_ranges(device)[end,:])
end
catch_error( CreateAIVoltageChan(t.th,
Ref(codeunits(channel),1),
Ref(codeunits(""), 1),
analog_input_configs[terminal_config],
terminal_config,
range[1], range[2],
Val_Volts,
convert(Ptr{UInt8},C_NULL)) )
Expand Down Expand Up @@ -67,8 +64,10 @@ read_analog_cfunctions = Dict{Type,Function}(
UInt16 => ReadBinaryU16,
UInt32 => ReadBinaryU32 )

function read(t::AITask, precision::DataType, num_samples_per_chan::Integer = -1)
num_channels = getproperties(t)["NumChans"][1]
function read(t::AITask, num_samples_per_chan::Integer = -1, precision::DataType = Float64)
outdata_ref = Ref{Cuint}()
DAQmxGetTaskNumChans(t.th, outdata_ref)
num_channels = outdata_ref.x
num_samples_per_chan_read = Int32[0]
buffer_size = num_samples_per_chan==-1 ? 1024 : num_samples_per_chan
data = Array{precision}(undef, buffer_size*num_channels)
Expand Down
6 changes: 4 additions & 2 deletions src/digital.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ read_digital_cfunctions = Dict{Type,Function}(
UInt16 => ReadDigitalU16,
UInt32 => ReadDigitalU32 )

function read(t::DITask, precision::DataType, num_samples_per_chan::Integer = -1)
num_channels = getproperties(t)["NumChans"][1]
function read(t::DITask, num_samples_per_chan::Integer = -1, precision::DataType = UInt32)
outdata_ref = Ref{Cuint}()
DAQmxGetTaskNumChans(t.th, outdata_ref)
num_channels = outdata_ref.x
num_samples_per_chan_read = Int32[0]
buffer_size = num_samples_per_chan==-1 ? 1024 : num_samples_per_chan
data = Array{precision}(undef, buffer_size*num_channels)
Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ else
@test typeof(getproperties(t,dev*"/ai0")) == Dict{String,Tuple{Any,Bool}}
@test typeof(t) == NIDAQ.AITask
@test start(t) == nothing
@test length(read(t, Float64, 3)) == 3
@test length(read(t, 3)) == 3
@test stop(t) == nothing
@test analog_input(t, dev*"/ai1") == nothing
@test start(t) == nothing
@test length(read(t, UInt32, 6)) == 12
@test length(read(t, 6, UInt32)) == 12
@test stop(t) == nothing
@test NIDAQ.CfgSampClkTiming(t.th, convert(Ref{UInt8},b""), 100.0, NIDAQ.Val_Rising,
NIDAQ.Val_FiniteSamps, UInt64(10)) == 0
@test start(t) == nothing
@test length(read(t, Float64)) == 20
@test length(read(t)) == 20
@test stop(t) == nothing
@test clear(t) == nothing
end
Expand Down Expand Up @@ -85,11 +85,11 @@ else
t = digital_input(dev*"/Port0/Line0")
@test typeof(t) == NIDAQ.DITask
@test start(t) == nothing
@test length(read(t, UInt32, 3)) == 3
@test length(read(t, 3)) == 3
@test stop(t) == nothing
@test digital_input(t, dev*"/Port0/Line1") == nothing
@test start(t) == nothing
@test length(read(t, UInt32, 6)) == 12
@test length(read(t, 6)) == 12
@test stop(t) == nothing
rslt = Ref{UInt32}(0)
NIDAQ.DAQmxGetBufInputOnbrdBufSize(t.th, rslt)
Expand All @@ -98,7 +98,7 @@ else
NIDAQ.Val_FiniteSamps, UInt64(10)) == 0
if first(props["ProductCategory"]) != :Val_MSeriesDAQ # M Series has no digital onboard clock
@test start(t) == nothing
@test length(read(t, UInt32)) == 20
@test length(read(t)) == 20
@test stop(t) == nothing
end
@test clear(t) == nothing
Expand Down

4 comments on commit 190fb1d

@bjarthur
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Cody-G could you please try these changes i just pushed to master? would be good to know they worked on someone else's card before we tag a release. thanks.

@Cody-G
Copy link
Contributor

@Cody-G Cody-G commented on 190fb1d Apr 21, 2019

Choose a reason for hiding this comment

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

Unfortunately I've moved on from the project and don't have access to any cards any time soon. Looking through the changes I don't see any obvious issues, except I wonder why the order of arguments to the read function was changed. That's a breaking change, so I'd rather avoid it if possible.

@bjarthur
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i've now documented and deprecated the change to read. the thinking in putting the number of samples before the precision and adding a (hopefully popular) default to the latter is that users would more likely need to use an alternate number of samples than an alternate precision.

@Cody-G
Copy link
Contributor

@Cody-G Cody-G commented on 190fb1d Apr 29, 2019

Choose a reason for hiding this comment

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

Got it, thanks for the explanation. Looks good to me!

Please sign in to comment.