Files
2026-09-02 07:37:44 +02:00

40 lines
998 B
Python

import pyads
import struct
PLC_IP = "129.129.181.207"
AMS_NET_ID = "5.17.17.136.1.1"
PLC_PORT = pyads.PORT_TC3PLC1
NC_PORT = 501
# plc = pyads.Connection(AMS_NET_ID, PLC_PORT, PLC_IP)
# plc.open()
nc = pyads.Connection(AMS_NET_ID, NC_PORT, PLC_IP)
print(nc)
symbols = nc.get_all_symbols()
print(symbols)
import pyads
# 1. Verbindung zum lokalen PLC/NC-System herstellen
# AMS NetID "127.0.0.1.1.1" steht für das lokale System.
# Falls remote, passe die NetID entsprechend an.
nc = pyads.Connection(AMS_NET_ID, NC_PORT, PLC_IP)
try:
nc.open()
# Pfad aus dem Target Browser (Port 501 / NC-Task):
# 'Axes.EncoderTest.ActPos' oder 'TCNC.NcTaskSaf.Axes.EncoderTest.ActPos'
symbol_name = 'Axes.EncoderTest.ActPos'
# Istposition auslesen (NC-Positionen sind gewöhnlich LREAL / 64-Bit Float)
act_pos = nc.read_by_name(symbol_name, plc_datatype=pyads.PLCTYPE_LREAL)
print(f"Aktuelle Position von EncoderTest: {act_pos:.4f} mm")
finally:
nc.close()