Skip to content

Commit

Permalink
Added function to switch to EPC without power off.
Browse files Browse the repository at this point in the history
Package added to pip.
  • Loading branch information
maxkrapp1 committed Jan 16, 2023
1 parent c5249e5 commit d10617c
Show file tree
Hide file tree
Showing 47 changed files with 3,039 additions and 941 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Python 🐍 distributions 📦 to PyPI

on:
release:
types: [published]

jobs:
build-n-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ __pycache__
/dist/
/*.egg-info/

# IDEs
# IDEs
/deploy/
/.vscode/
/.vs/
/.settings/
/.ipynb_checkpoints/
/docs/
/source/_build/
*__pycache__
/.project
/.pydevproject
73 changes: 37 additions & 36 deletions Examples/BCMuxInterface/BCMuxInterface.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import socket

class BCMuxInterface():
""" BC-Mux control class.

class BCMuxInterface:
"""BC-Mux control class.
With this class the `BC-MUX Multiplexer <https://zahner.de/products-details/multiplexer/bc-mux>`_ can
be controlled remotely without the BC-Mux Controller software.
The USB interface of the BC Mux is not supported by Python. Also the network settings must be
done with the program BC-Mux Network Config before using python.
The BC-MUX is an extension which makes it possible to separate up to 16 channels of a cyclizer
individually with switch boxes from the cyclizer and to switch them to the Zennium for e.g.
impedance measurements. This allows the cyclizer to be extended up to 16 channels with sequential
Expand All @@ -18,98 +19,98 @@ class BCMuxInterface():
This class makes it possible to control the Zennium and the Multiplexer from one Python instance
via Remote2, which makes the use more flexible than with the BC-Mux Controller.
Also, if the cyclizer supports it, the complete system can be controlled from a single Python software.
:param ip: SerialCommandInterface object to control the device.
:type ip: str
:param port: SerialDataInterface object for online data.
:type port: int
"""

BUFFER_SIZE = 1024

def __init__(self, ip, port):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.ip = ip
self.port = port
self.socket.connect((self.ip, self.port))
return

def close(self):
""" Closing the connection.
"""Closing the connection.
Disconnects the TCP/IP connection to the BC-MUX.
"""
self.socket.close()
return

def connectChannel(self, channel):
""" Connects the channel to the zennium.
"""Connects the channel to the zennium.
With this command, a channel is disconnected from the cyclizer and switched to the Zennium,
for example for impedance measurements.
:param channel: The channel to connect to the zennium.
:returns: The response string from the device.
:rtype: string
"""
command = "ch {}"
return self._executeCommandAndReadReply(command.format(channel))

def disconnectChannel(self):
""" Disconnects all channels from the zennium.
"""Disconnects all channels from the zennium.
All channels are disconnected from the Zennium and switched to the specific cyclizer channel.
:returns: The response string from the device.
:rtype: string
"""
command = "ch 0"
return self._executeCommandAndReadReply(command)

def setPulseLength(self, length):
""" Setting the relais control.
"""Setting the relais control.
The BC-MUX supports switchboxes containing monostable or bistable relais. With this command,
the control of the relais is set.
If a number other than 0 is set, the relay is switched with a pulse.
The pulse is then the number in milliseconds long.
:param length: The length of the switching pulse in milliseconds. 0 for monostable relays.
:returns: The response string from the device.
:rtype: string
"""
command = "puls {}"
return self._executeCommandAndReadReply(command.format(length))

def _executeCommandAndReadReply(self, command):
""" Private function to send a command to the device and read a string.
"""Private function to send a command to the device and read a string.
This command sends the command to the device and returns the response from the device.
:returns: Response string from the device.
:returns: Response string from the device.
:rtype: string
"""
command += "\r\n"
self.socket.send(command.encode("utf-8"))
data = self.socket.recv(BCMuxInterface.BUFFER_SIZE)
return data.decode("utf-8")

if __name__ == '__main__':

if __name__ == "__main__":
TCP_IP = "169.169.169.169"
TCP_PORT = 4223

bcMux = BCMuxInterface(TCP_IP, TCP_PORT)

bcMux.setPulseLength(250)
bcMux.disconnectChannel()

for i in range(16):
print(f"Channel: {i+1}")
bcMux.connectChannel(i+1)
bcMux.connectChannel(i + 1)
bcMux.disconnectChannel()

bcMux.close()

print("finish")

34 changes: 12 additions & 22 deletions Examples/BasicIntroduction/BasicIntroduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,15 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"connection successfull\n"
]
}
],
"outputs": [],
"source": [
"TARGET_HOST = \"localhost\"\n",
"\n",
"if __name__ == \"__main__\":\n",
" zenniumConnection = ThalesRemoteConnection()\n",
" connectionSuccessful = zenniumConnection.connectToTerm(TARGET_HOST, \"ScriptRemote\")\n",
" if connectionSuccessful:\n",
" print(\"connection successfull\")\n",
" else:\n",
" print(\"connection not possible\")\n",
" sys.exit()"
" zenniumConnection.connectToTerm(TARGET_HOST, \"ScriptRemote\")"
]
},
{
Expand Down Expand Up @@ -377,11 +364,9 @@
}
],
"metadata": {
"interpreter": {
"hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963"
},
"kernelspec": {
"display_name": "Python 3.9.7 64-bit",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -394,9 +379,14 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]"
},
"orig_nbformat": 4
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "5238573367df39f7286bb46f9ff5f08f63a01a80960060ce41e3c79b190280fa"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
27 changes: 14 additions & 13 deletions Examples/BasicIntroduction/BasicIntroduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@
import math
import cmath
from thales_remote.connection import ThalesRemoteConnection
from thales_remote.script_wrapper import PotentiostatMode,ThalesRemoteScriptWrapper
from thales_remote.script_wrapper import PotentiostatMode, ThalesRemoteScriptWrapper


def printImpedance(impedance):
print(f"Impedance: {abs(impedance):>10.3e} ohm {cmath.phase(impedance)/cmath.pi*180.0:>10.2f} degree")
print(
f"Impedance: {abs(impedance):>10.3e} ohm {cmath.phase(impedance)/cmath.pi*180.0:>10.2f} degree"
)
return


def spectrum(scriptHandle, lower_frequency, upper_frequency, number_of_points):
log_lower_frequency = math.log(lower_frequency)
log_upper_frequency = math.log(upper_frequency)
log_interval_spacing = (log_upper_frequency - log_lower_frequency) / (number_of_points - 1)

log_interval_spacing = (log_upper_frequency - log_lower_frequency) / (
number_of_points - 1
)

for i in range(number_of_points):
current_frequency = math.exp(log_lower_frequency + log_interval_spacing * i)
print(f"Frequency: {current_frequency:e} Hz")
printImpedance(scriptHandle.getImpedance(current_frequency))

return


TARGET_HOST = "localhost"

if __name__ == "__main__":
zenniumConnection = ThalesRemoteConnection()
connectionSuccessful = zenniumConnection.connectToTerm(TARGET_HOST, "ScriptRemote")
if connectionSuccessful:
print("connection successfull")
else:
print("connection not possible")
sys.exit()
zenniumConnection.connectToTerm(TARGET_HOST, "ScriptRemote")

zahnerZennium = ThalesRemoteScriptWrapper(zenniumConnection)
zahnerZennium.forceThalesIntoRemoteScript()
Expand Down Expand Up @@ -59,7 +61,7 @@ def spectrum(scriptHandle, lower_frequency, upper_frequency, number_of_points):
zahnerZennium.enablePotentiostat()
zahnerZennium.setFrequency(2000)
zahnerZennium.setNumberOfPeriods(3)

zahnerZennium.enablePotentiostat()
zahnerZennium.getCurrent()

Expand All @@ -76,4 +78,3 @@ def spectrum(scriptHandle, lower_frequency, upper_frequency, number_of_points):

zenniumConnection.disconnectFromTerm()
print("finish")

30 changes: 8 additions & 22 deletions Examples/CVImportPlot/CVImportPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,19 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"connection successfull\n"
]
}
],
"outputs": [],
"source": [
"\n",
"if __name__ == \"__main__\":\n",
" zenniumConnection = ThalesRemoteConnection()\n",
" connectionSuccessful = zenniumConnection.connectToTerm(\n",
" \"localhost\", \"ScriptRemote\")\n",
" if connectionSuccessful:\n",
" print(\"connection successfull\")\n",
" else:\n",
" print(\"connection not possible\")\n",
" sys.exit()\n",
" zenniumConnection.connectToTerm(\"localhost\", \"ScriptRemote\")\n",
"\n",
" zahnerZennium = ThalesRemoteScriptWrapper(zenniumConnection)\n",
" zahnerZennium.forceThalesIntoRemoteScript()\n",
"\n",
" zahnerZennium.calibrateOffsets()\n"
" zahnerZennium.calibrateOffsets()"
]
},
{
Expand Down Expand Up @@ -187,7 +173,7 @@
" Determine the maximum current for the next measurement\n",
" from the maximum current of the last CV measurement.\n",
" \"\"\"\n",
" latestMeasurement = IscImport(fileInterface.getLatestReceivedFile()[\"binary_data\"])\n",
" latestMeasurement = IscImport(fileInterface.getLatestReceivedFile().binaryData)\n",
" maximumCurrent = max(abs(latestMeasurement.getCurrentArray()))\n",
"\n",
" zahnerZennium.setCVMaximumCurrent(maximumCurrent * 3)\n",
Expand Down Expand Up @@ -241,11 +227,11 @@
"source": [
" iscFileFromDisc = IscImport(r\"C:\\THALES\\temp\\cv\\cv_1000mVs.isc\")\n",
"\n",
" iscFiles = [IscImport(file[\"binary_data\"]) for file in fileInterface.getReceivedFiles()]\n",
" iscFiles = [IscImport(file.binaryData) for file in fileInterface.getReceivedFiles()]\n",
"\n",
" for iscFile in iscFiles:\n",
" print(f\"{iscFile.getScanRate()} V/s\\tmeasurement finished at {iscFile.getMeasurementEndDateTime()}\")\n",
" \n"
" "
]
},
{
Expand Down Expand Up @@ -314,7 +300,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit d10617c

Please sign in to comment.