Skip to content

Instantly share code, notes, and snippets.

@Rahix
Last active October 29, 2022 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rahix/26e391acfbecac2215305c2ae7fcf5c3 to your computer and use it in GitHub Desktop.
Save Rahix/26e391acfbecac2215305c2ae7fcf5c3 to your computer and use it in GitHub Desktop.
Script to scan a PROFIBUS network for all online peripherals using pyprofibus
# SPDX-License-Identifier: GPL-2.0-or-later
from pyprofibus import phy_serial
from pyprofibus import fdl
import pyprofibus
def main():
phy = phy_serial.CpPhySerial("/dev/ttyUSB0")
phy.setConfig(baudrate=phy_serial.CpPhy.BAUD_19200)
phy.debug = 1
xceiv = fdl.FdlTransceiver(phy)
xceiv.setRXFilter(None)
i = 3
while True:
print(f"Ping {i:3}...")
fcb = fdl.FdlFCB()
telegram = fdl.FdlTelegram_FdlStat_Req(da=i, sa=2)
xceiv.send(fcb, telegram)
i += 1
try:
ok, telegram = xceiv.poll(0.2)
if ok and not not telegram:
print(telegram)
else:
print("Nothing")
except Exception as e:
print(f"Error: {e}")
if i == 126:
break
print("Done.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment