modbus_MediaPipe/send_W_value.py

15 lines
354 B
Python

import socket
PLC_IP = "169.254.11.8" # 換成你的 PLC IP
PLC_PORT = 5000
message = "W=99;"
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((PLC_IP, PLC_PORT))
s.sendall(message.encode())
print(f"[Python] 已傳送: {message}")
except Exception as e:
print(f"[Python] 傳送失敗: {e}")