This file contains the details about the script 'connman.py' and the instructions to use it.
The file defines the classes TConnection
and SConnection
that can be imported as:
from connman import TConnection
from connman import SConnection
The file connman.py
will have to be in the same directory as the script that imports the classes.
An object of type TConnection
can be then defined as follows:
- Without any arguments
C = TConnection()
- Host ip as the only argument
C = TConnection("ip")
- Host ip and port as arguments:
C = TConnection("ip", port)
The following fields have a default value associated with them and are utilized when no argument is supplied to the constructor.
- ip: 172.24.0.75
- port: 23
The object of type TConnection will have the following functions available to it:
- send(cmd)
- justSend(cmd)
- setup()
- status(rsp)
- powerOffPort(port)
- powerOnPort(port)
- togglePort(port)
- refresh()
- cyclePower(port, t)
- On1()
- On2()
- On3()
- On4()
- On5()
- On6()
- On7()
- On8()
- Off1()
- Off2()
- Off3()
- Off4()
- Off5()
- Off6()
- Off7()
- Off8()
A brief description of these functions is available below.
-
send(cmd):- This function will send the contents of the variable cmd as a string over Telnet to the connected host. Note that the command does not have to be a string. The function justSend(cmd) is functionally the same thing as send(cmd), except that it does not monitor the PSU output to analyze which ports are on and which are off.
-
setup():- This function will take the PSU in the mode from which the ports can be controlled. This function is designed for internal use rather than being called on an object.
-
status(rsp):- This function takes the PSU output as its input and analyses which ports are on and off. This function is designed for internal use rather than being called on an object.
-
powerOffPort(port):- This function takes an integer between 0 and 8, inclusive, as input. For an input between 1 and 8, the function, as aptly named, will power the port off. If 0 is supplied, then all of the ports from 1 to 8 will be turned off.
-
powerOnPort(port):- This function takes an integer between 0 and 8, inclusive, as input. For an input between 1 and 8, the function, as aptly named, will power the port on. If 0 is supplied, then all of the ports from 1 to 8 will be turned on.
-
togglePort(port):- This function takes an integer between 1 and 8, inclusive, as input. For an input between 1 and 8, the function, as aptly named, will toggle the port.
-
refresh():- This function will restablish the telnet connection with the PSU if more than 120 seconds have passed since the last interaction. Essentialy, it revives a timed out connection.
-
cyclePower(port, t):- This function will toggle the supplied port, wait for t seconds, and then toggle the port again.
The functions from 9 to 24 behave exactly as their name would suggest.
The ony thing to note is that calling on
on a port that is already on will not turn the port off and vice versa.
An object of type SConnection
can be then defined as follows:
- Serial device as the only argument:
C = TConnection("device")
- Serial device and baudrate as arguments:
C = TConnection("device", baudrate)
- Serial device, baudrate, and timeout, in seconds, as arguments:
C = TConnection("device", baudrate, timeout)
The following fields have a default value associated with them and are utilized when a value for the argument is not supplied to the constructor.
- baudrate: 115200
- timeout: 1
The object of type SConnection will have the following functions available to it:
- send(cmd)
- readAll()
A brief description of these functions is available below.
-
send(cmd):- This method will append a '\r' at the end of the command supplied and write that to the provided serial device. Making the process of writing commands over the serial connection easier is the main focus of this function. The command doesn't have to be a string. The method will return the result of sending the specified command to the device as a string.
-
readAll():- If there are things in the serial communication buffer, this method will return them all as a single variable. The send(cmd) method utilizes this method internally.