示例#1
0
from __future__ import print_function
from potentiostat import Potentiostat
import sys
import time

if len(sys.argv) > 1:
    port = sys.argv[1]
else:
    port = '/dev/ttyACM0'

channel_list = [1, 7]
num_sample = 10
sleep_dt = 0.25

dev = Potentiostat(port)
dev.set_volt_range('5V')
dev.set_curr_range('100uA')

dev.set_mux_enabled(True)
dev.set_enabled_mux_channels(channel_list)
dev.set_mux_ref_elect_connected(True)
dev.set_mux_ctr_elect_connected(True)

print()

for channel in channel_list:

    print('testing channel: ', channel)
    print('----------------------------------------------')

    dev.set_mux_wrk_elect_connected(channel)
class ConstVoltLogger(object):
    def __init__(self, param):
        """
        param - dictionary of parameters for the constant voltage test. It
        should contain the following items.

         filename      Data log filename
         port          Potentiostat serial port
         volt_range    Output voltage range
         curr_range    Measurement current range
         sample_dt     Sample period (s)
         volt          # Output voltage (V)

        """
        self.param = param
        self.done = False
        self.sep = ','

        self.pstat = Potentiostat(self.param['port'])
        self.pstat.set_volt_range(self.param['volt_range'])
        self.pstat.set_curr_range(self.param['curr_range'])
        self.pstat.set_volt(self.param['volt'])

        self.scheduler = sched.scheduler(time.time, time.sleep)
        self.scheduler_event = None
        signal.signal(signal.SIGINT, self.sigint_handler)

    def get_file_start_time(self):
        t_start_file = None
        if os.path.exists(self.param['filename']):
            line_list = []
            with open(self.param['filename'], 'r') as fid:
                try:
                    line_list = fid.readlines()
                    start_line = line_list[0]
                    start_line = start_line.split(self.sep)
                    t_start_file = float(start_line[0])
                except:
                    pass
        return t_start_file

    def run(self):
        self.done = False
        t_start = time.time()
        t_start_file = self.get_file_start_time()
        if t_start_file is None:
            t_start_file = t_start

        print()
        print('press ctl-c to exit')
        print()
        print('t (s), current (A)')
        print('------------------')

        with open(self.param['filename'], 'a') as fid:
            cnt = 0
            while not self.done:
                curr = self.pstat.get_curr()
                t_current = time.time()
                t_elapsed = t_current - t_start_file

                fid.write('{0}{1} {2}{3}'.format(t_current, self.sep, curr,
                                                 os.linesep))
                print('{0:1.2f}{1} {2:1.4f}'.format(t_elapsed, self.sep, curr))

                t_next = t_start + (cnt + 1) * self.param['sample_dt']
                self.scheduler_event = self.scheduler.enterabs(
                    t_next, 1, lambda: None, ())
                self.scheduler.run()
                cnt += 1

    def sigint_handler(self, signum, frame):
        self.scheduler.cancel(self.scheduler_event)
        self.done = True
示例#3
0
    t1 = 50.0  # Transition stop time (s)

    v0 = -0.9  # Initial voltage (V)
    v1 = 1.2  # Final voltage (V)

    amp = 0.1  # Sinusoid ampliude (V)
    per = 2.0  # Sinusoid period (s)

    dt = 0.05  # Time step for setting voltage and measurements
    t_total = 60.0  # Total experiment duration

    volt_func = create_sin_linear_func(t0, t1, v0, v1, amp, per)

    # Create device object, set voltage/current ranges and run test
    pstat = Potentiostat('/dev/ttyACM0')
    pstat.set_volt_range('2V')
    pstat.set_curr_range('100uA')
    t, volt, curr = run_manual_test(pstat, volt_func, dt, t_total)

    # Plot results
    plt.subplot(211)
    plt.plot(t, volt)
    plt.ylabel('potential (V)')
    plt.grid('on')

    plt.subplot(212)
    plt.plot(t, curr)
    plt.xlabel('time (s)')
    plt.ylabel('current (uA)')
    plt.grid('on')
    plt.show()
示例#4
0
curr_range = dev.get_curr_range()
print('volt range: {0}'.format(curr_range))

curr_range = dev.set_curr_range(new_curr_range)
print('volt range: {0}'.format(curr_range))

curr_range = dev.get_curr_range()
print('volt range: {0}'.format(curr_range))
print()



# Set voltage range. 
# --------------------------------------------------------------------
# Note, this is only need for manual operation as the voltage range is 
# automatically set from the parameters when running tests.

new_volt_range = "5V"
volt_range = dev.get_volt_range()
print('volt range: {0}'.format(volt_range))

volt_range = dev.set_volt_range(new_volt_range)
print('volt range: {0}'.format(volt_range))

volt_range = dev.get_volt_range()
print('volt range: {0}'.format(volt_range))
print()