I am trying to control a National Instruments PXI oscilloscope using Julia by calling the provided .dlls
.
So far I managed to initialize the communication with the instrument, configure some settings and almost finished the Fetch
function for reading waveforms. I store the waveform in a simple Array{Float64,1}
The problem is, whenever I try to plot that array, or serialize it to disk, Julia crashes (I am on Windows, I don’t know how to log the crash report, but there are some errors printed on console in the second before Julia closes).
My code is the following:
ViStatus = Int32
ViSession = UInt32
ViConstString = Ptr{UInt8}
ViReal64 = Float64
ViInt32 = Int32
sym = Libdl.dlsym(lib, :niScope_Fetch)
channelList = [UInt8.(collect("0")); UInt8(0)] # terminate with NULL char
timeout = 0.0
npts = 1000
numSamples = Int32(npts)
struct niScope_wfmInfo
relativeInitialX::Float64
absoluteInitialX::Float64
xIncrement::Float64
actualSamples::Int32
gain::Float64
offset::Float64
end
wfmInfo = niScope_wfmInfo(0.0, 0.0, 0.0, Int32(0), 1.0, 0.0)
PwfmInfo = Ref(wfmInfo) # pointer to struct to be passed to ccall
wfm = Vector{Float64}(undef, npts) # arg type is pointer but one needs to pass the array
status = ccall(sym, ViStatus,
(ViSession, ViConstString, ViReal64, ViInt32, Ptr{Array{Float64,1}}, Ptr{niScope_wfmInfo}) ,
scope_obj, channelList, timeout, numSamples, wfm, PwfmInfo)
plot(wfm)
Am I missing something?
It’s the first time I use ccall and my experience with C is almost zero.