Skip to content

Commit

Permalink
Merge pull request #2 from microdaq/1.1.1v
Browse files Browse the repository at this point in the history
1.2.0v
  • Loading branch information
witczenko committed Mar 1, 2018
2 parents 2cb0e17 + 75dcea5 commit 193e147
Show file tree
Hide file tree
Showing 10 changed files with 526 additions and 71 deletions.
Binary file added install/py_mlink/MLink32.dll
Binary file not shown.
Binary file added install/py_mlink/MLink32.so
Binary file not shown.
Binary file added install/py_mlink/MLink64.dll
Binary file not shown.
Binary file added install/py_mlink/MLink64.so
Binary file not shown.
102 changes: 75 additions & 27 deletions install/py_mlink/PyMLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,39 @@ def reconnect(self):
self.connect(self._ip)

@_connect_decorate
def get_version(self):
def get_fw_version(self):
'''
Description:
Returns version of MicroDAQ firmware
Usage:
(major, minor, fix, build) = get_fw_version()
'''
major = c_int()
minor = c_int()
fix = c_int()
build = c_int()

res = cml.mlink_fw_version(pointer(self._linkfd), pointer(major), pointer(minor), pointer(fix), pointer(build))
self._raise_exception(res)

return (major.value, minor.value, fix.value, build.value)

def get_lib_version(self):
'''
Description:
Returns version of MLink library
Usage:
get_version()
(major, minor, fix, build) = get_lib_version()
'''
return cml.mlink_version(pointer(self._linkfd))
major = c_int()
minor = c_int()
fix = c_int()
build = c_int()

res = cml.mlink_lib_version(pointer(self._linkfd), pointer(major), pointer(minor), pointer(fix), pointer(build))
self._raise_exception(res)

return (major.value, minor.value, fix.value, build.value)

def hw_info(self):
'''
Expand All @@ -163,29 +188,64 @@ def hw_info(self):

# ------------ DSP FUNCTIONS ------------
@_connect_decorate
def dsp_load(self, dsp_firmware, param=''):
def dsp_run(self, dsp_firmware, step_time):
'''
Description:
Loads DSP program
Executes DSP program
Usage:
dsp_load(dsp_firmware, param='')
dsp_firmware - XCos generated DSP application path
param - optional parameters
dsp_run(dsp_firmware, step_time)
dsp_firmware - XCos generated DSP application
step_time - custom model mode step or -1 to keep Xcos settings
'''
res = cml.mlink_dsp_load(pointer(self._linkfd), dsp_firmware, param)
res = cml.mlink_dsp_run(pointer(self._linkfd), dsp_firmware, step_time)
self._raise_exception(res)

@_connect_decorate
def dsp_start(self):
def dsp_mem_write(self, index, data):
'''
Description:
Starts DSP program
Writes data to MicroDAQ memory which can be accessed
via MEM read block in XCOS model.
Usage:
dsp_start()
dsp_mem_write(index, data)
index - memory index
data - data to be written
'''

if not isinstance(data, list):
data = [data]

data_c = c_float * len(data)
data_c = data_c(*data)

res = cml.mlink_dsp_mem_write(pointer(self._linkfd), index, len(data), data_c)
self._raise_exception(res)

@_connect_decorate
def dsp_signal_read(self, signal_id, vector_size, vector_count, timeout=1000):
'''
res = cml.mlink_dsp_start(pointer(self._linkfd))
Description:
Reads DSP signal
Usage:
data = dsp_signal_read(signal_id, vector_size, vector_count, timeout=1000)
signal_id - SIGNAL block identification number from XCOS model.
vector_size - SIGNAL block data size.
vector_count - vectors to read.
timeout - maximum amount of time to wait for data in miliseconds
'''
data_size = vector_size*vector_count
data = c_double *(data_size)
data = data()
res = cml.mlink_dsp_signal_read(signal_id, vector_size, byref(data), data_size, timeout)
self._raise_exception(res)

val_list = []

for vec in xrange(0, vector_count):
val_list.append([data[i] for i in xrange(0, vector_size)])

return val_list

@_connect_decorate
def dsp_stop(self):
'''
Expand All @@ -196,19 +256,7 @@ def dsp_stop(self):
'''
res = cml.mlink_dsp_stop(pointer(self._linkfd))
self._raise_exception(res)

# TODO: doc - validate
@_connect_decorate
def dsp_upload(self):
'''
Description:
Uploads DSP program to MicroDAQ memory.
DSP program will be loaded automatically after device reboot.
Usage:
dsp_upload()
'''
res = cml.mlink_dsp_upload(pointer(self._linkfd))
self._raise_exception(res)

# ------------ DIGITAL IO FUNCTIONS ------------
@_connect_decorate
Expand Down Expand Up @@ -419,14 +467,14 @@ def ai_read(self, channels, ai_range=AIRange.AI_10V, is_differential=False):
for i in range(len(channels) - 1):
is_differential = is_differential + is_differential_cpy
elif len(channels) != len(is_differential):
raise MLinkError('ai_scan_init: Mode (is_differential parameter) vector should match selected AI channels')
raise MLinkError('ai_read: Mode (is_differential parameter) vector should match selected AI channels')

if len(ai_range) == 2 and len(channels) != 1:
range_cpy = ai_range
for i in range(len(channels)-1):
ai_range = ai_range + range_cpy
elif len(channels) != len(ai_range) / 2:
raise MLinkError('ai_scan_init: Range vector should match selected AI channels!')
raise MLinkError('ai_read: Range vector should match selected AI channels!')

channels_idx = c_int8 * len(channels)
channels_idx = channels_idx(*channels)
Expand Down
63 changes: 38 additions & 25 deletions install/py_mlink/ctypes_mlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,19 @@ def add_library_search_dirs(other_dirs):

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 37
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_version'):
if not hasattr(_lib, 'mlink_fw_version'):
continue
mlink_version = _lib.mlink_version
mlink_version.argtypes = [POINTER(c_int)]
if sizeof(c_int) == sizeof(c_void_p):
mlink_version.restype = ReturnString
else:
mlink_version.restype = String
mlink_version.errcheck = ReturnString
mlink_fw_version = _lib.mlink_fw_version
mlink_fw_version.argtypes = [POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int)]
mlink_fw_version.restype = c_int
break

for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_lib_version'):
continue
mlink_lib_version = _lib.mlink_lib_version
mlink_lib_version.argtypes = [POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int)]
mlink_lib_version.restype = c_int
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 38
Expand Down Expand Up @@ -666,40 +670,49 @@ def add_library_search_dirs(other_dirs):
mlink_disconnect_all.restype = c_void
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 44
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_dsp_load'):
if not hasattr(_lib, 'mlink_dsp_run'):
continue
mlink_dsp_load = _lib.mlink_dsp_load
mlink_dsp_load.argtypes = [POINTER(c_int), String, String]
mlink_dsp_load.restype = c_int
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 45

#EXTERNC MDAQ_API int mlink_dsp_run(int *link_fd, const char *dsp_binary_path, double period);
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_dsp_start'):
if not hasattr(_lib, 'mlink_dsp_run'):
continue
mlink_dsp_start = _lib.mlink_dsp_start
mlink_dsp_start.argtypes = [POINTER(c_int)]
mlink_dsp_start.restype = c_int
mlink_dsp_run = _lib.mlink_dsp_run
mlink_dsp_run.argtypes = [POINTER(c_int), String, c_double]
mlink_dsp_run.restype = c_int
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 46
#EXTERNC MDAQ_API int mlink_dsp_signal_read(int signal_id, int signal_size, double *data, int data_size, int timeout);
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_dsp_stop'):
if not hasattr(_lib, 'mlink_dsp_signal_read'):
continue
mlink_dsp_stop = _lib.mlink_dsp_stop
mlink_dsp_stop.argtypes = [POINTER(c_int)]
mlink_dsp_stop.restype = c_int
mlink_dsp_signal_read = _lib.mlink_dsp_signal_read
mlink_dsp_signal_read.argtypes = [c_int, c_int, POINTER(c_double), c_int, c_int]
mlink_dsp_signal_read.restype = c_int
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 47
#EXTERNC MDAQ_API int mlink_dsp_mem_write(int *link_fd, int start_idx, int len, float *data);
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_dsp_upload'):
if not hasattr(_lib, 'mlink_dsp_mem_write'):
continue
mlink_dsp_upload = _lib.mlink_dsp_upload
mlink_dsp_upload.argtypes = [POINTER(c_int)]
mlink_dsp_upload.restype = c_int
mlink_dsp_mem_write = _lib.mlink_dsp_mem_write
mlink_dsp_mem_write.argtypes = [POINTER(c_int), c_int, c_int, POINTER(c_float)]
mlink_dsp_mem_write.restype = c_int
break

#EXTERNC MDAQ_API int mlink_dsp_stop(int *link_fd );
for _lib in _libs.itervalues():
if not hasattr(_lib, 'mlink_dsp_stop'):
continue
mlink_dsp_stop = _lib.mlink_dsp_stop
mlink_dsp_stop.argtypes = [POINTER(c_int)]
mlink_dsp_stop.restype = c_int
break

# /home/witczenko/Downloads/Scilab-master/microdaq/etc/mlink/MLink/MLink2.h: 50
Expand Down
23 changes: 4 additions & 19 deletions install/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,23 @@
print 'This platform is not supported!'
sys.exit()

# Download needed binaries
mlink_lib = lib_ver+lib_ext
pack_data = {PYMLINK_VERSION: [mlink_lib]}

try:
url = "https://github.com/microdaq/MLink/raw/master/"+mlink_lib

print 'Downloading MLink library from ' + url
bin = urllib2.urlopen(url)

mlink_lib = lib_prefix + mlink_lib
with open(os.path.normpath(PYMLINK_VERSION+'/'+mlink_lib), 'wb') as output:
output.write(bin.read())
print '...done.'
except:
print 'Cannot download MLink library. Check your internet connection and try again.'
sys.exit()

# if linux then copy lib to standard location
if os_name == 'Linux':
pack_data = {}
linux_lib_path = '/usr/lib/'
try:
print 'Moving file '+PYMLINK_VERSION+'/'+mlink_lib+' to '+linux_lib_path
shutil.move(os.path.normpath(PYMLINK_VERSION+'/'+mlink_lib), os.path.normpath(linux_lib_path+mlink_lib))
print 'copying file '+PYMLINK_VERSION+'/'+mlink_lib+' to '+linux_lib_path
shutil.copy(os.path.normpath(PYMLINK_VERSION+'/'+mlink_lib), os.path.normpath(linux_lib_path+'lib'+mlink_lib))
except:
print '...failed.'
sys.exit()

tmp_dir = ''
setup(name='PyMLink',
version='1.1',
version='1.1.1',
author='Lukas Wit',
author_email='lukas.w@embedded-solutions.pl',
url='www.microdaq.org',
Expand All @@ -85,4 +70,4 @@
shutil.rmtree('build')
print '...done.'
except:
print '...failed.'
print '...failed.'

0 comments on commit 193e147

Please sign in to comment.