Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError of IP address #61

Open
DangerLin opened this issue May 29, 2023 · 5 comments
Open

TypeError of IP address #61

DangerLin opened this issue May 29, 2023 · 5 comments
Assignees

Comments

@DangerLin
Copy link

Hi there! When I tried to use the bio_logic module to control my potentiostat (SP-150e), it returned an error message saying TypeError. The script I used is from the test example of the package. And I am quite sure I have typed the IP address correctly as a string.
Could anyone help me with this issue? Thanks a lot!

Traceback (most recent call last): File "D:\Scripts\test.py", line 310, in <module> test_cv_technique() File "D:\Scripts\test.py", line 166, in test_cv_technique sp150.connect() File "D:\Anaconda\envs\test_env_EClab\lib\site-packages\PyExpLabSys\drivers\bio_logic.py", line 260, in connect address = create_string_buffer(self.address) File "D:\Anaconda\envs\test_env_EClab\lib\ctypes\__init__.py", line 66, in create_string_buffer raise TypeError(init) TypeError: 192.168.72.01

@KennethNielsen KennethNielsen self-assigned this Aug 9, 2023
@KennethNielsen
Copy link
Member

Hi @DangerLin

I missed this in the inbox before vacation. If this is still a problem, can you share the code you use to connect?

@JustAnEmployee
Copy link

JustAnEmployee commented Aug 29, 2023

Hi @KennethNielsen I've got the same issue with this issue.

C:\Users\wan376\AppData\Local\Programs\Python\Python311\python.exe C:/Users/wan376/PycharmProjects/faster2/Potentiostat/test_potentiostat.py
Traceback (most recent call last):
  File "C:\Users\wan376\PycharmProjects\faster2\Potentiostat\test_potentiostat.py", line 57, in <module>
    run_ocv()
  File "C:\Users\wan376\PycharmProjects\faster2\Potentiostat\test_potentiostat.py", line 12, in run_ocv
    sp150.connect()
  File "C:\Users\wan376\PycharmProjects\faster2\Potentiostat\bio_logic_driver.py", line 262, in connect
    address = create_string_buffer(self.address)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\wan376\AppData\Local\Programs\Python\Python311\Lib\ctypes\__init__.py", line 66, in create_string_buffer
    raise TypeError(init)
TypeError: 192.168.0.257

The code I ran was a copy paste of the example code from read the docs.

def run_ocv():
    """Test the OCV technique"""
    ip_address = '192.168.0.257'  # REPLACE THIS WITH A VALID IP
    # ip_address = 'USB0'
    # Instantiate the instrument and connect to it
    sp150 = SP150(ip_address)
    sp150.connect()

    # Instantiate the technique. Make sure to give values for all the
    # arguments where the default values does not fit your purpose. The
    # default values can be viewed in the API documentation for the
    # technique.
    ocv = OCV(rest_time_T=0.2,
              record_every_dE=10.0,
              record_every_dT=0.01)

    # Load the technique onto channel 0 of the potentiostat and start it
    sp150.load_technique(0, ocv)
    sp150.start_channel(0)

The point at which the code failed was

# Communications functions
    def connect(self, timeout=5):
        address = create_string_buffer(self.address)

I'm running python 3.11.4 in a windows environment.

@DangerLin
Copy link
Author

Hi @DangerLin

I missed this in the inbox before vacation. If this is still a problem, can you share the code you use to connect?

Hi Kenneth, my code is attached below:

from __future__ import print_function
from pprint import pprint
import time
from PyExpLabSys.drivers.bio_logic import SP150, CV

ip_address = '169.254.72.33'

#data save path
save_path = 'D:\Data\EC lab\Danger\20230527\epx_1.csv' # file name is to be defined.

def test_cv_technique():
    """Test the CV technique"""
    import matplotlib.pyplot as plt
    sp150 = SP150(ip_address)
    sp150.connect()
    cv_ = CV(vs_initial=(True,) * 5,
             voltage_step=(0.0, 0.5, -0.7, 0.0, 0.0),
             scan_rate=(100.0,) * 2,
             record_every_dE=0.01,
             N_cycles=1)
    sp150.load_technique(0, cv_)

    sp150.start_channel(0)
    ew_ = []
    ii_ = []
    run_time = []
    try:
        while True:
            time.sleep(0.1)
            data_out = sp150.get_data(0)
            if data_out is None:
                break
            print(data_out.technique)
            print('Ewe:', data_out.Ewe)
            print('I:', data_out.I)
            print('time/s', data_out.time)
            ew_ += data_out.Ewe
            ii_ += data_out.I
            run_time += data_out.time
            print('cycle:', data_out.cycle)
    except KeyboardInterrupt:
        sp150.stop_channel(0)
        sp150.disconnect()
    else:
        sp150.stop_channel(0)
        sp150.disconnect()
    plt.plot(ew_, ii_)
    plt.show()
    print('end')
    
    CV.save_data(save_path)

if __name__ == '__main__':
    test_cv_technique()

@DangerLin
Copy link
Author

JustAnEmployee

Hi, sir, if you have a solution, could you please let me know? Thank you!

@KennethNielsen
Copy link
Member

Sorry, for the slow answer time. This seems to be a signature that changed over time, maybe after the whole Python2/3 debacle. The create_string_buffer function now expects bytes not str. So, if that is the only place where the IP-address is used, you could make a workaround by converting your IP-address to bytes before sending it into the class. Something like:

ip_address = "192.168.1.2".encode("ascii")

if this works, I will make a fix around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants