bicarlsen / easy-biologic

Python library for communicating with Biologic devices.
GNU General Public License v3.0
18 stars 11 forks source link

The ability to switch between ground mode and floating mode #7

Closed KF243 closed 2 years ago

KF243 commented 2 years ago

For multi channels' connection, I need to use floating mode instead of ground mode. How can I switch the mode?

bicarlsen commented 2 years ago

I added the functionlaity for this in commit 6a3481. I do not have an SP-300 which is required to test the functionality. If you do, please test it and let me know if it works.

Test Program

import easy_biologic as ebl
import easy_biologic.lib.ec_lib as ecl

bl = ebl.BiologicDevice( <port> )
bl.connect()

bl.hardware_configuration

bl.channel_configuration( <ch> )
bl.set_channel_configuration( <ch>, ecl.ChannelMode.GROUNDED, ecl.ElectrodeConnection.STANDARD )

I haven't tested to check if this program works correctly, so you may have to debug.

KF243 commented 2 years ago

easy-biologic 0.3.0.post1 was reinstalled. But TestProgram.py shows the following error.

Exception has occurred: ModuleNotFoundError No module named 'ec_errors' File "C:\Users\kfush\data\TestProgram.py", line 2, in import easy_biologic.ec_lib as ecl

FG1.zip

KF243 commented 2 years ago

Line 2 and line 11 were modified. But TestProgram2.py shows the following error.

Exception has occurred: AttributeError 'BiologicDevice' object has no attribute 'hardware_configuration' File "C:\Users\kfush\data\TestProgram2.py", line 11, in bl.hardware_configuration

FG2.zip

bicarlsen commented 2 years ago

Did you download commit 6a3481 and reinstall the package from the downloaded version?

KF243 commented 2 years ago

C:\Users\kfush>git clone https://github.com/bicarlsen/easy-biologic.git Cloning into 'easy-biologic'... remote: Enumerating objects: 515, done. remote: Counting objects: 100% (515/515), done. remote: Compressing objects: 100% (320/320), done. Receiving objects: 99% (510/515), 10.80remote: Total 515 (delta 308), reused 397 (delta 193), pack-reused 0 MiB/s Receiving objects: 100% (515/515), 11.39 MiB | 1.19 MiB/s, done. Resolving deltas: 100% (308/308), done.

I think the package was successfully installed. But TestProgram2.py shows the same error as follows. Exception has occurred: AttributeError 'BiologicDevice' object has no attribute 'hardware_configuration' File "C:\Users\kfush\data\TestProgram2.py", line 11, in bl.hardware_configuration

bicarlsen commented 2 years ago

After downloading the new commit you need to move into that directory and run pip install . to update Python to use that version. You can run pip list afterwards to ensure it was installed correclty. Next to the name it should give the file path to the downloaded version.

KF243 commented 2 years ago

easy-biologic seems to be in the path correctly as follows. C:\Users\kfush\AppData\Local\Programs\Python\Python39\Lib\site-packages\easy_biologic>pip list Package Version


cycler 0.11.0 DateTime 4.3 easy-biologic 0.3.0.post1 fonttools 4.28.1 kiwisolver 1.3.2 matplotlib 3.5.0 numpy 1.21.4 optosigma 1.0.0 packaging 21.2 pandas 1.3.4 Pillow 8.4.0 pip 21.3.1 pyparsing 2.4.7 pyserial 3.5 python-dateutil 2.8.2 pytz 2021.3 scipy 1.7.2 setuptools 58.1.0 setuptools-scm 6.3.2 six 1.16.0 tomli 1.2.2 zope.interface 5.4.0

What is wrong?

bicarlsen commented 2 years ago

This means you haven't installed the downloaded version. Try installing from commit 118bf5. The new version should be 0.3.1. Try uninstalling the package, then installing the downloaded version by navigating to its folder and running pip install ..

KF243 commented 2 years ago

I could install the version 0.3.1. Next TestProgram2.py shows the following message.

Exception has occurred: EcError
ERR_GEN_NOTCONNECTED (-1): No instrument connected.
  File "C:\Users\kfush\data\TestProgram2.py", line 14, in <module>
    bl.channel_configuration( ch )
bicarlsen commented 2 years ago

This is because in your program ch is defined as a list, but #channel_configuration takes in a single channel as an argument. I have fixed some bugs in commit c6185e which you should download and install for further testing.

KF243 commented 2 years ago

c6185e was committed but it seems no change in the error.

C:\Users\kfush\easy-biologic-c6185e7f82055c1ccc3c6952164e68e40916a956>pip install . Processing c:\users\kfush\easy-biologic-c6185e7f82055c1ccc3c6952164e68e40916a956 Preparing metadata (setup.py) ... done Using legacy 'setup.py install' for easy-biologic, since package 'wheel' is not installed. Installing collected packages: easy-biologic Attempting uninstall: easy-biologic Found existing installation: easy-biologic 0.3.1 Uninstalling easy-biologic-0.3.1: Successfully uninstalled easy-biologic-0.3.1 Running setup.py install for easy-biologic ... done Successfully installed easy-biologic-0.3.1


Exception has occurred: TypeError list indices must be integers or slices, not list File "C:\Users\kfush\data\TestProgram2.py", line 14, in bl.channel_configuration( ch )

bicarlsen commented 2 years ago

You are likely still passing a list to channel_configuration, but only a single channel should be passed. e.g. bl.channel_configuration( 0 ).

KF243 commented 2 years ago

TestProgram21.py shows the following.

Exception has occurred: EcError
ERR_GEN_FUNCTIONFAILED (-6): Function failed.
  File "C:\Users\kfush\data\TestProgram21.py", line 16, in <module>
    bl.set_channel_configuration( 0, ecl.ChannelMode.GROUNDED, ecl.ElectrodeConnection.STANDARD )

FG3.zip

bicarlsen commented 2 years ago

I added a new upate in commit 8a016b. See if that helps.

Can you also print out the results from the other calls (i.e. .hardware_configuration and #channel_configuration) to ensure those are giving sensible results.

KF243 commented 2 years ago

C:\Users\kfush\easy-biologic-8a016bc65869a48556c0c115e8f42ba851882e09>pip install easy-biologic Collecting easy-biologic Using cached easy_biologic-0.3.0.post1-py3-none-any.whl (23.7 MB) Installing collected packages: easy-biologic Successfully installed easy-biologic-0.3.0.post1

This version is OK? The following .py programs in /Lib/site-packages/easy_biologic folder show problems in VSCode.

In biologic_device.py, "tech" is not defined Pylance(reportUndefinedVariable) [269, 38] In data_parser.py, Import "ec_lib" could not be resolved Pylance(reportMissingImports) [12, 8] In ec_lib.py, Import "ec_errors" could not be resolved Pylance(reportMissingImports) [53, 6], "err" is not defined Pylance(reportUndefinedVariable) [639, 12] and [717, 12]

bicarlsen commented 2 years ago

No, it should be version 0.3.1.

KF243 commented 2 years ago

Successfully installed easy-biologic-0.3.1

Now, TestProgram21.py can understand bl.hardware_configuration, but shows a new error as follows,

Exception has occurred: EcError
ERR_GEN_NOTCONNECTED (-1): No instrument connected.
  File "C:\Users\kfush\data\TestProgram21.py", line 15, in <module>
    bl.channel_configuration( 0 )

FG3.zip

bicarlsen commented 2 years ago

Can you try running another command to ensure the device is connected properly. Perhaps print out the device's id with bl.idn or something similar. Can you also please print out the results of each call to check if everything is okay.

KF243 commented 2 years ago

TestProgram22.py shows the followings.

Exception has occurred: EcError
ERR_GEN_FUNCTIONFAILED (-6): Function failed.
  File "C:\Users\kfush\data\TestProgram22.py", line 17, in <module>
    bl.set_channel_configuration( 0, ecl.ChannelMode.GROUNDED, ecl.ElectrodeConnection.STANDARD )

and in terminal,

PS C:\Users\kfush\data>  c:; cd 'c:\Users\kfush\data'; & 'C:\Users\kfush\AppData\Local\Programs\Python\Python39\python.exe' 'c:\Users\kfush\.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\lib\python\debugpy\launcher' '60427' '--' 'c:\Users\kfush\data\TestProgram22.py'
device id = 2

FG4.zip

bicarlsen commented 2 years ago

Can you please print out the results of bl.hardware_configuration and bl.channel_configuration( <ch> ) as well.

KF243 commented 2 years ago

I am not sure how to print out the result. But TestPrograms show the attached messages at terminal.

FG5.zip

bicarlsen commented 2 years ago

Please try the code in commit 8c4c30.

bicarlsen commented 2 years ago

I was able to test the code in commit f8e1350 on our own machine and everything seems to work. Can you please confirm.

KF243 commented 2 years ago

commit 8c4c30 was uploaded but TestProgram shows "No instrument connected". How do you test the code in commit f8e1350 which seems a part of class HardwareConf( c.Structure )?

'idn' in ec_lib.py seems to be the connection id of the device, "2". Why is it 2 instead of others?

bicarlsen commented 2 years ago

If it is saying No instrument connected you may have a connectivity issue. You can always try running something like bl.idn to ensure a connection has been established.

You can use this link to more easily download the code in commit f8e1350.

The ID of the device isn't important, it makes it so you can communicate with more than one Biologic device from the same computer. If I remember correctly though, the reason it starts at '2' is because the controlling computer is considered device '1'.

KF243 commented 2 years ago

After restart VSCode, "No instrument connected" was not shown. But TestProgram223.py shows a new error message.

PS C:\Users\kfush\data> & C:/Users/kfush/AppData/Local/Programs/Python/Python39/python.exe c:/Users/kfush/data/TestProgram223.py
Traceback (most recent call last):
  File "c:\Users\kfush\data\TestProgram223.py", line 12, in <module>
    bl.set_channel_configuration( 0, ecl.ChannelMode.GROUNDED, ecl.ElectrodeConnection.STANDARD )
  File "C:\Users\kfush\AppData\Local\Programs\Python\Python39\lib\site-packages\easy_biologic\device.py", line 280, in set_channel_configuration
    ecl.set_hardware_configuration( self.idn, ch, mode, connection )
  File "C:\Users\kfush\AppData\Local\Programs\Python\Python39\lib\site-packages\easy_biologic\lib\ec_lib.py", line 933, in set_hardware_configuration
    validate( err )
  File "C:\Users\kfush\AppData\Local\Programs\Python\Python39\lib\site-packages\easy_biologic\lib\ec_lib.py", line 1566, in validate
    raise EcError( err )
easy_biologic.lib.ec_errors.EcError: ERR_GEN_FUNCTIONFAILED (-6): Function failed.
PS C:\Users\kfush\data>

Why bl.set_channel_configuration( 0, ecl.ChannelMode.GROUNDED, ecl.ElectrodeConnection.STANDARD ) is not suitable for ecl.set_hardware_configuration( self.idn, ch, mode, connection )?

bicarlsen commented 2 years ago

I don't believe I have TestProgram223.py. Are you sure you updated the code to the new version?

KF243 commented 2 years ago

Sorry. Find TestProgram223.py in the attachment.

FG6.zip

bicarlsen commented 2 years ago

It appears you are calling the functions correctly. I suggest printing out each call to make sure you are getting sensible results. Please also make sure you have commit f8e1350 installed.

KF243 commented 2 years ago

How can I print out each call using VSCode?

bicarlsen commented 2 years ago

Just by wrapping the result in a print() statment. e.g. print( bl.idn )

KF243 commented 2 years ago

Terminal comment of TestProgram224.py was printed out.

FG7.zip

bicarlsen commented 2 years ago

The output doesn't seem to have any output, but is just the same program.

KF243 commented 2 years ago

Sorry. Check the .txt file in re-attached.

FG7.zip

bicarlsen commented 2 years ago

It appears you don't have the correct version of the code installed. Please try removing the package, and reinstalling from commit f8e1350.

You can ensure the correct version of the code is installed by printing out bl.channel_configuration( 0 ) and ensureing it looks like HardwareConfiguration(connection=<ElectrodeConnection.STANDARD: 0>, mode=<ChannelMode.FLOATING: 1> instead of <easy_biologic.lib.ec_lib.HardwareConf object at 0x0000028972C99040>

KF243 commented 2 years ago

This time, zip file was used for installing commit f831350 instead of "git clone https://github.com/bicarlsen/easy-biologic.git". Anyways, the followings are shown and it seems to be OK. PS C:\Users\kfush\data> & C:/Users/kfush/AppData/Local/Programs/Python/Python39/python.exe c:/Users/kfush/data/TestProgram224.py 6- None 7- {0: HardwareConfiguration(connection=<ElectrodeConnection.STANDARD: 0>, mode=<ChannelMode.GROUNDED: 0>), 1: HardwareConfiguration(connection=<ElectrodeConnection.STANDARD: 0>, mode=<ChannelMode.GROUNDED: 0>)} 11- HardwareConfiguration(connection=<ElectrodeConnection.STANDARD: 0>, mode=<ChannelMode.GROUNDED: 0>) 12- None 13- HardwareConfiguration(connection=<ElectrodeConnection.STANDARD: 0>, mode=<ChannelMode.GROUNDED: 0>) 14- None PS C:\Users\kfush\data>

KF243 commented 2 years ago

I want to use in FLOATNG mode instead of GROUND mode. However, currently, channel mode cannot be changed to FLOATING.

FG8.zip

bicarlsen commented 2 years ago

Great! It appears to be almost working now.

I think this may have been a bug where I accientally switched the two parameters somewhere. Please try commit 541b183.

KF243 commented 2 years ago

It becomes worse. Check the result text. Anyway, which do I download a new commit, via zip file or via git? The errors are not same.

TestProgram226_printout_version2.txt

bicarlsen commented 2 years ago

It appears that the output you sent and the previous one are the same, so I think the code didn't update. I don't know what you mean by "it becomes worse".

The best way to update the code is to use git pull <remote_name> <branch_name> then ensure you have checkouted the correct branch. In this case you want to use the brnach hardware_conf so the command will look something like git pull origin hardware_conf & git checkout hardware_conf. However I leave it to you to ensure you are one the correct branch by comparing the commit ID. You can do this using git log. If these are unfamiliar to you, I suggest doing a tutorial on basic git commands and usage.

KF243 commented 2 years ago

TestProgram226.py with easy-biologic downloaded (correctly, installed via .zip file) the latest hardware_conf (b8bfd1c) results in showing EM_b8bfd1c_TestProgram226py.txt. Then I tried to reinstall commit f8e1350 from this issue, but it seems to be changed and the same as b8bfd1c.

Easy-biologic-hardware_conf_OK, which is the previous commit downloaded via .zip previous commit, shows the result of OK_TestProgram226py.txt as previously reported, although I cannot find and download the same commit from your github now.

FG9.zip

technologies.zip

OK_without_technologiesInEasy-Biologic.zip

bicarlsen commented 2 years ago

Sorry about that. I fixed the errors in commit 14615aa.

KF243 commented 2 years ago

FLOATING mode are available now. Thank you. I will use this "set_channel_configuration" for SECM operation.

bicarlsen commented 2 years ago

Great :) Glad we finally got it working.

I've included the changes in version 0.3.1 of the package