Skip to content

Instantly share code, notes, and snippets.

@AntLouiz
Last active June 3, 2019 22:51
Show Gist options
  • Save AntLouiz/00cb842f7498cf9504451eee98508761 to your computer and use it in GitHub Desktop.
Save AntLouiz/00cb842f7498cf9504451eee98508761 to your computer and use it in GitHub Desktop.
Testing python dll files loading
import time
from ctypes import *
bnt = WinDLL('./BNT36.dll')
bnt.OpenBNT.argtypes = [c_char_p, c_ushort]
bnt.OpenBNT.restype = c_bool
IP = c_char_p(b"192.168.1.4")
PORT = c_ushort(11111)
is_open = bnt.OpenBNT(IP, PORT)
print("IS OPEN {}".format(is_open))
if is_open:
channels = [1, 10, 19, 20]
arr = (c_char * len(channels))()
for i in range(len(channels)):
arr[i] = channels[i]
bnt.ProgramChannels.restype = c_int
n_channels = bnt.ProgramChannels(arr)
if n_channels > 0:
bnt.StartRealAcq.restype = c_bool
bnt.StartCalibAcq = c_bool
started = bnt.StartRealAcq(200, 2, 1, True)
print("STARTED: {}".format(started))
a = c_ubyte()
ie_status = c_ubyte()
n_samples = c_int64()
i_last = c_int64()
n_samples_got = c_int()
short_buffer = (c_short * 4096)()
bufsize = 8192
bnt.GetData.argtypes = [
POINTER(c_ubyte),
POINTER(c_int64),
POINTER(c_int64),
POINTER(c_int),
POINTER(c_long),
c_long
]
bnt.GetData.restype = c_bool
data_buffer = cast(short_buffer, POINTER(c_long))
time.sleep(2)
response = bnt.GetData(
byref(ie_status),
byref(n_samples),
byref(i_last),
byref(n_samples_got),
data_buffer,
bufsize
)
if response:
j=(n_samples_got.value-1)*len(channels)
short_array = (c_short * 4096)
data = short_array.from_address(addressof(data_buffer))
data = [d for d in data]
print("N SAMPLES: {}".format(n_samples.value))
print("N SAMPLES GOT: {}".format(n_samples_got.value))
print(data)
bnt.StopAcquisition()
bnt.CloseBNT()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment