No.15
That's my number
- Joined
- Jun 29, 2020
- Messages
- 123
And is willing to help me with a script? I am trying to test batteries with a DC load bank that understands some scpi.
I know nothing about programming and put together a script that I mostly copied from magnaload. Obviously it does not work, but it connects to the load and opened an empty graph at the end. What I am looking to do is capacity test batteries. Once I get it right I will offer capacity testing for free for anyone in my area.
remember don't laugh this is from someone who knows nothing about python
I know nothing about programming and put together a script that I mostly copied from magnaload. Obviously it does not work, but it connects to the load and opened an empty graph at the end. What I am looking to do is capacity test batteries. Once I get it right I will offer capacity testing for free for anyone in my area.
remember don't laugh this is from someone who knows nothing about python
Python:
# Import plotting library Matplotlib
# Import .csv parser
# Import socket
# Import time: Time access and conversions to allow for pausing
# Import numpy for mathemetical manipulation of arrays
import matplotlib.pyplot as plt
import csv, socket, time
import numpy as np
# Create connection object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.10.103', 3000))
# Create an empty numpy data array 999 rows, 4 columns
outputSamples = np.empty([999, 3])
iSample = 0
# Send SCPI commands to set the LOAD
s.sendall(b'MODe:CURRENT\n')
s.sendall(b'ISET 2\n')
s.sendall (b'VOLTage:PROTection:UNDer:STATe ON\n')
s.sendall (b'VOLT:PROT:UND 12.8\n')
# Send SCPI command to enable the DC input
s.sendall(b'INPUT ON\n')
# Open data stream to .csv file. .csv has two columns:
# Column 1: Current set point in amperes
# Column 2: Time in seconds
# The first row is headers
with open('example_profile.csv', 'r') as csvfile:
# Read the .csv file using comma (,) as the delimeter
dataset = csv.reader(csvfile, delimiter=',')
# Skip the header row
next(dataset)
# Split the dataset up to rows
rows = list(dataset)
# Create an empty array for measurements, the same length as .csv row numbers
inputSamples = np.empty([len(rows), 2], dtype=float)
# Record the time that the measurements began
testStartTime = time.time()
# Run for loop while there are still rows of data left
for idx, data in enumerate(rows):
# Store row data to array
inputSamples[idx] = [data[0], data[1]]
# Send SCPI command to LOAD to current set point at present row
s.sendall(b'CURR 1\n'.format(data[0]))
# Determine how long the MagnaLOAD should stay at this current set point
stopTime = testStartTime + int(data[1])
# Run while loop while there is still time left
while time.time() < stopTime:
# Send SCPI command to MagnaLOAD to measure all DC input variables
s.sendall('MEAS:CURRENT?\n')
# Get the LOAD's response and split it up into its respective variables
[curr, volt, res, pwr] = (s.readline()).split(',')
# Round measurements and store them to array, along with with time
outputSamples[iSample] = ([round(float(curr), 2), round(float(volt), 2), round(time.time() - testStartTime, 2)])
iSample += 1
time.sleep(0.5)
# Send SCPI command to disable DC input
s.sendall(b'INPUT OFF\n')
# Create a plot series of current vs. time
plt.subplot(2, 1, 1)
plt.plot(outputSamples[0:iSample, 2], outputSamples[0:iSample, 0], 'r--')
plt.ylabel('Output Current(A)')
plt.title('I-V Profile')
# Create a plot series of voltage vs. time
plt.subplot(2, 1, 2)
plt.plot(outputSamples[0:iSample, 2], outputSamples[0:iSample, 1], 'b--')
plt.xlabel('Time (s)')
plt.ylabel('Output Voltage(V)')
# Show the plot
plt.show()