Skip to content

Commit

Permalink
driver/power: add backend for Phoenix Contact FL 2303-8SP1 SPE switch
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Lübbe <jluebbe@lasnet.de>
Signed-off-by: Semin Buljevic <49791905+SeminSey@users.noreply.github.com>

Rename phoenix_fl_switch.py to phoenixcontact_fl_2300.py

Signed-off-by: semin.buljevic <semin.buljevic@jumo.net>
  • Loading branch information
ActionHOSchT authored and semin.buljevic committed May 28, 2024
1 parent 8f46a37 commit f07c307
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Currently available are:
``netio_kshell``
Controls a NETIO 4C PDU via a Telnet interface.

``phoenixcontact_fl_2300``
Controls a single-pair-ethernet powerswitch via telnet.
Tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA

``raritan``
Controls Raritan PDUs via SNMP.

Expand Down
74 changes: 74 additions & 0 deletions labgrid/driver/power/phoenixcontact_fl_2300.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
This Driver was tested on a FL SWITCH 2303-8SP1 with FW-version 3.27.01 BETA
file phoenixcontact_fl_2300.py
author Raffael Krakau
date 2023-08-24
Copyright 2023 JUMO GmbH & Co. KG
'''
import pexpect

PORT = 23


def __login_telnet(tn):
"""
Login user with set credentials
@param tn : pyexpect-telnet-object
"""
username = "admin"
password = "private"

# login user with password
tn.expect(b'User: ')
tn.send(bytes(f'{username}\r\n', "utf-8"))
tn.expect(b'Password: ')
tn.send(bytes(f'{password}\r\n', "utf-8"))


def power_set(host, port, index: int, value: bool):
"""
Set power state by socket port number (e.g. 1 - 8) and an value {'enable', 'disable'}.
- values:
- disable(False): Turn OFF,
- enable(True): Turn ON
"""
action = "enable" if value else "disable"

with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
# login user with password
__login_telnet(tn)

# set value
tn.send(f'pse port {index} power {action}\r\n'.encode())

tn.expect(b'OK')

tn.send(b"quit\r\n")
tn.expect(pexpect.EOF)


def power_get(host, port, index: int) -> bool:
"""
Get current state of a given socket number.
- host: spe-switch-device adress
- port: standard is 23
- index: depends on spe-switch-device 1-n (n is the number of spe-switch-ports)
"""
status = None

with pexpect.spawn(f"telnet {host} {port}", timeout=1) as tn:
# login user with password
__login_telnet(tn)

# get value
tn.send(bytes(f'show pse port port-no {index}\r\n', "utf-8"))

status = tn.expect(['disable', 'enable'])

tn.send(b"quit\r\n")
tn.expect(pexpect.EOF)

return True if status == 1 else False

0 comments on commit f07c307

Please sign in to comment.