-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhses_read_write_reals.py
More file actions
55 lines (44 loc) · 1.71 KB
/
Copy pathhses_read_write_reals.py
File metadata and controls
55 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
HSES - Read and Write Real Variables
======================================
Read and write real (floating point) variables (D variables) on the robot.
"""
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
from examples import connect_robot
print("=" * 60)
print(" YASKAWA SDK - HSES: Read/Write Real Variables")
print("=" * 60)
robot = connect_robot()
try:
while True:
print("\n 1. Read real variables")
print(" 2. Write real variable")
print(" 0. Quit")
choice = input("\nChoice: ").strip()
if choice == "0":
break
elif choice == "1":
start_str = input("Start index (default 0): ").strip()
start = int(start_str) if start_str else 0
count_str = input("Count (default 5): ").strip()
count = int(count_str) if count_str else 5
print(f"\nReading real variables {start} to {start + count - 1}...")
data = robot.high_speed_e_server.read_real(start, count)
for i, val in enumerate(data.value, start=start):
print(f" D[{i}] = {val}")
elif choice == "2":
idx_str = input("Variable index: ").strip()
if not idx_str:
continue
idx = int(idx_str)
val_str = input(f"Value for D[{idx}] (comma-separated for multiple): ").strip()
if not val_str:
continue
values = [float(v.strip()) for v in val_str.split(",")]
print(f"\nWriting {values} at index {idx}...")
result = robot.high_speed_e_server.write_real(idx, values)
print("Done.")
finally:
robot.disconnect()
print("\nDisconnected.")