Last active
October 29, 2022 09:54
-
-
Save Rahix/26e391acfbecac2215305c2ae7fcf5c3 to your computer and use it in GitHub Desktop.
Script to scan a PROFIBUS network for all online peripherals using pyprofibus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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