Skip to content

Instantly share code, notes, and snippets.

@Bouni
Last active June 13, 2024 07:37
Show Gist options
  • Save Bouni/7b28a8521c963b6b048d9323ba12e45b to your computer and use it in GitHub Desktop.
Save Bouni/7b28a8521c963b6b048d9323ba12e45b to your computer and use it in GitHub Desktop.
Read SICK FlexiSoft GMOD gateway data using pymodbus
# See https://cdn.sick.com/media/docs/6/86/086/Operating_instructions_Flexi_Soft_Gateways_in_the_Safety_Designer_Configuration_software_de_IM0081086.PDF
# Page 36
from pymodbus.client import ModbusTcpClient as ModbusClient
IP = "192.168.255.3"
PORT = 502
ADDRESS = 1100
REGISTERS = 25
SLAVE_ID = 1
client = ModbusClient(IP, port=PORT)
client.connect()
# Address must be subtracted by 1
response = client.read_holding_registers(ADDRESS - 1, REGISTERS, SLAVE_ID)
# Split 16bit ints into 8bit and swap them in order to resable the exact layout shown in the FlexiSoft Designer
data = sum(
[[(register & 0xFF), (register >> 8 & 0xFF)] for register in response.registers], []
)
for n, register in enumerate(data,1):
print(f"{n} {register:08b}")
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment