Skip to content

Commit

Permalink
added support for julia 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Jan 19, 2016
1 parent 88c21c9 commit 5fd30b5
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 147 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Installation
============

First download and install NI-DAQmx version
[14.1.0](http://www.ni.com/download/ni-daqmx-14.1/4953/en/) (or
[15.1.1](http://www.ni.com/download/ni-daqmx-15.1.1/5665/en/) (or for Julia v3,
[14.1.0](http://www.ni.com/download/ni-daqmx-14.1/4953/en/),
[14.0.0](http://www.ni.com/download/ni-daqmx-14.0/4918/en/),
[9.6.0](http://www.ni.com/download/ni-daqmx-9.6/3423/en/)) from National
Instruments. Then on the Julia command line:
Expand Down Expand Up @@ -322,8 +323,8 @@ julia> names(NIDAQ)

NIDAQmx is a powerful interface, and while NIDAQ.jl provides wrappers
for all of it's functions, it only abstracts a few of them. If these
don't suit your needs you'll have to dive deep into src/functions_V*.jl
and src/constants_V*.jl. Complete documentation of this low-level API
don't suit your needs you'll have to dive deep into `src/functions_V*.jl`
and `src/constants_V*.jl`. Complete documentation of this low-level API
is [here](http://zone.ni.com/reference/en-XX/help/370466V-01/) and
[here](http://zone.ni.com/reference/en-XX/help/370471W-01/).

Expand Down Expand Up @@ -370,11 +371,9 @@ $ mv common.jl src/constants_V<version>.jl

The following manual edits are then necessary:

+ In `constants_V<version>.jl` comment out `const CVICALLBACK = CVICDECL`.

+ For Julia v3, in `constants_V<version>.jl` change `typealias bool32 uInt32`
to `typealias bool32 Bool32`.

+ In `constants_V<version>.jl`
+ comment out `const CVICALLBACK = CVICDECL`,
+ change `typealias bool32 uInt32` to `typealias bool32 Bool32`.
+ For NI-DAQmx v9.6.0 in `NIDAQmx.h` change
`defined(__linux__)` to `defined(__linux__) || defined(__APPLE__)`.

Expand Down
28 changes: 15 additions & 13 deletions src/NIDAQ.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VERSION >= v"0.4.0-dev+6521" && __precompile__()

module NIDAQ

import Base.write, Base.read, Base.start
Expand Down Expand Up @@ -29,13 +31,13 @@ export Bool32

try
global ver
major = Uint32[0]
ccall((:DAQmxGetSysNIDAQMajorVersion,NIDAQmx),Int32,(Ptr{Uint32},),major)
minor = Uint32[0]
ccall((:DAQmxGetSysNIDAQMinorVersion,NIDAQmx),Int32,(Ptr{Uint32},),minor)
update = Uint32[0]
ccall((:DAQmxGetSysNIDAQUpdateVersion,NIDAQmx),Int32,(Ptr{Uint32},),update)
ver = "$(major[1]).$(minor[1]).$(update[1])"
major = Ref{UInt32}(0)
ccall((:DAQmxGetSysNIDAQMajorVersion,NIDAQmx),Int32,(Ref{UInt32},),major)
minor = Ref{UInt32}(0)
ccall((:DAQmxGetSysNIDAQMinorVersion,NIDAQmx),Int32,(Ref{UInt32},),minor)
update = Ref{UInt32}(0)
ccall((:DAQmxGetSysNIDAQUpdateVersion,NIDAQmx),Int32,(Ref{UInt32},),update)
ver = "$(major[]).$(minor[]).$(update[])"
catch
error("can not determine NIDAQmx version.")
end
Expand All @@ -47,8 +49,8 @@ catch
error("NIDAQmx version $ver is not supported.")
end

unsigned_constants = (Uint64=>Symbol)[]
signed_constants = (Int64=>Symbol)[]
unsigned_constants = Dict{UInt64,Symbol}()
signed_constants = Dict{Int64,Symbol}()

for sym in names(NIDAQ,true)
isdefined(sym) || continue
Expand All @@ -57,7 +59,7 @@ for sym in names(NIDAQ,true)
sym_str = sym_str[6:end]
sym_str[1]=='_' && (sym_str = sym_str[2:end])
if @eval typeof($sym) <: Unsigned
@eval $(symbol(sym_str)) = uint32($sym)
@eval $(symbol(sym_str)) = UInt32($sym)
unsigned_constants[eval(:($sym))] = symbol(sym_str)
elseif @eval typeof($sym) <: Signed
sym_str[1:min(end,4)]=="Val_" || continue
Expand All @@ -69,9 +71,9 @@ for sym in names(NIDAQ,true)
end

function catch_error(code::Int32, extra::ASCIIString=""; err_fcn=error)
sz = DAQmxGetErrorString(code, convert(Ptr{Uint8},C_NULL), convert(Uint32,0))
data = zeros(Uint8,sz)
ret = DAQmxGetErrorString(code, convert(Ptr{Uint8},data), convert(Uint32,sz))
sz = DAQmxGetErrorString(code, convert(Ptr{UInt8},C_NULL), convert(UInt32,0))
data = zeros(UInt8,sz)
ret = DAQmxGetErrorString(code, pointer(data), convert(UInt32,sz))
ret>0 && warn("DAQmxGetErrorString error $ret")
ret<0 && err_fcn("DAQmxGetErrorString error $ret")
data = chop(convert(ASCIIString, data))
Expand Down
44 changes: 22 additions & 22 deletions src/analog.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
analog_input_configs = {
analog_input_configs = Dict{AbstractString,Number}(
"referenced single-ended" => Val_RSE,
"non-referenced single-ended" => Val_NRSE,
"differential" => Val_Diff }
"differential" => Val_Diff )

function analog_input(channel::ASCIIString; terminal_config="differential", range=nothing)
t = AITask()
Expand All @@ -16,12 +16,12 @@ function analog_input(t::AITask, channel::ASCIIString;
range=float(analog_input_ranges(device)[end,:])
end
catch_error( CreateAIVoltageChan(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
analog_input_configs[terminal_config],
range[1], range[2],
Val_Volts,
convert(Ptr{Uint8},C_NULL)) )
convert(Ptr{UInt8},C_NULL)) )
nothing
end

Expand All @@ -37,20 +37,20 @@ function analog_output(t::AOTask, channel::ASCIIString; range=nothing)
range=float(analog_output_ranges(device)[end,:])
end
catch_error( CreateAOVoltageChan(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
range[1], range[2],
Val_Volts,
convert(Ptr{Uint8},C_NULL)) )
convert(Ptr{UInt8},C_NULL)) )
nothing
end

read_analog_cfunctions = {
(Float64 => ReadAnalogF64),
(Int16 => ReadBinaryI16),
(Int32 => ReadBinaryI32),
(Uint16 => ReadBinaryU16),
(Uint32 => ReadBinaryU32) }
read_analog_cfunctions = Dict{Type,Function}(
Float64 => ReadAnalogF64,
Int16 => ReadBinaryI16,
Int32 => ReadBinaryI32,
UInt16 => ReadBinaryU16,
UInt32 => ReadBinaryU32 )

function read(t::AITask, precision::DataType, num_samples_per_chan::Integer = -1)
num_channels = getproperties(t)["NumChans"][1]
Expand All @@ -61,9 +61,9 @@ function read(t::AITask, precision::DataType, num_samples_per_chan::Integer = -1
convert(Int32,num_samples_per_chan),
1.0,
reinterpret(Bool32,Val_GroupByChannel),
convert(Ptr{precision},data),
convert(Uint32,num_samples_per_chan*num_channels),
convert(Ptr{Int32},num_samples_per_chan_read),
pointer(data),
convert(UInt32,num_samples_per_chan*num_channels),
pointer(num_samples_per_chan_read),
reinterpret(Ptr{Bool32},C_NULL)) )
data = data[1:num_samples_per_chan_read[1]*num_channels]
num_channels==1 ? data : reshape(data, (num_samples_per_chan, convert(Int64,num_channels)))
Expand All @@ -73,19 +73,19 @@ for (cfunction, types) in (
(WriteAnalogF64, Float64),
(WriteBinaryI16, Int16),
(WriteBinaryI32, Int32),
(WriteBinaryU16, Uint16),
(WriteBinaryU32, Uint32))
(WriteBinaryU16, UInt16),
(WriteBinaryU32, UInt32))
@eval function write(t::AOTask, data::Matrix{$types})
num_samples_per_chan::Int32 = size(data, 1)
data = reshape(data, length(data))
num_samples_per_chan_written = Int32[0]
catch_error( $cfunction(t.th,
num_samples_per_chan,
reinterpret(Bool32, uint32(false)),
reinterpret(Bool32, UInt32(false)),
1.0,
reinterpret(Bool32,Val_GroupByChannel),
convert(Ptr{$types},data),
convert(Ptr{Int32},num_samples_per_chan_written),
pointer(data),
pointer(num_samples_per_chan_written),
reinterpret(Ptr{Bool32},C_NULL)) )
num_samples_per_chan_written[1]
end
Expand Down
2 changes: 1 addition & 1 deletion src/constants_V15.1.1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3574,7 +3574,7 @@ typealias float32 Cfloat
typealias float64 Cdouble
typealias int64 Clonglong
typealias uInt64 Culonglong
typealias bool32 uInt32
typealias bool32 Bool32
typealias TaskHandle Ptr{Void}
typealias CalHandle uInt32
typealias DAQmxEveryNSamplesEventCallbackPtr Ptr{Void}
Expand Down
88 changes: 44 additions & 44 deletions src/counter.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
function count_edges(channel::ASCIIString;
edge::String="rising", initial_count::Integer=0, direction::String="up")
edge::AbstractString="rising", initial_count::Integer=0, direction::AbstractString="up")
t = CITask()
if edge {"rising", "falling"}
if edge ("rising", "falling")
error("edge must either be \"rising\" or \"falling\"")
end
if direction {"up", "down"}
if direction ("up", "down")
error("direction must either be \"up\" or \"down\"")
end
catch_error( CreateCICountEdgesChan(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
edge == "rising" ? Val_Rising : Val_Falling,
uint32(initial_count),
UInt32(initial_count),
direction == "up" ? Val_CountUp : Val_CountDown) )
t
end

# broken
function measure_duty_cycle(channel::ASCIIString; units::String="seconds")
function measure_duty_cycle(channel::ASCIIString; units::AbstractString="seconds")
t = CITask()
if units == "seconds"
ret = CreateCIPulseChanTime(t.th,
convert(Ptr{Uint8},channel), convert(Ptr{Uint8},""),
pointer(channel), pointer(""),
2.0, 1000.0,
Val_Seconds)
elseif units == "ticks"
ret = CreateCIPulseChanTicks(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
pointer(""),
2.0, 1000.0)
else
error("units must either be \"seconds\" or \"ticks\"")
Expand All @@ -40,59 +40,59 @@ end
function quadrature_input(channel::ASCIIString; z_enable::Bool=true)
t = CITask()
ret = CreateCIAngEncoderChan(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
Val_X4,
reinterpret(Bool32, uint32(z_enable)),
reinterpret(Bool32, UInt32(z_enable)),
0.0,
Val_AHighBHigh,
Val_Ticks,
uint32(1), 0.0,
convert(Ptr{Uint8},""))
UInt32(1), 0.0,
pointer(""))
ret>0 && warn(error(ret))
ret<0 && error(error(ret))
t
end

function line_to_line(channel::ASCIIString;
units::String="seconds", edge1::String="rising", edge2::String="rising")
units::AbstractString="seconds", edge1::AbstractString="rising", edge2::AbstractString="rising")
t = CITask()
if units {"seconds", "ticks"}
if units ("seconds", "ticks")
error("units must either be \"seconds\" or \"ticks\"")
end
if edge1 {"rising", "falling"}
if edge1 ("rising", "falling")
error("edge1 must either be \"rising\" or \"falling\"")
end
if edge2 {"rising", "falling"}
if edge2 ("rising", "falling")
error("edge2 must either be \"rising\" or \"falling\"")
end
catch_error( CreateCITwoEdgeSepChan(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
1.0, 1000.0,
units == "seconds" ? Val_Seconds : Val_Ticks,
edge1 == "rising" ? Val_Rising : Val_Falling,
edge2 == "rising" ? Val_Rising : Val_Falling,
convert(Ptr{Uint8},"")) )
pointer("")) )
t
end

function generate_pulses{T<:Number}(channel::ASCIIString, low::T=2, high::T=2; delay::T=0)
t = COTask()
if T<:FloatingPoint
if T<:AbstractFloat
ret = CreateCOPulseChanTime(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
Val_Seconds,
Val_Low,
convert(Float64,delay),
convert(Float64,low),
convert(Float64,high))
elseif T<:Integer
ret = CreateCOPulseChanTicks(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Uint8},""),
convert(Ptr{Uint8},""),
pointer(channel),
pointer(""),
pointer(""),
Val_Low,
convert(Int32,delay),
convert(Int32,low),
Expand All @@ -109,7 +109,7 @@ function read(t::CITask, channel::ASCIIString, num_samples::Integer = -1)

#function read_counter_scalar(precision::DataType, cfunction::Function)
# data = precision[0]
# ret = cfunction(t, 1.0, convert(Ptr{precision},data), convert(Ptr{Uint32},C_NULL))
# ret = cfunction(t, 1.0, pointer(data), pointer(C_NULL))
# ret>0 && warn("NIDAQmx: $ret")
# ret<0 && error("NIDAQmx: $ret")
# data
Expand All @@ -121,9 +121,9 @@ function read(t::CITask, channel::ASCIIString, num_samples::Integer = -1)
catch_error( cfunction(t.th,
convert(Int32,num_samples),
1.0,
convert(Ptr{precision},data),
convert(Uint32,num_samples),
convert(Ptr{Int32},num_samples_read),
pointer(data),
convert(UInt32,num_samples),
pointer(num_samples_read),
reinterpret(Ptr{Bool32},C_NULL)) )
data = data[1:num_samples_read[1]]
reshape(data, (num_samples, div(length(data),num_samples)))
Expand All @@ -137,10 +137,10 @@ function read(t::CITask, channel::ASCIIString, num_samples::Integer = -1)
convert(Int32,num_samples),
1.0,
Val_GroupByChannel,
convert(Ptr{Float64},high),
convert(Ptr{Float64},low),
convert(Uint32,num_samples),
convert(Ptr{Int32},num_samples_read),
pointer(high),
pointer(low),
convert(UInt32,num_samples),
pointer(num_samples_read),
reinterpret(Ptr{Bool32},C_NULL)) )
high = high[1:num_samples_read[1]]
low = low[1:num_samples_read[1]]
Expand All @@ -150,21 +150,21 @@ function read(t::CITask, channel::ASCIIString, num_samples::Integer = -1)

tmp = channel_type(t.th, channel)
if tmp[2] == Val_CountEdges
data = read_counter_vector(Uint32, ReadCounterU32)
data = read_counter_vector(UInt32, ReadCounterU32)
elseif tmp[2] == Val_PulseTime
data = read_counter_2vectors(Float64, ReadCtrTime)
elseif tmp[2] == Val_PulseTicks
data = read_counter_2vectors(Uint32, ReadCtrTicks)
data = read_counter_2vectors(UInt32, ReadCtrTicks)
elseif tmp[2] == Val_Position_AngEncoder
data = read_counter_vector(Uint32, ReadCounterU32)
data = read_counter_vector(UInt32, ReadCounterU32)
elseif tmp[2] == Val_TwoEdgeSep # might be broken
val = Cint[0]
catch_error( GetCITwoEdgeSepUnits(t.th,
convert(Ptr{Uint8},channel),
convert(Ptr{Int32},val)) )
pointer(channel),
pointer(val)) )
if val[1] == Val_Ticks
data = read_counter_vector(Uint32, ReadCounterU32)
#data = read_counter_scalar(Uint32, ReadCounterScalarU32)
data = read_counter_vector(UInt32, ReadCounterU32)
#data = read_counter_scalar(UInt32, ReadCounterScalarU32)
elseif val[1] == Val_Seconds
data = read_counter_vector(Float64, ReadCounterF64)
#data = read_counter_scalar(Float64, ReadCounterScalarF64)
Expand Down
Loading

0 comments on commit 5fd30b5

Please sign in to comment.