Skip to content

Instantly share code, notes, and snippets.

@Rahix
Last active Oct 29, 2022
Embed
What would you like to do?
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