Copies data from an array into a Windows memory buffer.
win_array_to_buf(data_array, memhandle, first_point, count)
data_array (POINTER(c_ushort))
The C array containing the data to be copied
memhandle (int)
This must be a memory handle that was returned by win_buf_alloc() when the buffer was allocated. The data will be copied into this buffer.
first_point (int)
Index of the first point in the memory buffer where data will be copied to.
count (int)
Number of data points to copy.
From pyul import ul
count = 1000
# Allocate the buffer and cast it to an unsigned short
memhandle = ul.win_buf_alloc(count)
data_array = ctypes.cast(memhandle, ctypes.POINTER(ctypes.c_ushort))
# Calculate and store the waveform
for i in range(0, count):
data_array[i] = 2047 * (1.0 + math.sin(6.2832 * i / count))
# Output the waveform
ul.a_out_scan(0, 0, 0, count, 100, ULRange.BIP5VOLTS, memhandle, 0)
# Free the buffer and set the data_array to None
ul.win_buf_free(memhandle)
data_array = None