Skip to content

Commit cbf700f

Browse files
authored
Merge pull request #10 from lnw/additionsAndFixes
additional functions, some comments, some typos
2 parents ccad264 + 68b0edd commit cbf700f

File tree

5 files changed

+250
-59
lines changed

5 files changed

+250
-59
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# py-korad
2-
Korad Test & Measurment Equipment Python Library
2+
Korad Test & Measurement Equipment Python Library
33

44
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
55

6-
This is the start of a reposistory to unify the Korad device drivers into a single repository. This is currently under development and notes will be shown below on what support is currently avalible.
6+
This is the start of a repository to unify the Korad device drivers into a single repository. This is currently under development and notes will be shown below on what support is currently avaliable.
77

88
**Check out the Wiki for more info**
99

@@ -12,7 +12,7 @@ This is the start of a reposistory to unify the Korad device drivers into a sing
1212
- USB Interface: Separate USB class added - tested with batteryCurve only.
1313

1414
## KA P Series Power Supplies (ie. KA6003P)
15-
I will most likley pull this from one of the existing Korad Serial libraries.
15+
I will most likely pull this from one of the existing Korad Serial libraries.
1616

1717
## KD P Series Power Supplies
18-
Once I have compaired the SCPI command set between this device and the KA series hopefully we will just be able to unify these into a single class.
18+
Once I have compared the SCPI command set between this device and the KA series hopefully we will just be able to unify these into a single class.

examples/batteryCurve.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
"""This sample program will use the kel103 to test a batteries capacity and
2-
show this information in matplotlib. This method is an aproximation and its resolution
3-
can be increase with sampling rate.
41
"""
5-
import socket
2+
This sample program will use the kel103 to test a battery's capacity and
3+
show this information in matplotlib. This method is an aproximation and its
4+
resolution can be increased with sampling rate.
5+
"""
6+
67
import time
78
import re
89
import matplotlib
@@ -16,11 +17,14 @@
1617
MISSED_LIMIT = 10 # amount of missed samples that is allowed
1718

1819
# setup the device (the IP of your ethernet/wifi interface, the IP of the Korad device)
19-
kel = kel103.kel103("192.168.8.126", "192.168.8.128", 18190)
20+
host_ip = "192.168.x.x"
21+
device_ip = "192.168.x.x"
22+
port = 18190
23+
kel = kel103.kel103(host_ip, device_ip, port)
2024
kel.checkDevice()
2125

2226
# a quick battery test
23-
kel.setOutput(False)
27+
kel.setOutput(False)
2428
voltage = kel.measureVolt()
2529
kel.setCurrent(dischargeRate)
2630
voltageData = []
@@ -33,24 +37,29 @@
3337
startTime = time.time()
3438
missedSuccessiveSamples = 0
3539

40+
fileBasename = f"test_{time.time()}"
41+
3642
while voltage > cutOffVoltage:
3743
try:
3844
# store the time before measuring volt/current
39-
current_time = (time.time() - startTime)
45+
currentTime = (time.time() - startTime)
4046
voltage = kel.measureVolt()
4147
current = kel.measureCurrent()
4248
voltageData.append(voltage)
4349
# Only append the timedata when volt/current measurements went fine.
4450
# This is because the voltage or current measurement could fail
45-
# and then the x and y-axis would have different dimentions
46-
timeData.append(current_time)
51+
# and then the x and y-axis would have different dimensions
52+
timeData.append(currentTime)
4753

4854
# solve the current stuff as a running accumulation
49-
capacity = ((startTime - time.time()) / 60 / 60) * current
55+
capacity = ((time.time() - startTime) / 3600) * current
5056

51-
print("Voltage: " + str(voltage) + " V DC, Capacity: " + str(capacity) + " Ah")
52-
time.sleep(0.25)
57+
print(f"Voltage: {voltage:.3f} V DC, Capacity: {capacity:.3f} Ah")
58+
time.sleep(1.0)
5359
missedSuccessiveSamples = 0
60+
61+
with open(f'{fileBasename}.txt', 'a') as f:
62+
f.write(f"{currentTime} {voltage}\n")
5463
except Exception as e:
5564
print(e)
5665
missedSuccessiveSamples += 1
@@ -65,9 +74,10 @@
6574
fig, ax = plt.subplots()
6675
ax.plot(timeData, voltageData)
6776

68-
ax.set(xlabel='time (s)', ylabel='voltage (V DC)',
69-
title='Battery Discharge Test {}A: {:.4f}Ah'.format(dischargeRate, capacity))
77+
ax.set(xlabel='time (s)',
78+
ylabel='voltage (V DC)',
79+
title=f'Battery Discharge Test {dischargeRate:.3f}A: {capacity:.4f}Ah')
7080
ax.grid()
7181

72-
fig.savefig("test_" + str(time.time()) + ".png")
82+
fig.savefig(f"{fileBasename}.png")
7383
plt.show()

examples/dynamicMode.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
# 1st param: the IP of your ethernet/wifi interface
55
# 2nd param: the IP of the Korad device
66
# 3rd param: the port of the Korad device (18190 = default)
7-
kel = kel103.kel103("192.168.2.28", "192.168.7.183", 18190)
7+
host_ip = "192.168.x.x"
8+
device_ip = "192.168.x.x"
9+
port = 18190
10+
kel = kel103.kel103(host_ip, device_ip, port)
811

912
print("Connecting to device..")
1013
try:

examples/internalResistance.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
"""
3+
This sample program uses the kel103 to measure the voltage drop and current
4+
for two resistances and calculate the internal resistance of the battery.
5+
"""
6+
7+
import time
8+
from korad import kel103
9+
10+
11+
def measureVoltageAndCurrentAtResistance(kel, resistance):
12+
kel.setResistance(resistance)
13+
kel.setOutput(True)
14+
time.sleep(1.0)
15+
u1 = kel.measureVolt()
16+
i1 = kel.measureCurrent()
17+
kel.setOutput(False)
18+
return u1, i1
19+
20+
def main():
21+
host_ip = "192.168.x.x"
22+
device_ip = "192.168.x.x"
23+
port = 18190
24+
kel = kel103.kel103(host_ip, device_ip, port)
25+
kel.setOutput(False)
26+
27+
u1, i1 = measureVoltageAndCurrentAtResistance(kel, 5)
28+
u2, i2 = measureVoltageAndCurrentAtResistance(kel, 10)
29+
30+
ri = (u1 - u2) / (i2 - i1)
31+
print(f"internal resistance {ri}")
32+
33+
if __name__ == "__main__":
34+
main()
35+

0 commit comments

Comments
 (0)