Skip to content

Commit 683b4e8

Browse files
committed
ADD warning if trying to load data from tcp/ws listener without starting the server first
1 parent 2588656 commit 683b4e8

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/gh/components/DF_tcp_listener/code.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,20 @@ def stop_server():
114114

115115
# Load buffered points into Rhino PointCloud
116116
if i_load and not sc.sticky[f'{prefix}_prev_load']:
117-
raw = sc.sticky.get(f'{prefix}_cloud_buffer_raw', [])
118-
if raw:
119-
pc = rg.PointCloud()
120-
for x, y, z, r, g, b in raw:
121-
pc.Add(rg.Point3d(x, y, z), sd.Color.FromArgb(int(r), int(g), int(b)))
122-
sc.sticky[f'{prefix}_latest_cloud'] = pc
123-
sc.sticky[f'{prefix}_status_message'] = f'Loaded pcd with {pc.Count} pts'
117+
if not sc.sticky.get(f'{prefix}_server_started', False):
118+
self.AddRuntimeMessage(self.RuntimeMessageLevel.Warning,
119+
"Please start server here before trying to send data from remote device.")
120+
sc.sticky[f'{prefix}_status_message'] = "Server not started"
124121
else:
125-
sc.sticky[f'{prefix}_status_message'] = 'No data buffered'
122+
raw = sc.sticky.get(f'{prefix}_cloud_buffer_raw', [])
123+
if raw:
124+
pc = rg.PointCloud()
125+
for x, y, z, r, g, b in raw:
126+
pc.Add(rg.Point3d(x, y, z), sd.Color.FromArgb(int(r), int(g), int(b)))
127+
sc.sticky[f'{prefix}_latest_cloud'] = pc
128+
sc.sticky[f'{prefix}_status_message'] = f'Loaded pcd with {pc.Count} pts'
129+
else:
130+
sc.sticky[f'{prefix}_status_message'] = 'No data buffered'
126131

127132
# Update previous states
128133
sc.sticky[f'{prefix}_prev_start'] = i_start

src/gh/components/DF_websocket_listener/code.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ def run_server():
107107

108108
# LOAD buffered PCD on i_load rising edge
109109
if i_load and not sc.sticky[f'{prefix}_prev_load']:
110-
sc.sticky[f'{prefix}_loaded_pcd'] = sc.sticky.get(f'{prefix}_last_pcd')
111-
cnt = len(sc.sticky[f'{prefix}_loaded_pcd']) if sc.sticky[f'{prefix}_loaded_pcd'] else 0
112-
logs.append(f"Loaded pcd with {cnt} pts")
113-
ghenv.Component.ExpireSolution(True) # noqa: F821
110+
if not sc.sticky.get(f'{prefix}_server'):
111+
self.AddRuntimeMessage(self.RuntimeMessageLevel.Warning,
112+
"Please start server here before trying to send data from remote device.")
113+
logs.append("Server not started")
114+
else:
115+
sc.sticky[f'{prefix}_loaded_pcd'] = sc.sticky.get(f'{prefix}_last_pcd')
116+
cnt = len(sc.sticky[f'{prefix}_loaded_pcd']) if sc.sticky[f'{prefix}_loaded_pcd'] else 0
117+
logs.append(f"Loaded pcd with {cnt} pts")
118+
ghenv.Component.ExpireSolution(True) # noqa: F821
114119

115120
# BUILD output PointCloud
116121
raw = sc.sticky.get(f'{prefix}_loaded_pcd')
@@ -127,7 +132,7 @@ def run_server():
127132
# UPDATE UI message & return outputs
128133
ghenv.Component.Message = logs[-1] if logs else 'Waiting..' # noqa: F821
129134
sc.sticky[f'{prefix}_prev_start'] = i_start
130-
sc.sticky[f'{prefix}_prev_stop'] = i_stop
131-
sc.sticky[f'{prefix}_prev_load'] = i_load
135+
sc.sticky[f'{prefix}_prev_stop'] = i_stop
136+
sc.sticky[f'{prefix}_prev_load'] = i_load
132137

133138
return [o_cloud]

0 commit comments

Comments
 (0)