### Monitor EPIC Controller I/O Source: https://context7.com/optodeveloper/optommp/llms.txt A complete example for continuous monitoring of I/O points and scratchpad values. ```python import optommp import time def monitor_epic(host, duration_seconds=60): """Monitor an EPIC controller for a specified duration.""" device = None try: # Connect to the controller device = optommp.O22MMP(host) # Display device information print(f"Connected to: {device.UnitDescription()}") print(f"Firmware: {device.FirmwareVersion()}") print(f"IP (E0): {device.IPAddressE0()}") print("-" * 40) start_time = time.time() while (time.time() - start_time) < duration_seconds: # Read digital inputs (module 0, channels 0-3) digital_states = [] for ch in range(4): state = device.GetDigitalPointState(0, ch) digital_states.append(state) print(f"Digital inputs: {digital_states}") # Read analog inputs (module 0, channels 0-1) for ch in range(2): value = device.GetAnalogPointValue(0, ch) min_v = device.GetAnalogPointMin(0, ch) max_v = device.GetAnalogPointMax(0, ch) print(f"Analog ch{ch}: {value:.2f} (range: {min_v}-{max_v})") # Check scratchpad for commands command = device.GetScratchPadStringArea(0) if command: print(f"Command received: {command}") # Update status in scratchpad device.SetScratchPadStringArea(1, f"Last check: {time.ctime()}") print("-" * 40) time.sleep(1) except Exception as e: print(f"Error: {e}") finally: if device: device.close() print("Connection closed.") # Run the monitor monitor_epic('192.168.1.100', duration_seconds=30) ``` -------------------------------- ### Get OptoMMP Device Information Source: https://context7.com/optodeveloper/optommp/llms.txt Retrieves the unit description, firmware version, and last error code from the Opto 22 controller. Useful for identifying the device and troubleshooting. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Get the unit description (e.g., "GRV-EPIC-PR1") unit = device.UnitDescription() print(f"Connected to: {unit}") # Get the firmware version (e.g., "R1.1a") firmware = device.FirmwareVersion() print(f"Firmware version: {firmware}") # Check the last error code for troubleshooting error_code = device.LastError() print(f"Last error code: {error_code}") device.close() ``` -------------------------------- ### Initialize OptoMMP Connection Source: https://context7.com/optodeveloper/optommp/llms.txt Establishes a TCP connection to an Opto 22 EPIC controller. Use the controller's IP address or omit for localhost. Ensure the connection is closed when finished. ```python import optommp # Connect to a remote Opto 22 EPIC controller by IP address device = optommp.O22MMP('192.168.1.100') # Or connect to localhost (default) for local development local_device = optommp.O22MMP() # Always close the connection when done device.close() ``` -------------------------------- ### Read OptoMMP Network Configuration Source: https://context7.com/optodeveloper/optommp/llms.txt Retrieves IP and MAC addresses for both Ethernet interfaces (0 and 1) on the Opto 22 controller. Useful for network diagnostics. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Get Ethernet 0 network information ip_e0 = device.IPAddressE0() mac_e0 = device.MACAddressE0() print(f"Ethernet 0: IP={ip_e0}, MAC={mac_e0}") # Get Ethernet 1 network information ip_e1 = device.IPAddressE1() mac_e1 = device.MACAddressE1() print(f"Ethernet 1: IP={ip_e1}, MAC={mac_e1}") device.close() ``` -------------------------------- ### Write and Read Scratchpad Float Values Source: https://context7.com/optodeveloper/optommp/llms.txt Demonstrates storing and retrieving floating-point numbers in the scratchpad memory area. ```python # Write a float value to scratchpad index 0 status = device.SetScratchPadFloatArea(0, 3.14159) print(f"Write status: {status}") # Returns 0 on success # Read the float value back from scratchpad index 0 value = device.GetScratchPadFloatArea(0) print(f"Float at index 0: {value}") # Returns 3.14159 # Store temperature readings in scratchpad temperatures = [72.5, 68.3, 75.1, 70.8] for i, temp in enumerate(temperatures): device.SetScratchPadFloatArea(i, temp) # Retrieve all stored temperatures for i in range(len(temperatures)): temp = device.GetScratchPadFloatArea(i) print(f"Temperature {i}: {temp}°F") device.close() ``` -------------------------------- ### ScratchPad Access Functions Source: https://github.com/optodeveloper/optommp/blob/master/README.md Functions for interacting with the device's scratchpad memory area for integers, floats, and strings. ```APIDOC ## GetScratchPadIntegerArea(index) ### Description Returns the integer value at the specified scratchpad index. ### Parameters - **index** (int) - Required - The scratchpad index. ## SetScratchPadIntegerArea(index, value) ### Description Sets the integer value at the specified scratchpad index. ### Parameters - **index** (int) - Required - The scratchpad index. - **value** (int) - Required - The value to set. ## GetScratchPadFloatArea(index) ### Description Returns the float value at the specified scratchpad index. ### Parameters - **index** (int) - Required - The scratchpad index. ## SetScratchPadFloatArea(index, value) ### Description Sets the float value at the specified scratchpad index. ### Parameters - **index** (int) - Required - The scratchpad index. - **value** (float) - Required - The value to set. ``` -------------------------------- ### Read and Write Digital I/O Points Source: https://context7.com/optodeveloper/optommp/llms.txt Controls digital outputs (ON/OFF) and reads digital input states using module and channel numbers. State values are 1 for ON and 0 for OFF. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Read the current state of digital point on module 0, channel 2 module = 0 channel = 2 state = device.GetDigitalPointState(module, channel) print(f"Digital point state: {state}") # Returns 1 or 0 # Turn ON a digital output on module 0, channel 3 status = device.SetDigitalPointState(0, 3, 1) print(f"Set digital point status: {status}") # Returns 0 on success # Turn OFF the same digital output status = device.SetDigitalPointState(0, 3, 0) print(f"Set digital point status: {status}") device.close() ``` -------------------------------- ### Read and Write Analog I/O Points Source: https://context7.com/optodeveloper/optommp/llms.txt Reads analog input values and writes to analog outputs as floating-point numbers. Also retrieves the configured min/max ranges for each channel. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Read the current value of an analog point on module 0, channel 1 module = 0 channel = 1 value = device.GetAnalogPointValue(module, channel) print(f"Analog value: {value}") # Returns float (e.g., 4.235) # Get the configured min/max range for the analog point min_val = device.GetAnalogPointMin(module, channel) max_val = device.GetAnalogPointMax(module, channel) print(f"Range: {min_val} to {max_val}") # Write a value to an analog output on module 0, channel 0 status = device.SetAnalogPointValue(0, 0, 5.5) print(f"Set analog point status: {status}") # Returns 0 on success device.close() ``` -------------------------------- ### I/O Access Functions Source: https://github.com/optodeveloper/optommp/blob/master/README.md Functions for reading and writing states and values to digital and analog I/O modules. ```APIDOC ## SetDigitalPointState(module, channel, state) ### Description Toggles the digital output at the specified channel on a module. ### Parameters - **module** (int) - Required - The module index. - **channel** (int) - Required - The channel index. - **state** (int) - Required - The state to set (0 or 1). ## GetDigitalPointState(module, channel) ### Description Fetches the current state of a digital point. ### Parameters - **module** (int) - Required - The module index. - **channel** (int) - Required - The channel index. ### Response - **state** (int) - Returns 0 or 1. ## GetAnalogPointValue(module, channel) ### Description Returns the current float value of an analog I/O point. ### Parameters - **module** (int) - Required - The module index. - **channel** (int) - Required - The channel index. ### Response - **value** (float) - The current analog value. ## SetAnalogPointValue(module, channel, value) ### Description Sets the analog I/O point to a specific float value. ### Parameters - **module** (int) - Required - The module index. - **channel** (int) - Required - The channel index. - **value** (float) - Required - The value to set. ``` -------------------------------- ### Perform Low-Level Memory Block Operations Source: https://context7.com/optodeveloper/optommp/llms.txt Use ReadBlock and WriteBlock for direct memory access and data packing. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Read 4 bytes from a memory address address = 0xF030000C # Last error address data = device.ReadBlock(address, 4) value = device.UnpackReadResponse(data, 'i') print(f"Read value: {value}") # Pack and write a float value to memory float_value = 25.5 packed = device.PackFloat(float_value) print(f"Packed float bytes: {packed}") # e.g., [65, 204, 0, 0] # Pack and write an integer value to memory int_value = 500 packed_int = device.PackInteger(int_value) print(f"Packed integer bytes: {packed_int}") # e.g., [0, 0, 1, 244] device.close() ``` -------------------------------- ### Work with ScratchPad Float Area Source: https://context7.com/optodeveloper/optommp/llms.txt Reads and writes floating-point values in the scratchpad memory area for sharing decimal data between processes. This snippet is a placeholder and requires implementation. ```python import optommp device = optommp.O22MMP('192.168.1.100') ``` -------------------------------- ### Work with ScratchPad Integer Area Source: https://context7.com/optodeveloper/optommp/llms.txt Reads and writes 32-bit integer values in the scratchpad memory area for inter-process communication. Supports single and multiple index operations. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Write an integer value to scratchpad index 0 status = device.SetScratchPadIntegerArea(0, 12345) print(f"Write status: {status}") # Returns 0 on success # Read the integer value back from scratchpad index 0 value = device.GetScratchPadIntegerArea(0) print(f"Integer at index 0: {value}") # Returns 12345 # Write and read multiple indices for i in range(5): device.SetScratchPadIntegerArea(i, i * 100) for i in range(5): val = device.GetScratchPadIntegerArea(i) print(f"Index {i}: {val}") # 0, 100, 200, 300, 400 device.close() ``` -------------------------------- ### Read Raw Memory Addresses Source: https://context7.com/optodeveloper/optommp/llms.txt Access specific memory locations directly using hexadecimal offset addresses. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Read 4 bytes from a specific memory offset as an integer # Offset is specified as a hex string value = device.ReadRawOffset('F030000C', 4, 'i') print(f"Raw integer value: {value}") # Read 4 bytes as a float float_val = device.ReadRawOffset('F0D82000', 4, 'f') print(f"Raw float value: {float_val}") # Read raw binary data (no formatting) raw_data = device.ReadRawOffset('F0300080', 12, 'NONE') print(f"Raw binary: {raw_data}") device.close() ``` -------------------------------- ### Manage Scratchpad String Area Source: https://context7.com/optodeveloper/optommp/llms.txt Read and write string values up to 127 characters in the scratchpad memory area. ```python import optommp device = optommp.O22MMP('192.168.1.100') # Write a string value to scratchpad index 0 status = device.SetScratchPadStringArea(0, "Hello EPIC!") print(f"Write status: {status}") # Returns 0 on success # Read the string value back from scratchpad index 0 text = device.GetScratchPadStringArea(0) print(f"String at index 0: {text}") # Returns "Hello EPIC!" # Store status messages in different indices device.SetScratchPadStringArea(0, "System Running") device.SetScratchPadStringArea(1, "Batch #12345") device.SetScratchPadStringArea(2, "Operator: John") # Read status messages for i in range(3): msg = device.GetScratchPadStringArea(i) print(f"Message {i}: {msg}") device.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.