### Install fsuipc Package Source: https://github.com/tjensen/fsuipc/blob/master/README.md Use pip to install the fsuipc package. This package is only supported on Windows platforms. ```bash pip install fsuipc ``` -------------------------------- ### Check Python Version (32/64-bit) Source: https://github.com/tjensen/fsuipc/blob/master/README.md Determine if your Python installation is 32-bit or 64-bit. This is important for compatibility with flight simulator software. ```bash python -VV ``` -------------------------------- ### Get Simulator and FSUIPC Version Information Source: https://context7.com/tjensen/fsuipc/llms.txt Retrieve the simulator's version, the FSUIPC version string, and the client library version string. Constants like `SIM_FSX` are available for mapping simulator versions. ```python from fsuipc import FSUIPC, SIM_ANY, SIM_FSX, SIM_P3D, SIM_P3D64, SIM_FS2020 with FSUIPC() as fsuipc: # Get simulator version constant sim_version = fsuipc.get_simulator_version() # Map version to name sim_names = { SIM_FSX: "FSX (32-bit)", SIM_P3D: "Prepar3D (32-bit)", SIM_P3D64: "Prepar3D (64-bit)", SIM_FS2020: "Microsoft Flight Simulator 2020" } print(f"Simulator: {sim_names.get(sim_version, 'Unknown')}") # Get FSUIPC version string (e.g., "7.023a") fsuipc_ver = fsuipc.get_fsuipc_version() print(f"FSUIPC Version: {fsuipc_ver}") # Get client library version string (e.g., "2.011") lib_ver = fsuipc.get_library_version() print(f"Library Version: {lib_ver}") ``` -------------------------------- ### Connect to FSUIPC Client Source: https://context7.com/tjensen/fsuipc/llms.txt Demonstrates how to establish a connection to the FSUIPC client. Supports connecting to any available simulator or a specific simulator type. Includes basic connection using a context manager and manual connection management. ```python from fsuipc import FSUIPC, SIM_ANY, SIM_FSX, SIM_P3D64, SIM_FS2020, FSUIPCException # Basic connection - connects to any available simulator with FSUIPC() as fsuipc: # Read single offset - aircraft altitude (8-byte signed integer at offset 0x570) altitude = fsuipc.read([(0x570, "l")]) print(f"Altitude: {altitude[0]} units") # Connect to a specific simulator type try: with FSUIPC(version=SIM_FS2020) as fsuipc: print("Connected to Microsoft Flight Simulator 2020") except FSUIPCException as e: print(f"Connection failed: {e}") # Manual connection management (not recommended) fsuipc = FSUIPC() try: data = fsuipc.read([(0x560, "l")]) finally: fsuipc.close() ``` -------------------------------- ### Version and Connection Info Methods Source: https://context7.com/tjensen/fsuipc/llms.txt Methods for retrieving version information about the simulator, FSUIPC, and the client library. ```APIDOC ## Version and Connection Info Methods ### Description Methods for retrieving version information about the simulator, FSUIPC, and the client library. ### Methods - `get_simulator_version()`: Returns a constant representing the simulator version. - `get_fsuipc_version()`: Returns the FSUIPC version string. - `get_library_version()`: Returns the client library version string. ### Parameters None for these methods. ### Request Example ```python from fsuipc import FSUIPC, SIM_ANY, SIM_FSX, SIM_P3D, SIM_P3D64, SIM_FS2020 with FSUIPC() as fsuipc: # Get simulator version constant sim_version = fsuipc.get_simulator_version() # Map version to name sim_names = { SIM_FSX: "FSX (32-bit)", SIM_P3D: "Prepar3D (32-bit)", SIM_P3D64: "Prepar3D (64-bit)", SIM_FS2020: "Microsoft Flight Simulator 2020" } print(f"Simulator: {sim_names.get(sim_version, 'Unknown')}") # Get FSUIPC version string (e.g., "7.023a") fsuipc_ver = fsuipc.get_fsuipc_version() print(f"FSUIPC Version: {fsuipc_ver}") # Get client library version string (e.g., "2.011") lib_ver = fsuipc.get_library_version() print(f"Library Version: {lib_ver}") ``` ### Response #### Success Response (200) - **sim_version** (int) - A constant representing the simulator version. - **fsuipc_ver** (str) - The FSUIPC version string. - **lib_ver** (str) - The client library version string. #### Response Example ``` Simulator: Microsoft Flight Simulator 2020 FSUIPC Version: 7.023a Library Version: 2.011 ``` ``` -------------------------------- ### PreparedData.read() Source: https://context7.com/tjensen/fsuipc/llms.txt Reads data from the flight simulator using a pre-prepared data specification. Returns values in the same order as the specification. ```APIDOC ## PreparedData.read() ### Description Reads data from the flight simulator using a pre-prepared data specification. Returns values in the same order as the specification. ### Method `read()` ### Endpoint N/A (Method of a `PreparedData` object) ### Parameters None ### Request Example ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Create prepared data for flight instruments instruments = fsuipc.prepare_data([ (0x0570, "l"), # Altitude (0x02BC, "d"), # Indicated airspeed (0x0580, "d"), # Magnetic heading (0x036C, "d"), # Vertical speed (0x0366, "b"), # Gear position (0x0BE8, "H"), # Flaps position ], for_reading=True) # Continuous monitoring loop while True: altitude, airspeed, heading, vs, gear, flaps = instruments.read() print(f"ALT: {altitude:>8} | SPD: {airspeed:>5} | HDG: {heading:>3}") print(f"VS: {vs:>8} | GEAR: {'DOWN' if gear else 'UP':>4} | FLAPS: {flaps:>5}") print("-" * 50) input("Press ENTER to refresh") ``` ### Response #### Success Response (200) Returns a tuple of values corresponding to the prepared data specification. #### Response Example ``` (10000, 150.5, 180.0, -50.0, 0, 4096) ``` ``` -------------------------------- ### Write Data to Flight Simulator Source: https://context7.com/tjensen/fsuipc/llms.txt Use `PreparedData.write()` to send data to the simulator. The values must be provided in a list, matching the order defined when the data specification was prepared with `for_reading=False`. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Prepare control surfaces for writing controls = fsuipc.prepare_data([ (0x0BB2, "h"), # Elevator trim (-16383 to 16383) (0x0BC8, "H"), # Parking brake (0 or 32767) (0x0BE8, "H"), # Flaps (0-16383) (0x0366, "b"), # Gear handle (0=up, 1=down) ], for_reading=False) # Set takeoff configuration controls.write([ 0, # Elevator trim: neutral 0, # Parking brake: off 4096, # Flaps: ~25% 1, # Gear: down ]) # After takeoff - retract gear and flaps controls.write([ 500, # Elevator trim: slight nose up 0, # Parking brake: off 0, # Flaps: up 0, # Gear: up ]) ``` -------------------------------- ### PreparedData.write() Source: https://context7.com/tjensen/fsuipc/llms.txt Writes data to the flight simulator using a pre-prepared data specification. Values are written in the order defined during preparation. ```APIDOC ## PreparedData.write() ### Description Writes data to the flight simulator using a pre-prepared data specification. Values are written in the order defined during preparation. ### Method `write(values)` ### Endpoint N/A (Method of a `PreparedData` object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **values** (list) - Required - A list of values to write, in the same order as defined in the `prepare_data` call. ### Request Example ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Prepare control surfaces for writing controls = fsuipc.prepare_data([ (0x0BB2, "h"), # Elevator trim (-16383 to 16383) (0x0BC8, "H"), # Parking brake (0 or 32767) (0x0BE8, "H"), # Flaps (0-16383) (0x0366, "b"), # Gear handle (0=up, 1=down) ], for_reading=False) # Set takeoff configuration controls.write([ 0, # Elevator trim: neutral 0, # Parking brake: off 4096, # Flaps: ~25% 1, # Gear: down ]) # After takeoff - retract gear and flaps controls.write([ 500, # Elevator trim: slight nose up 0, # Parking brake: off 0, # Flaps: up 0, # Gear: up ]) ``` ### Response #### Success Response (200) No explicit return value, indicates successful write operation. #### Response Example (No direct response example, as it's a write operation.) ``` -------------------------------- ### FSUIPC.write() Method Source: https://context7.com/tjensen/fsuipc/llms.txt Explains how to use the `write()` method to send data to simulator memory offsets, including writing single values, multiple values, and string data. ```APIDOC ## FSUIPC.write() ### Description Writes data to flight simulator memory using an unprepared data specification. Each tuple contains the offset, data type, and the value to write. ### Method `write(data_to_write)` ### Parameters #### Request Body - **data_to_write** (list of tuples) - Required - A list where each tuple specifies data to write. Each tuple should be in the format `(offset, type_string, value)` or `(offset, length, value)` for strings. - **offset** (int): The memory offset to write to. - **type_string** (str): A character representing the data type (same as in `read()` method). - **length** (int): For writing strings, specifies the fixed length of the byte string. - **value**: The data to write. This should be of the appropriate Python type corresponding to the specified data type (e.g., int for integer types, float for float types, bytes for string types). ### Request Example ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Write single value - set parking brake (offset 0x0BC8) fsuipc.write([(0x0BC8, "H", 32767)]) # 32767 = brake on, 0 = brake off # Write multiple values at once fsuipc.write([ (0x0BC8, "H", 32767), # Parking brake on (0x0366, "b", 1), # Landing gear down (0x0BE8, "H", 16384), # Flaps 50% ]) # Write string data fsuipc.write([ (0x3380, 128, b"KLAX"), # Set departure airport (fixed 128 bytes) ]) # Set specific aircraft position fsuipc.write([ (0x0560, "l", 5586418533), # Latitude (0x0568, "l", -10877009920), # Longitude (0x0570, "l", 30000), # Altitude ]) ``` ``` -------------------------------- ### Basic FSUIPC Usage: Read Flight Data Source: https://github.com/tjensen/fsuipc/blob/master/README.md Demonstrates how to initialize the FSUIPC client, prepare data for reading specific offsets (latitude, longitude, altitude), and continuously read and print this data in a loop. Ensure your Python version matches the simulator's architecture (32-bit or 64-bit) and run as administrator if necessary. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: prepared = fsuipc.prepare_data([ (0x560, "l"), (0x568, "l"), (0x570, "l") ], True) while True: latitude, longitude, altitude = prepared.read() print(f"Latitude: {latitude}") print(f"Longitude: {longitude}") print(f"Altitude: {altitude}") input("Press ENTER to read again") ``` -------------------------------- ### Read Various Data Types from Simulator Source: https://context7.com/tjensen/fsuipc/llms.txt Demonstrates reading different data types including integers, unsigned integers, floats, and zero-terminated strings from specific simulator memory offsets. Ensure the correct data type code is used for each offset. ```python from fsuipc import FSUIPC # Data type codes and their Python equivalents: # # String Types: # "b" = 1-byte unsigned int (0-255) # "c" = 1-byte signed int (-128 to 127) # "h" = 2-byte signed int (-32768 to 32767) # "H" = 2-byte unsigned int (0-65535) # "d" = 4-byte signed int # "u" = 4-byte unsigned int # "l" = 8-byte signed int # "L" = 8-byte unsigned int # "f" = 8-byte double precision float # "F" = 4-byte single precision float # # Integer Types (for strings): # Positive int N = fixed-length string of N bytes (no terminator) # Negative int -N = zero-terminated string, max N bytes with FSUIPC() as fsuipc: # Examples of each type data = fsuipc.read([ (0x0366, "b"), # Gear: 1-byte unsigned (0x0BE8, "H"), # Flaps: 2-byte unsigned (0x02BC, "d"), # Airspeed: 4-byte signed (0x0570, "l"), # Altitude: 8-byte signed (0x6040, "f"), # Latitude: 8-byte float (0x3D00, -256), # Aircraft title: zero-terminated string, max 256 ]) gear, flaps, speed, alt, lat, title = data print(f"Gear: {gear}, Flaps: {flaps}") print(f"Speed: {speed}, Alt: {alt}") print(f"Lat: {lat}") print(f"Title: {title.decode('utf-8').rstrip(chr(0))}") ``` -------------------------------- ### FSUIPC.read() Method Source: https://context7.com/tjensen/fsuipc/llms.txt Details on how to use the `read()` method to retrieve data from simulator memory offsets, including support for various data types and string reading. ```APIDOC ## FSUIPC.read() ### Description Reads data from flight simulator memory using an unprepared data specification. Returns a list of values corresponding to each offset in the specification. ### Method `read(offsets)` ### Parameters #### Request Body - **offsets** (list of tuples) - Required - A list where each tuple specifies an offset to read. Each tuple should be in the format `(offset, type_string)` or `(offset, length)` for strings. - **offset** (int): The memory offset to read from. - **type_string** (str): A character representing the data type: - `b`: 1-byte unsigned integer - `c`: 1-byte signed integer - `h`: 2-byte signed integer - `H`: 2-byte unsigned integer - `d`: 4-byte signed integer - `u`: 4-byte unsigned integer - `l`: 8-byte signed integer - `L`: 8-byte unsigned integer - `f`: 8-byte float - `F`: 4-byte float - **length** (int): For reading strings, a negative value indicates a zero-terminated string, and a positive value indicates a fixed length. ### Response #### Success Response (200) - **list of values** (list) - A list containing the data read from the specified offsets, in the same order as the request. ### Request Example ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Read multiple values at once data = fsuipc.read([ (0x560, "l"), # Latitude (8-byte signed) (0x568, "l"), # Longitude (8-byte signed) (0x570, "l"), # Altitude (8-byte signed) (0x02BC, "d"), # Indicated airspeed (4-byte signed) (0x0580, "d"), # Heading (4-byte signed) (0x036C, "d"), # Vertical speed (4-byte signed) ]) latitude, longitude, altitude, airspeed, heading, vs = data print(f"Position: {latitude}, {longitude}") print(f"Altitude: {altitude}") print(f"Airspeed: {airspeed}") print(f"Heading: {heading}") print(f"VS: {vs}") # Read string data (negative value = zero-terminated, positive = fixed length) aircraft_name = fsuipc.read([(0x3D00, -256)]) # Aircraft title (max 256 chars) print(f"Aircraft: {aircraft_name[0].decode('utf-8').rstrip(chr(0))}") ``` ``` -------------------------------- ### Connect to Simulator and Handle Errors Source: https://context7.com/tjensen/fsuipc/llms.txt Connects to Microsoft Flight Simulator 2020 and demonstrates handling specific FSUIPC exceptions. Ensure the correct simulator version is specified and consider running as administrator if send message errors occur. ```python from fsuipc import ( # Simulator type constants SIM_ANY, SIM_FS98, SIM_FS2K, SIM_CFS2, SIM_CFS1, SIM_FLY, SIM_FS2K2, SIM_FS2K4, SIM_FSX, SIM_ESP, SIM_P3D, SIM_FSX64, SIM_P3D64, SIM_FS2020, # Error code constants ERR_OK, ERR_OPEN, ERR_NOFS, ERR_REGMSG, ERR_ATOM, ERR_MAP, ERR_VIEW, ERR_VERSION, ERR_WRONGFS, ERR_NOTOPEN, ERR_NODATA, ERR_TIMEOUT, ERR_SENDMSG, ERR_DATA, ERR_RUNNING, ERR_SIZE, FSUIPCException, ) # Example: Handle specific errors try: with FSUIPC(version=SIM_FS2020) as fsuipc: data = fsuipc.read([(0x0570, "l")]) except FSUIPCException as e: error_messages = { ERR_NOFS: "No flight simulator is running", ERR_WRONGFS: "Wrong simulator type", ERR_NOTOPEN: "Connection not established", ERR_TIMEOUT: "Communication timeout", ERR_DATA: "Bad data - check 32/64-bit match", ERR_SENDMSG: "Send failed - try running as administrator", } print(f"Error: {error_messages.get(e.args[0], 'Unknown error')}") ``` -------------------------------- ### Read Prepared Data from Flight Simulator Source: https://context7.com/tjensen/fsuipc/llms.txt The `PreparedData.read()` method retrieves data based on a pre-defined specification. Ensure the data is prepared with `for_reading=True`. The returned values correspond to the order specified during preparation. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Create prepared data for flight instruments instruments = fsuipc.prepare_data([ (0x0570, "l"), # Altitude (0x02BC, "d"), # Indicated airspeed (0x0580, "d"), # Magnetic heading (0x036C, "d"), # Vertical speed (0x0366, "b"), # Gear position (0x0BE8, "H"), # Flaps position ], for_reading=True) # Continuous monitoring loop while True: altitude, airspeed, heading, vs, gear, flaps = instruments.read() print(f"ALT: {altitude:>8} | SPD: {airspeed:>5} | HDG: {heading:>3}") print(f"VS: {vs:>8} | GEAR: {'DOWN' if gear else 'UP':>4} | FLAPS: {flaps:>5}") print("-" * 50) input("Press ENTER to refresh") ``` -------------------------------- ### FSUIPC.prepare_data() Source: https://context7.com/tjensen/fsuipc/llms.txt Creates a PreparedData object for optimized repeated reads/writes of the same offsets. This reduces conversion overhead when accessing the same data multiple times. ```APIDOC ## FSUIPC.prepare_data() ### Description Creates a PreparedData object for optimized repeated reads/writes of the same offsets. This reduces conversion overhead when accessing the same data multiple times. ### Method `prepare_data(offsets, for_reading=True)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **offsets** (list of tuples) - Required - A list of tuples, where each tuple contains an offset and its data type string (e.g., `(0x560, "l")`). - **for_reading** (bool) - Optional - If True, prepares for reading; if False, prepares for writing. Defaults to True. ### Request Example ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Prepare data specification for reading position_data = fsuipc.prepare_data([ (0x560, "l"), # Latitude (0x568, "l"), # Longitude (0x570, "l"), # Altitude (0x02BC, "d"), # Airspeed (0x0580, "d"), # Heading ], for_reading=True) # Prepare data for writing only controls_data = fsuipc.prepare_data([ (0x0BC8, "H"), # Parking brake (0x0BE8, "H"), # Flaps ], for_reading=False) # Use in a loop - much more efficient than repeated raw reads import time for _ in range(10): lat, lon, alt, spd, hdg = position_data.read() print(f"Alt: {alt}, Speed: {spd}, Heading: {hdg}") time.sleep(1) ``` ### Response #### Success Response (200) Returns a `PreparedData` object. #### Response Example (No direct response example, as it returns an object for further use.) ``` -------------------------------- ### Prepare Data for Optimized Reads and Writes Source: https://context7.com/tjensen/fsuipc/llms.txt Use `prepare_data` to create optimized data specifications for repeated access. This reduces overhead when reading or writing the same offsets multiple times. Specify `for_reading=True` for read operations and `for_reading=False` for write operations. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Prepare data specification for reading position_data = fsuipc.prepare_data([ (0x560, "l"), # Latitude (0x568, "l"), # Longitude (0x570, "l"), # Altitude (0x02BC, "d"), # Airspeed (0x0580, "d"), # Heading ], for_reading=True) # Prepare data for writing only controls_data = fsuipc.prepare_data([ (0x0BC8, "H"), # Parking brake (0x0BE8, "H"), # Flaps ], for_reading=False) # Use in a loop - much more efficient than repeated raw reads import time for _ in range(10): lat, lon, alt, spd, hdg = position_data.read() print(f"Alt: {alt}, Speed: {spd}, Heading: {hdg}") time.sleep(1) ``` -------------------------------- ### FSUIPC Class Usage Source: https://context7.com/tjensen/fsuipc/llms.txt Demonstrates basic connection and usage of the FSUIPC class, including reading aircraft altitude and connecting to specific simulator versions. ```APIDOC ## FSUIPC Class Usage ### Description The `FSUIPC` class is the main connection class for interacting with flight simulator data through FSUIPC memory offsets. It supports the context manager protocol for automatic resource management. ### Code Examples **Basic Connection and Reading Altitude:** ```python from fsuipc import FSUIPC, SIM_ANY with FSUIPC() as fsuipc: # Read single offset - aircraft altitude (8-byte signed integer at offset 0x570) altitude = fsuipc.read([(0x570, "l")]) print(f"Altitude: {altitude[0]} units") ``` **Connecting to a Specific Simulator (FS2020):** ```python from fsuipc import FSUIPC, SIM_FS2020, FSUIPCException try: with FSUIPC(version=SIM_FS2020) as fsuipc: print("Connected to Microsoft Flight Simulator 2020") except FSUIPCException as e: print(f"Connection failed: {e}") ``` **Manual Connection Management (Not Recommended):** ```python from fsuipc import FSUIPC fsuipc = FSUIPC() try: data = fsuipc.read([(0x560, "l")]) finally: fsuipc.close() ``` ``` -------------------------------- ### Write Data to FSUIPC Source: https://context7.com/tjensen/fsuipc/llms.txt Writes data to flight simulator memory using unprepared data specifications. Each tuple contains offset, type, and the value to write. Supports writing single values, multiple values, strings, and setting aircraft position. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Write single value - set parking brake (offset 0x0BC8) fsuipc.write([(0x0BC8, "H", 32767)]) # 32767 = brake on, 0 = brake off # Write multiple values at once fsuipc.write([ (0x0BC8, "H", 32767), # Parking brake on (0x0366, "b", 1), # Landing gear down (0x0BE8, "H", 16384), # Flaps 50% ]) # Write string data fsuipc.write([ (0x3380, 128, b"KLAX"), # Set departure airport (fixed 128 bytes) ]) # Set specific aircraft position fsuipc.write([ (0x0560, "l", 5586418533), # Latitude (0x0568, "l", -10877009920), # Longitude (0x0570, "l", 30000), # Altitude ]) ``` -------------------------------- ### Read Data from FSUIPC Source: https://context7.com/tjensen/fsuipc/llms.txt Reads data from flight simulator memory using unprepared data specifications. Supports various data types including integers, floats, and strings. Returns a list of values corresponding to each offset. ```python from fsuipc import FSUIPC with FSUIPC() as fsuipc: # Read multiple values at once # Offset types: b=1-byte unsigned, c=1-byte signed, h=2-byte signed, # H=2-byte unsigned, d=4-byte signed, u=4-byte unsigned, # l=8-byte signed, L=8-byte unsigned, f=8-byte float, F=4-byte float data = fsuipc.read([ (0x560, "l"), # Latitude (8-byte signed) (0x568, "l"), # Longitude (8-byte signed) (0x570, "l"), # Altitude (8-byte signed) (0x02BC, "d"), # Indicated airspeed (4-byte signed) (0x0580, "d"), # Heading (4-byte signed) (0x036C, "d"), # Vertical speed (4-byte signed) ]) latitude, longitude, altitude, airspeed, heading, vs = data print(f"Position: {latitude}, {longitude}") print(f"Altitude: {altitude}") print(f"Airspeed: {airspeed}") print(f"Heading: {heading}") print(f"VS: {vs}") # Read string data (negative value = zero-terminated, positive = fixed length) aircraft_name = fsuipc.read([(0x3D00, -256)]) # Aircraft title (max 256 chars) print(f"Aircraft: {aircraft_name[0].decode('utf-8').rstrip(chr(0))}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.