### Installing elliptec-controller for Development (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Clones the elliptec-controller repository from GitHub and installs it in editable mode using pip. This is useful for development or getting the latest unreleased version. Requires Git, Python, and pip. ```bash git clone https://github.com/TheFermiSea/elliptec-controller.git cd elliptec-controller pip install -e . ``` -------------------------------- ### Installing Package from TestPyPI (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Installs the package `elliptec-controller` from the TestPyPI index URL using pip. This is used to verify the uploaded package. ```Bash pip install --index-url https://test.pypi.org/simple/ elliptec-controller ``` -------------------------------- ### Python API Basic Usage - Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/quickstart.md Shows how to use the `elliptec_controller` Python library to connect to a rotator via serial, get device information, home the device, move to an absolute position, and retrieve its current status. It also includes notes on serial port management. ```python import serial from elliptec_controller import ElliptecRotator # Open serial connection ser = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1) # Create rotator instance (replace port and address) rotator = ElliptecRotator("/dev/ttyUSB0", motor_address=1, name="MyRotator") try: # Get device info (called automatically if port name is given) # info = rotator.get_device_info() # You can call it manually if needed # print(f"Device info: {rotator.device_info}") # Home the device info = rotator.get_device_info() print(f"Device info: {info}") # Home the device rotator.home(wait=True) # Move to absolute position rotator.move_absolute(45.0, wait=True) # Get current status status = rotator.get_status() print(f"Status: {status}") finally: # Always close the serial connection if you opened it manually # If ElliptecRotator was initialized with a port name string, # it handles closing automatically. # ser.close() ``` -------------------------------- ### CLI Basic Operations - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/quickstart.md Demonstrates fundamental command-line usage of the `elliptec-controller` tool, including checking status, homing the device, moving to an absolute position, and retrieving device information. ```bash # Get device status elliptec-controller status # Home all rotators elliptec-controller home # Move a specific rotator elliptec-controller move-abs -r 0 -pos 45.0 # Get device information elliptec-controller info ``` -------------------------------- ### Setup Development Environment - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/CONTRIBUTING.md Commands to create a Python virtual environment, activate it, and install the project package in editable mode along with its dependencies listed in requirements.txt. ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -e . pip install -r requirements.txt ``` -------------------------------- ### Installing PyPI Build Tools (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Installs the necessary Python packages (`build` and `twine`) required to build and upload Python packages to the Python Package Index (PyPI). ```Bash pip install build twine ``` -------------------------------- ### Installing elliptec-controller with pip (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Installs the elliptec-controller Python package from PyPI using the pip package manager. This is the standard way to install the library for basic usage. Requires Python and pip to be installed. ```bash pip install elliptec-controller ``` -------------------------------- ### Python API Error Handling - Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/quickstart.md Provides an example of implementing robust error handling when using the `elliptec_controller` Python library. It covers catching serial connection errors, initialization failures, checking device readiness before operations, handling operation errors, and attempting to stop the device in case of issues. ```python import serial from elliptec_controller import ElliptecRotator rotator = None try: rotator = ElliptecRotator( port="/dev/ttyUSB0", # Replace with your port motor_address=1, # Replace with your address debug=True ) except serial.SerialException as e: print(f"Failed to connect to rotator: {e}") exit(1) except Exception as e: print(f"Failed to initialize rotator: {e}") exit(1) try: # Check if rotator is ready before operation if not rotator.is_ready(): print("Rotator not ready. Homing...") if not rotator.home(wait=True): print("Homing failed.") # Decide how to proceed if homing fails exit(1) # Perform operations print("Moving to 0 degrees...") if rotator.move_absolute(0.0, wait=True): print("Move successful.") else: print("Move failed.") except Exception as e: print(f"Error during operation: {e}") # Attempt to stop the rotator in case of error try: print("Attempting to stop rotator...") rotator.stop() except Exception as stop_e: print(f"Failed to stop rotator: {stop_e}") finally: # ElliptecRotator closes the port automatically if it opened it. print("Operation finished.") ``` -------------------------------- ### Synchronized Movement Setup with Two Elliptec Rotators (Python) Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Starts the setup for synchronizing two Elliptec rotators connected to the same serial port using group addressing. This snippet imports necessary libraries for the subsequent synchronized movement example. ```python import serial from elliptec_controller import ElliptecRotator import time ``` -------------------------------- ### Initializing Git Repository (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Initializes a new Git repository in the current directory, adds all files to the staging area, and creates the initial commit with a message. ```Bash cd /home/maitai/Documents/urashg_2/elliptec-controller git init git add . git commit -m "Initial commit" ``` -------------------------------- ### Installing Package in Development Mode (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Installs the package in 'editable' mode using pip, allowing changes in the source code directory to be reflected without reinstallation. Useful for development. ```Bash pip install -e . ``` -------------------------------- ### Install elliptec-controller from source Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Clones the elliptec-controller repository from GitHub and installs it locally in editable mode using pip. ```bash git clone https://github.com/TheFermiSea/elliptec-controller.git cd elliptec-controller pip install . ``` -------------------------------- ### Uploading Package to PyPI (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Uploads the generated package distributions from the `dist/` directory to the official PyPI repository using `twine`. Requires authentication. ```Bash python -m twine upload dist/* ``` -------------------------------- ### Verifying Elliptec Controller CLI Connection (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Uses the installed elliptec-controller command-line interface (CLI) tool to check the status of a device connected to a specific serial port. Replace /dev/ttyUSB0 with the actual port name. Requires the package to be installed and the device connected. ```bash elliptec-controller --port /dev/ttyUSB0 status ``` -------------------------------- ### Verifying Elliptec Controller Python API (Python) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Demonstrates how to use the elliptec_controller Python library to connect to and communicate with multiple Elliptec rotators. It initializes a TripleRotatorController, retrieves device information for each connected rotator, and then closes the connection. Requires the library installed and devices connected. Adjust port, addresses, and names as needed. ```python from elliptec_controller import TripleRotatorController # Create a controller (adjust port and addresses as needed) controller = TripleRotatorController( port="/dev/ttyUSB0", addresses=[3, 6, 8], names=["HWP1", "QWP", "HWP2"] ) # Test communication for rotator in controller.rotators: info = rotator.get_device_info() print(f"{rotator.name} info: {info}") # Close when done controller.close() ``` -------------------------------- ### Uploading Package to TestPyPI (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Uploads the generated package distributions from the `dist/` directory to the TestPyPI repository using `twine`. Requires authentication. ```Bash python -m twine upload --repository testpypi dist/* ``` -------------------------------- ### Install Test Dependencies (Manual) - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Manually installs the required test dependencies, `pytest` and `pyserial`. ```bash pip install pytest pyserial ``` ```bash uv pip install pytest pyserial ``` -------------------------------- ### Building Python Package (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Uses the `build` module to create source and wheel distributions of the Python package, typically generating files in a `dist/` directory. ```Bash python -m build ``` -------------------------------- ### Listing Serial Ports on Linux/macOS (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Lists files in the /dev/ directory that match the pattern tty*. This command helps identify available serial ports (like /dev/ttyUSB0, /dev/tty.usbserial-*) on Linux and macOS systems. ```bash ls /dev/tty* ``` -------------------------------- ### Running All Pytest Tests (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Executes all tests discovered by the pytest framework in the current project directory. ```Bash pytest ``` -------------------------------- ### Install elliptec-controller using pip Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Installs the elliptec-controller Python package from the Python Package Index (PyPI) using the pip package manager. ```bash pip install elliptec-controller ``` -------------------------------- ### Install and Use Code Style Tools - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/CONTRIBUTING.md Commands to install the black formatter and flake8 linter, and then apply them to the project's source code directory to ensure adherence to PEP 8 standards. ```bash pip install black flake8 black elliptec_controller/ flake8 elliptec_controller/ ``` -------------------------------- ### Listing Serial Ports on Windows (PowerShell) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Uses the PowerShell Get-WmiObject cmdlet to query the Windows Management Instrumentation (WMI) for information about available serial ports (Win32_SerialPort). This helps identify COM ports (like COM1, COM2) on Windows systems. ```powershell Get-WmiObject Win32_SerialPort ``` -------------------------------- ### Connecting to Remote GitHub Repository (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Adds a remote origin URL to the local repository, renames the default branch to 'main', and pushes the initial commit to the remote repository, setting the upstream branch. ```Bash git remote add origin https://github.com/TheFermiSea/elliptec-controller.git git branch -M main git push -u origin main ``` -------------------------------- ### Install Test Dependencies (Editable) - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Installs the project in editable mode along with the optional test dependencies defined in `pyproject.toml`. Use `pip` or `uv`. ```bash pip install -e .[test] ``` ```bash uv pip install -e .[test] ``` -------------------------------- ### Checking Git Status (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Displays the status of the working tree and staging area, showing which files have been changed, staged, or are untracked. ```Bash git status ``` -------------------------------- ### Granting Serial Port Permissions on Linux (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/installation.md Adds the current user ($USER) to the dialout group on Linux systems. This group typically has permissions to access serial ports, resolving "Permission denied" errors. Requires superuser privileges (sudo). A log out/in is needed for changes to take effect. ```bash sudo usermod -a -G dialout $USER ``` -------------------------------- ### Running Specific Pytest Tests (Bash) Source: https://github.com/thefermisea/elliptec-controller/blob/main/GITHUB_SETUP.md Executes only the specified test functions or classes within the `tests/test_controller.py` file using pytest. ```Bash pytest tests/test_controller.py::TestHexConversion tests/test_controller.py::TestElliptecRotator ``` -------------------------------- ### Getting Device Info for ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Retrieves detailed information about the connected rotator (serial, firmware, pulse count, etc.) using the "in" command. Populates internal attributes and returns the info as a dictionary. Called automatically on initialization. ```python get_device_info(debug=False) -> dict ``` -------------------------------- ### Getting Status of ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Retrieves the current status code from the rotator. Useful for checking the device's state (e.g., moving, ready). Returns a status code string. ```python get_status() -> str ``` -------------------------------- ### Elliptec Controller Command Constants - Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Defines the hexadecimal command strings used to communicate with Elliptec devices. These constants represent various operations like getting status, stopping motion, homing, moving, setting parameters, and retrieving device information. ```python COMMAND_GET_STATUS = "gs" # Get status COMMAND_STOP = "st" # Stop motion COMMAND_HOME = "ho" # Home device COMMAND_FORWARD = "fw" # Forward continuous COMMAND_BACKWARD = "bw" # Backward continuous COMMAND_MOVE_ABS = "ma" # Move absolute COMMAND_GET_POS = "gp" # Get position COMMAND_SET_VELOCITY = "sv" # Set velocity COMMAND_GET_VELOCITY = "gv" # Get velocity COMMAND_SET_JOG_STEP = "sj" # Set jog step size COMMAND_GET_JOG_STEP = "gj" # Get jog step size COMMAND_SET_HOME_OFFSET = "so" # Set home offset COMMAND_GET_HOME_OFFSET = "go" # Get home offset COMMAND_GROUP_ADDRESS = "ga" # Set group address COMMAND_OPTIMIZE_MOTORS = "om" # Optimize motors COMMAND_GET_INFO = "in" # Get device info ``` -------------------------------- ### Clone Repository and Navigate - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/CONTRIBUTING.md Instructions for cloning your forked repository from GitHub and navigating into the project directory using standard Git and bash commands. ```bash git clone https://github.com/your-username/elliptec-controller.git cd elliptec-controller ``` -------------------------------- ### Run Project Tests - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/CONTRIBUTING.md Command using pytest to execute specific test modules within the project's test suite. Note that some tests may require hardware and could be skipped. ```bash pytest tests/test_controller.py::TestHexConversion tests/test_controller.py::TestElliptecRotator ``` -------------------------------- ### Basic Usage with Single Elliptec Rotator (Python) Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Demonstrates how to initialize, home, move to an absolute position, update, and retrieve the current position of a single Elliptec rotator using the elliptec-controller package. Includes error handling for serial communication. ```python import serial from elliptec_controller import ElliptecRotator import time # Using a specific serial port try: # Create a rotator instance - this opens the port and gets device info rotator1 = ElliptecRotator( port="/dev/ttyUSB0", # Replace with your serial port motor_address=1, # Replace with your device address (0-F) name="Rotator1", debug=True # Enable debug output ) # Print device info (retrieved during initialization) print("Device Info:", rotator1.device_info) print(f"Pulses per Revolution: {rotator1.pulse_per_revolution}") # Home the rotator print("Homing...") rotator1.home(wait=True) print("Homing complete.") time.sleep(1) # Move to an absolute position (in degrees) print("Moving to 90 degrees...") rotator1.move_absolute(90.0, wait=True) print("Move complete.") time.sleep(1) # Get the current position position = rotator1.update_position() print(f"Current position: {position:.2f} degrees") # Clean up (closes the serial port implicitly if opened by the class) # No explicit close needed if port name was passed to constructor except serial.SerialException as e: print(f"Serial port error: {e}") except Exception as e: print(f"An error occurred: {e}") ``` -------------------------------- ### Initializing ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Creates a new instance of the ElliptecRotator class. Requires the serial port, motor address, and optional name and debug flag. Handles port opening/closing if a port name is provided. ```python ElliptecRotator(port, motor_address, name=None, debug=False) ``` -------------------------------- ### Run Pytest Tests - Bash Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md Executes the test suite located in the `tests/` directory using `pytest`. Can be run directly or via `uv run`. ```bash pytest tests/ ``` ```bash uv run pytest tests/ ``` -------------------------------- ### Checking Readiness of ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Checks if the rotator is currently ready to accept new commands. Returns True if the device is not busy or in an error state, False otherwise. ```python is_ready() -> bool ``` -------------------------------- ### Synchronizing Two Elliptec Rotators - Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/README.md This script initializes two Elliptec rotators on the same serial port, configures one as a slave to the other with an angular offset, performs a synchronized absolute move, verifies their positions, and then reverts the slave configuration. Requires the `elliptec-controller` library and `pyserial`. ```python # Note: Both rotators must be on the same serial port for this to work. SERIAL_PORT = "/dev/ttyUSB0" # Replace with your serial port MASTER_ADDR = 1 # Replace with master's address (0-F) SLAVE_ADDR = 2 # Replace with slave's address (0-F) try: # Use context managers for reliable port handling if sharing a port manually # If passing port name to ElliptecRotator, it handles opening/closing. # Here, we instantiate them separately. master_rot = ElliptecRotator(SERIAL_PORT, MASTER_ADDR, "Master", debug=True) slave_rot = ElliptecRotator(SERIAL_PORT, SLAVE_ADDR, "Slave", debug=True) # --- Synchronization Setup --- slave_offset_deg = 30.0 # Slave will move to (target + 30 degrees) master_offset_deg = 0.0 # Master moves to target directly print(f"Configuring Slave (Addr {slave_rot.physical_address}) to listen to Master (Addr {master_rot.physical_address}) with {slave_offset_deg} deg offset...") if slave_rot.configure_as_group_slave(master_rot.physical_address, slave_offset_deg, debug=True): print("Slave configured successfully.") # Optionally set an offset for the master itself for the group move master_rot.group_offset_degrees = master_offset_deg else: print("Failed to configure slave!") raise RuntimeError("Slave configuration failed") # --- Perform Synchronized Move --- target_angle = 45.0 print(f"Sending synchronized move command to Master address {master_rot.physical_address} for logical target {target_angle} deg...") # Command is sent to master_rot's address. Both master and slave (listening on master's addr) will react. # Each applies its own offset internally. if master_rot.move_absolute(target_angle, wait=True, debug=True): print("Synchronized move command sent and completed.") else: print("Synchronized move failed.") time.sleep(1) # Verify positions (update_position handles offset adjustment for slaves) master_pos = master_rot.update_position(debug=True) slave_pos_logical = slave_rot.update_position(debug=True) # update_position returns the logical position for a slave print(f"Master final position: {master_pos:.2f} deg (Expected physical: {target_angle + master_offset_deg:.2f})") # Note: Slave's *physical* position would be target_angle + slave_offset_deg # update_position for a slave returns the logical position (physical - offset) print(f"Slave final logical position: {slave_pos_logical:.2f} deg (Expected logical: {target_angle:.2f})") # --- Revert Synchronization --- print("Reverting slave from group mode...") if slave_rot.revert_from_group_slave(debug=True): print("Slave reverted successfully.") else: print("Failed to revert slave.") master_rot.group_offset_degrees = 0.0 # Clear master offset too # Rotators now respond to their individual physical addresses again. except serial.SerialException as e: print(f"Serial port error: {e}") except Exception as e: print(f"An error occurred: {e}") finally: # Ensure ports are closed if necessary - ElliptecRotator closes implicitly # if it opened the port based on a string name. If you passed an open # serial object, you might need to close it manually here. print("Cleanup done.") ``` -------------------------------- ### Sending Command to ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Sends a low-level command to the rotator and processes the response. Handles addressing, timeouts, and optional overrides. Returns the device response string or an empty string on failure. ```python send_command(command, data=None, debug=False, timeout=None, send_addr_override=None, expect_reply_from_addr=None, timeout_multiplier=1.0) -> str ``` -------------------------------- ### Homing ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Initiates the homing procedure for the rotator. The `wait` parameter controls whether the method blocks until homing is complete. Returns True if the command was sent successfully. ```python home(wait=True) -> bool ``` -------------------------------- ### Configuring ElliptecRotator as Group Slave in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Configures this rotator to act as a slave in a synchronized group, listening to commands sent to a specified master address. An optional angular offset can be applied. Returns True if the configuration command was successful. ```python configure_as_group_slave(master_address_to_listen_to, slave_offset=0.0, debug=False) -> bool ``` -------------------------------- ### Waiting Until ElliptecRotator is Ready in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Blocks execution until the rotator reports being ready or a specified timeout occurs. Useful before sending movement commands. ```python wait_until_ready(timeout=None) ``` -------------------------------- ### Moving ElliptecRotator by Relative Amount in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Commands the rotator to move by a specified angular amount relative to its current position. Positive degrees move forward/clockwise, negative backward/counter-clockwise. Returns True if successful. ```python move_relative(degrees, wait=True) -> bool ``` -------------------------------- ### Moving ElliptecRotator to Absolute Position in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Commands the rotator to move to a specific absolute angular position (0-360 degrees). The `wait` parameter controls blocking until completion. Returns True if the command was sent. Applies group offset if configured. ```python move_absolute(degrees, wait=True, debug=False) -> bool ``` -------------------------------- ### Setting Velocity of ElliptecRotator in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Sets the rotation speed of the rotator. The velocity is specified as an integer between 0 and 63. Returns True if the command was successful. ```python set_velocity(velocity) -> bool ``` -------------------------------- ### Stopping ElliptecRotator Movement in Python Source: https://github.com/thefermisea/elliptec-controller/blob/main/docs/api.md Immediately stops any ongoing movement of the rotator. Returns True if the stop command was successfully sent. ```python stop() -> bool ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.