DeaD_EyE

SMC EX260-SIL1-X210 address mapping

Aug 7th, 2020
968
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. """
  4. Address mapping of SMC EX260-SIL1-X210 for IO-Link
  5.  
  6.  
  7.  
  8. The package rich is required to display the result in a table.
  9. Windows: py -3 -m pip install rich
  10. Linux: pip3 install rich
  11. """
  12.  
  13. from itertools import count
  14.  
  15. from rich.console import Console
  16. from rich.table import Table
  17.  
  18.  
  19. def get_valve_mapping(start, size):
  20.     size //= 4
  21.     valve = count(1)
  22.     for byte in reversed(range(start, start + size)):
  23.         for bit in range(8):
  24.             yield f"M{next(valve)}", f"Q{byte}.{bit}"
  25.  
  26.  
  27. def print_valve_mapping(start, size=32):
  28.     console = Console()
  29.     table = Table()
  30.     table.add_column("Valve")
  31.     table.add_column("Address")
  32.     for row in get_valve_mapping(start, size):
  33.         table.add_row(*row)
  34.     console.print(table)
  35.  
  36.  
  37. if __name__ == "__main__":
  38.     start_address = 132
  39.     size_bits = 16
  40.     print_valve_mapping(start_address, size_bits)
  41.  
RAW Paste Data