Ive got a similar question to ctypes and array of structs but im not looking to return the structure. Rather, my structure is passed into the function call as a pointer and then i want the values pointed at by the pointer. see below:
from .h:
typedef struct NIComplexNumberF32_struct {
ViReal32 real;
ViReal32 imaginary;
} NIComplexNumberF32;
ViStatus _VI_FUNC niRFSA_FetchIQSingleRecordComplexF32(
ViSession vi,
ViConstString channelList,
ViInt64 recordNumber,
ViInt64 numberOfSamples,
ViReal64 timeout,
NIComplexNumberF32* data,
niRFSA_wfmInfo* wfmInfo);
i have made several attempts, but this was my latest:
import ctypes
class NIComplexNumberF32_struct_data(ctypes.Structure):
_fields_ = [("real", ctypes.c_float),
("imaginary", ctypes.c_float)]
class niRFSA_wfmInfo_struct_data(ctypes.Structure):
_fields_ = [("absoluteInitialX", ctypes.c_double),
("relativeInitialX", ctypes.c_double),
("xIncrement", ctypes.c_double),
("actualSamples", ctypes.c_double),
("offset", ctypes.c_double),
("gain", ctypes.c_double),
("reserved1", ctypes.c_double),
("reserved2", ctypes.c_double)
]
# ViStatus _VI_FUNC niRFSA_FetchIQSingleRecordComplexF32(
# ViSession vi,
# ViConstString channelList,
# ViInt64 recordNumber,
# ViInt64 numberOfSamples,
# ViReal64 timeout,
# NIComplexNumberF32* data,
# niRFSA_wfmInfo* wfmInfo);
#create instances
data = ctypes.POINTER(NIComplexNumberF32_struct_data)()
wfmInfo = ctypes.POINTER(niRFSA_wfmInfo_struct_data)()
dll_path = r"C:\Program Files\IVI Foundation\IVI\bin\NiRFSA_64.dll"
dll = ctypes.cdll.LoadLibrary(dll_path)
dll.niRFSA_FetchIQSingleRecordComplexF32.argtypes =(ViSession,ViString,ViReal64,ViReal64,ViReal64,ctypes.POINTER(NIComplexNumberF32_struct_data),ctypes.POINTER(niRFSA_wfmInfo_struct_data) )
dll.niRFSA_FetchIQSingleRecordComplexF32(handle,bytes('','ascii'),0,1000,1,data,wfmInfo)
Traceback (most recent call last):
RuntimeError: (-1074134952) IVI: (Hex 0xBFFA0058) Null pointer passed for parameter or attribute.
What i want are the real/imag data values from the array of data structure.
I have got to be missing something dumb. Hoping someone can point me in the right direction.
thanks all!!