Home > Mobile >  .NET methods in python (conversion from matlab code) - Delsys EMGWorks
.NET methods in python (conversion from matlab code) - Delsys EMGWorks

Time:11-05

I have a script in Matlab, which accesses a DLL and allows me to utilize the methods to import and analyse data programmatically. However, I would like to convert it to python. I have looked at using pythonnet, but I cannot get it to work. Can anyone suggest a way of replicating this behaviour in python?

Ths example is specific to Delsys and their EMGWorks software.

%locate HPF DLL within EMGworks install folder
path = ['C:\Program Files (x86)\pathtoDLL\HPF.dll'];

%make HPF assembly visible to MATLAB
NET.addAssembly(path);

%locate target HPF file
curFile = 'C:\TestFiles\MyTestFile.hpf';

%construct HPF reader
myHPFreader = HPF.HPFReader(curFile);

%invoke “GetAllSampleRates” method on HPF reader object “myHPFreader”
mySampleRates = myHPFreader.GetAllSampleRates;

CodePudding user response:

The key it seems is knowing the structure of the dll so you can instantiate the class. I looked at the Matlab docs to work this out.

1. Install Python.net

pip install pythonnet

2. Import package and make package available to Python

import clr
clr.AddReference('C:\Program Files (x86)\Delsys, Inc\EMGworks\Matlab Conversion Library \HPF.dll')

3. Instantiate class object

This was initially confusing for me. But it seems that the name of the DLL will be the name of the package. In my case the .dll is HPF.dll so my package name is HPF.

from HPF import HPFReader
emg_file  = HPFReader(<filename>)

4. Utilise methods from table in matlab docs to get file info and print it out

channel_names = data.GetAllChannelNames()

for channel in channel_names:
    print(channel)

CodePudding user response:

Thanks Tim!

I made one small change to the great example you provided!

channel_names = emg_file.GetAllChannelNames()

The emg_file change matched the variable.

  • Related