solys2 package

Subpackages

solys2.common module

Common

Module containing common constants, functions and datatypes.

It exports the following functions:
  • gen_random_str: Generate a random str of the specified length.

  • create_default_logger: Instantiate a simple logger.

  • create_file_logger: Generate a file logger with extra log handlers.

It exports the following classes:
  • ContainedBool: Dataclass that act as a container for bool type.

class solys2.common.ContainedBool(value: bool)

Bases: object

Dataclass that acts as a container of a boolean variable so it gets passed as a reference.

value: bool
solys2.common.create_default_logger(level: int = 30) logging.Logger

Instantiate a simple logger that will be the default one.

By default it will only log messages if they are level WARNING or higher.

Parameters

level (int) – Log level that will be logged out.

Returns

logger – Generated Logger.

Return type

logging.Logger

solys2.common.create_file_logger(logfile: str, extra_log_handlers: List[logging.Handler] = [], level: int = 10) logging.Logger

Generate a file logger with extra log handlers.

Parameters
  • logfile (str) – Path of the file where the logging will be stored. In case that it’s not used, it will be printed in stderr.

  • extra_log_handlers (list of logging.Handler) – Custom handlers which the log will also log to.

  • level (int) – Log level that will be logged out.

Returns

logger – Generated Logger.

Return type

logging.Logger

solys2.common.gen_random_str(len: int) str

Return a random str of the specified length.

Parameters

len (int) – Length of the desired str.

Returns

rand_str – Generated random str of the specified length.

Return type

str

solys2.connection module

Connection

Module that encapsulates and abstracts functions that allow the low-level communication with the Solys2.

It exports the following classes:
  • SolysConnection : Class that allows directly sending commands and receiving messages from the Solys2.

class solys2.connection.SolysConnection(ip: str, port: int)

Bases: object

Class that allows directly sending commands and receiving messages from the Solys2.

sock

Socket that will be connected to the Solys2.

Type

socket.socket

close() None

Close the socket connection

connect(ip: str, port: int)

Create the socket and connect it to the Solys2.

Parameters
  • ip (str) – IP of the Solys2.

  • port (int) – Connection port of the Solys2.

empty_recv()

Receives messages from the Solys2 until there are no more messages. Those messages are descarted.

recv_msg() str

Receives a message from the Solys2.

Returns

response – Response given by the Solys2.

Return type

str

send_cmd(command: str) str

Send a command to the Solys2.

Parameters

command (str) – Command that will be sent to the Solys2.

Returns

response – Immediate response given by the Solys2.

Return type

str

solys2.response module

Response

Module that contains functionalities for processing the Solys2 responses.

It exports the following variables:
  • ERROR_CODES : A dictionary containing all the error codes (and custom ones) with their related error messages.

  • INSTRUMENT_STATUS : A dictionary containing all instrument status related to the instrument status code.

  • FLAGS_STATUS : A dictionary containing all flags related to the instrument status code.

It exports the following classes:
  • ErrorCode : Enum that contains all possible Solys2 error codes and some custom ones.

  • OutCode : Enum that represents the type of message received from the Solys2.

It exports the following functions:
  • process_response : Process the response given by the Solys2.

  • translate_status : Translate an status code to the corresponding human words.

class solys2.response.ErrorCode(value)

Bases: enum.Enum

Enum that contains all possible Solys2 error codes and some custom ones.

A = 'A'
B = 'B'
C = 'C'
D = 'D'
E = 'E'
E1 = '1'
E10 = '10'
E2 = '2'
E3 = '3'
E4 = '4'
E5 = '5'
E6 = '6'
E7 = '7'
E8 = '8'
E9 = '9'
F = 'F'
G = 'G'
P = 'P'
Q = 'Q'
R = 'R'
Y = 'Y'
Z = 'Z'
class solys2.response.OutCode(value)

Bases: enum.Enum

Enum that represents the type of message received from the Solys2.

NONE: Empty message, or a response that is not for the sent command. ERROR: An error was encountered- ANSWERED: The response was a successful answer for the command. ANSWERED_NO_NUMS: The response was a successful answer but it didn’t contain numbers. ANSWERED_VALUE_ERROR: The response was a successful answer but there was an error converting the numbers from strings.

ANSWERED = 1
ANSWERED_NO_NUMS = 2
ANSWERED_VALUE_ERROR = 3
ERROR = 0
NONE = -1
solys2.response.process_response(s: str, cmd: str, hex_nums: bool = False) Tuple[List[float], solys2.response.OutCode, Optional[str]]

Process the response given by the Solys2

Parameters
  • s (str) – Response given by the Solys2

  • cmd (str) – Command sent to the Solys2

  • hex_nums (bool) – The numbers are converted from hex strings instead of decimal strings if True.

Returns

  • numbers (list of float) – List of the numbers outputed by the Solys2.

  • out_code (OutCode) – OutCode explaining what kind of response was the response given by the Solys2

  • err_code (str or None) – Character (len 1 str) containing the error code, in case it’s an error, in which case the out_code would be equal to ERROR. Otherwise this will be None.

solys2.response.translate_status(raw_status: str) Tuple[str, List[str], List[str]]

Translate an status code to the corresponding human words.

Parameters

raw_status (str) – Raw status code received from the Solys2

Returns

  • ins_stat (str) – Instrument status.

  • flags_true (list of str) – List of all the activated flags.

  • flags_false (list of str) – List of all the deactivated flags.

solys2.solys2 module

Solys2

Module that encapsulates and abstracts an interface for interacting with the Solys2.

It exports the following classes:
  • Solys2 : Class that encapsulates and abstracts the connection and interaction with the Solys2.

  • CommandOutput : Dataclass that stores the output of a Solys2 message somewhat processed.

  • SolysFunction : Enum that stores the functions that the Solys2 can be set to with the FU command.

  • SolysException : Exception raised when there was an error with the Solys2.

It exports the following functions:
  • translate_error : Returns the error related to an error code.

class solys2.solys2.CommandOutput(raw_response: str, nums: List[float], out: solys2.response.OutCode, err: str)

Bases: object

Dataclass that stores the output of a Solys2 message somewhat processed.

raw_response

Raw response TCP message received from the Solys2.

Type

str

nums

Output numbers present in the raw_response, already filtered.

Type

list of float

out

Type of message received from the Solys.

Type

response.OutCode

err

Error code received from the Solys2. If none, it will be an empty str.

Type

str

err: str
nums: List[float]
out: solys2.response.OutCode
raw_response: str
class solys2.solys2.Solys2(ip: str, port: int = 15000, password: str = 'solys')

Bases: object

Class that encapsulates and abstracts the connection and interaction with the Solys2

ip

IP of the Solys2.

Type

str

port

Connection port of the Solys2.

Type

int

password

User password for the Solys2.

Type

str

connection

Connection with the Solys2.

Type

connection.SolysConnection

closed

Boolean value that stores if the connection is closed or not.

Type

bool

offset_cp

Adjustments of the motors. [adjustment_0, adjustment_1].

Type

list of float

adjust() Tuple[float, float, solys2.solys2.CommandOutput]

Adjust (AD) Retrieve the tracking adjustment for all motors. Returns AD <adjustment 0> <adjustment 1>. Adjustments are reported in degrees.

Also updates the inner variables that store the current adjustments.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • adjustment_0 (float) – Degrees of adjustment of the first motor.

  • adjustment_1 (float) – Degrees of adjustment of the second motor.

  • output (CommandOutput) – Output of the command, data received from solys.

adjust_azimuth(degrees: float) solys2.solys2.CommandOutput

Adjust the azimuth motor.

Cause the azimuth motor to be adjusted by the given degrees. The <degrees> parameters must be within [-0.2, 0.2] and the total adjustment must not exceed 4.

Raises

SolysException – If an error happens when calling the Solys2.

Parameters

degrees (float) – Degrees of adjustment to move (clockwise). Contained in the range [-0.2, 0.2].

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

adjust_zenith(degrees: float) solys2.solys2.CommandOutput

Adjust the zenith motor.

Cause the zenith motor to be adjusted by the given degrees. The <degrees> parameters must be within [-0.2, 0.2] and the total adjustment must not exceed 4.

Raises

SolysException – If an error happens when calling the Solys2.

Parameters

degrees (float) – Degrees of adjustment to move (clockwise). Contained in the range [-0.2, 0.2].

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

calculate_timedelta() Tuple[datetime.timedelta, solys2.solys2.CommandOutput]

Calculate the difference between solys internal time (UTC) and the Computer time in UTC.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • tdt (datetime.timedelta) – Difference between solys internal time (UTC) and the Computer time in UTC.

  • output (CommandOutput) – Output of the command, data received from solys.

close()

Close the connection.

connect()

Creates a new connection with the Solys. If it had another one, it gets closed.

get_current_position() Tuple[float, float, solys2.solys2.CommandOutput]

Current Position (CP) Obtain the positions where the Solys is at the moment.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • azimuth (float) – Azimuth angle at which the Solys is pointing.

  • zenith (float) – Zenith angle at which the Solys is pointing.

  • output (CommandOutput) – Output of the command, data received from solys.

get_datetime() Tuple[datetime.datetime, solys2.solys2.CommandOutput]

Get Time (TI) Retrieve the internal time (Universal).

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • dt (datetime.datetime) – Solys2 internal time.

  • output (CommandOutput) – Output of the command, data received from solys.

get_function() Tuple[solys2.solys2.SolysFunction, solys2.solys2.CommandOutput]

Get Function (FU) Retrieve the code indicating the function for which the tracker is being used.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • function (SolysFunction) – Function for which the tracker is being used. NO_FUNCTION in case of error.

  • output (CommandOutput) – Output of the command, data received from solys.

get_location_pressure() Tuple[float, float, float, solys2.solys2.CommandOutput]

Location and pressure (LL) Obtain the location and pressure for the site.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • latitude (float) – Latitude in decimal degrees

  • longitude (float) – Longitude in decimal degrees

  • pressure (float) – Nominal atmospheric pressure recorded for the site

  • output (CommandOutput) – Output of the command, data received from solys.

get_planned_position() Tuple[float, float, solys2.solys2.CommandOutput]

Position (PO) Obtain the positions that the Solys sais it’s going to.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • azimuth (float) – Azimuth angle at which the Solys is pointing.

  • zenith (float) – Zenith angle at which the Solys is pointing.

  • output (CommandOutput) – Output of the command, data received from solys.

get_power_save() Tuple[bool, solys2.solys2.CommandOutput]

Power Save (PS)

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • power_save_status (int) – 1 if its activated, 0 if not, -1 if error (it should raise an exception).

  • output (CommandOutput) – Output of the command, data received from solys.

get_queue_status() Tuple[int, int, solys2.solys2.CommandOutput]

Queue Status (QS) Retrieves the current number of path segments in the path for each motor.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • count_0 (int) – Queue status of the first motor. Azimuth/Horizontal motor.

  • count_1 (int) – Queue status of the second motor. Zenith/Vertical motor.

  • output (CommandOutput) – Output of the command, data received from solys.

get_raw_status() Tuple[str, solys2.solys2.CommandOutput]

Status (IS) Get the raw status code returned from the Solys2

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • raw_status (str) – Raw status code received from the Solys2.

  • output (CommandOutput) – Output of the command, data received from solys.

get_status() Tuple[str, List[str], List[str], solys2.solys2.CommandOutput]

Gets the status, translated for humans.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • ins_stat (str) – Instrument status.

  • flags_true (list of str) – List of all the activated flags.

  • flags_false (list of str) – List of all the deactivated flags.

  • output (CommandOutput) – Output of the command, data received from solys.

get_sun_intensity() Tuple[List[float], float, solys2.solys2.CommandOutput]

Sun intensity (SI) Retrieves the current sun intensity.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

  • intensities (list of 4 float) – Intensity of each quadrant. [Q1, Q2, Q3, Q4]

  • total_intensity (float) – Total intensity.

  • output (CommandOutput) – Output of the command, data received from solys.

home() solys2.solys2.CommandOutput

Home (HO) Tells the Solys to go to its home position. (it will stay there for over 1 minute). This might block the Solys for a couple of minutes.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

lift_protection(recursion: int = 0) solys2.solys2.CommandOutput

Change protection (PR 0) Allows or disallows modification to be done by the web interface to the configuration.

Parameters

recursion (int) – Level of recursion of this call. First time 0, next 1… This recursion is due to the need to try to lift the protection in case it goes down, which it does. At some point it will stop recursing.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

point_down() solys2.solys2.CommandOutput

Point down as much as possible Set the zenith angle to the maximum possible (94.5)

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

send_command(cmd: str, recursion: int = 0) solys2.solys2.CommandOutput

Send command to the solys. If it gets deauthenticated, it authenticates again automatically.

Parameters
  • cmd (str) – Command that is going to be sent

  • recursion (int) – Level of recursion of this call. First time 0, next 1… This recursion is due to the need to try to lift the protection in case it goes down, which it does. At some point it will stop recursing.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

send_password(recursion: int = 0) solys2.solys2.CommandOutput

Change password (PW) Send the password to the solys, authenticating this connection. Most of the set commands desire a password which can be changed here

Parameters

recursion (int) – Level of recursion of this call. First time 0, next 1… This recursion is due to the need to try to lift the protection in case it goes down, which it does. At some point it will stop recursing.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

set_automatic() List[solys2.solys2.CommandOutput]

Set the tracker in automatic active tracking following the sun.

Parameters

func (SolysFunction) – Function for which the tracker will be used for.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

outputs – Output of the commands, data received from solys.

Return type

list of CommandOutput

set_azimuth(azimuth: float) solys2.solys2.CommandOutput

Position 0 (PO 0) Set the azimuth angle at which the solys is pointing.

Raises

SolysException – If an error happens when calling the Solys2.

Parameters

azimuth (float) – Float between 0 and 360, representing the azimuth at which we want the solys to point to.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

set_function(func: solys2.solys2.SolysFunction) solys2.solys2.CommandOutput

Set Function (FU) Sets the function of the tracker.

Note: If the instrument was suntracking and is given a non-suntracking function, it will continue to follow the sun until it’s sent a home (HO) command.

Parameters

func (SolysFunction) – Function for which the tracker will be used for.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

set_manual() List[solys2.solys2.CommandOutput]

Set the tracker in manual standard operation mode.

Parameters

func (SolysFunction) – Function for which the tracker will be used for.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

outputs – Output of the commands, data received from solys.

Return type

list of CommandOutput

set_power_save(save: bool) solys2.solys2.CommandOutput

Power Save (PS)

Parameters

save (bool) – True if power save activated, false if not.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

set_zenith(zenith: float) solys2.solys2.CommandOutput

Position 1 (PO 1) Set the zenith angle at which the solys is pointing.

Raises

SolysException – If an error happens when calling the Solys2.

Parameters

zenith (float) – Float between 0 and 90, representing the zenith at which we want the solys to point to.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

version() solys2.solys2.CommandOutput

Version (VE) Obtain the version of the solys.

Raises

SolysException – If an error happens when calling the Solys2.

Returns

output – Output of the command, data received from solys.

Return type

CommandOutput

exception solys2.solys2.SolysException

Bases: Exception

Exception raised when there was an error in the communication with the Solys2, or the message was unexpected.

class solys2.solys2.SolysFunction(value)

Bases: enum.Enum

Functions that the Solys2 can be set to with the FU command.

  • NO_FUNCTION : The tracker will not move.

  • STANDARD_OPERATION : The tracker moves in response to motion commands. Homes to (90,90).

  • STANDARD_OPERATION_REVERSE : The tracker moves in response to motion commands. Homes to (90,0).

  • SUNTRACKING : Following the sun.

  • ACTIVE_TRACKING : Following the sun using the sun sensor for minor adjustment.

ACTIVE_TRACKING = 6
NO_FUNCTION = 0
STANDARD_OPERATION = 1
STANDARD_OPERATION_REVERSE = 2
SUNTRACKING = 4
solys2.solys2.translate_error(code: str) str

Returns the error related to the error code

Parameters

code (str) – Error code.

Returns

msg – Retrieved error message.

Return type

str