cameraserver
plantimager.commons.examples.cameraserver Link
DummyCamera Link
DummyCamera(context, url)
Dummy Camera serving images from a shared dataset for testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
ZeroMQ context used to create sockets for RPC communication. |
required |
url
|
str
|
Endpoint address that the RPC server will bind to. |
required |
Source code in plantimager/commons/examples/cameraserver.py
72 73 74 75 76 77 78 79 | |
config Link
config(value)
Sets camera controls/parameters from Picamera2 Appendix C.
Parameters
Parameters
value : dict
Control names and values (e.g., {'Brightness': 0.5, 'Contrast': 1.2}).
See Also
See Also
Picamera2 Manual Appendix C:
https://pip-assets.raspberrypi.com/categories/652-raspberry-pi-camera-module-2/documents/RP-008156-DS-2-picamera2-manual.pdf?disposition=inline#%5B%7B%22num%22%3A10333%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C70.86614%2C781.0236%2C0%5D
Source code in plantimager/commons/examples/cameraserver.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
get_image Link
get_image(lores=False)
Return a JPEG‑encoded image (as a memoryview) and a metadata dict.
The lores flag is ignored for the dummy implementation.
Source code in plantimager/commons/examples/cameraserver.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
register_method_buffer
staticmethod
Link
register_method_buffer(timeout=10000)
Registers this method as remote callable procedure which will transmit its output as a buffer-like object as well as a buffer_info dictionary.
method may take any input which will be serialized via json and must output a 2-tuple:
(memoryview or bytes, dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int | None
|
Specifies how much time in ms a client is expected to wait for the method to finish. If None, waits indefinitely. |
10000
|
Returns:
| Name | Type | Description |
|---|---|---|
decorator |
Callable[Callable[..., tuple[memoryview | bytes, dict]], Callable[..., tuple[memoryview | bytes, dict]]]
|
|
Source code in plantimager/commons/RPC.py
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | |
register_method_json
staticmethod
Link
register_method_json(timeout=10000)
Registers this method as remote callable procedure which will transmit its output via json.
It is advised to only send basic types and containers as output (int, float, str, bool, list, tuple, dict, ...) Arguments are also serialized via json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int | None
|
Specifies how much time in ms a client is expected to wait for the method to finish. If None, waits indefinitely. |
10000
|
Returns:
| Type | Description |
|---|---|
Callable[Callable[..., Any], Callable[..., Any]]
|
|
Source code in plantimager/commons/RPC.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | |
register_to_registry Link
register_to_registry(type_, name, registry_url, overwrite=True)
Register this RPCServer to the registry at registry_address as a device of type type_ and name name.
Note: The name not be accepted as is and may be modified by the registry to avoid duplicate. This method returns the accepted name of this device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
str
|
Name of the device type. |
required |
name
|
str
|
Proposed name of the device. |
required |
registry_url
|
str
|
Url of the device registry. Must have the form "tcp:// |
required |
overwrite
|
Wether or not this device should take preference for the use of this name and overwrite other conflicting devices. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Name of this device as accepted by the registry. |
Source code in plantimager/commons/RPC.py
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | |
serve_forever Link
serve_forever()
Serve the RPC server indefinitely, handling incoming requests until a stop signal is received.
The method enters a loop that repeatedly notifies the watchdog, checks the server's
liveness, waits for a request, and dispatches the request based on its event field.
Supported events include peer discovery, inventory retrieval, signal handling
initialization, method invocation, property access, and server shutdown. Upon receiving
a STOP_SERVER event the loop terminates, sockets are closed, and a log entry is
written.
If registered to the registry and the check_alive fails, exits the loop
Returns:
| Type | Description |
|---|---|
None
|
The server runs until it is stopped; no value is returned. |
Notes
- The private attribute
_stopcontrols the loop termination. It is set toTrueonly when aSTOP_SERVERrequest is processed. _socketand_signal_socketare closed during cleanup; if either attribute isNonethe correspondingclosecall is skipped.notify_watchdogand_alive_checkare called on every iteration to maintain server health monitoring.- The method assumes that
_wait_for_requestreturns a mapping with aneventkey; a falsy return value causes the loop to continue without processing.
See Also
RPCEvents : Enum defining the possible request events. _handle_find_peer_address, _handle_get_inventory, _handle_init_signal_handling, _handle_method_call, _handle_property_get, _handle_property_set : Private helper methods that implement the handling logic for each event type.
Source code in plantimager/commons/RPC.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 | |
stop_server Link
stop_server()
Stop the server and unregister the device if it has been registered.
The method sets the internal stop flag, optionally calls
:func:unregister_device to remove the device from a remote registry,
clears the identifying attributes (name, uuid, registry_addr),
and resets the corresponding entries in _cleanup_state to None.
This prevents a second unregister attempt during cleanup.
Raises:
| Type | Description |
|---|---|
Exception
|
Propagates any exception raised by :func: |
Notes
- The device is only unregistered when all three attributes
self.name,self.registry_addrandself.uuidevaluate toTrue. If any of them is falsy, the function simply sets the stop flag and returns. self._cleanup_stateis updated after a successful unregister to avoid duplicate cleanup actions later in the object's lifecycle.
See Also
unregister_device : Function that removes a device from the registry.
Source code in plantimager/commons/RPC.py
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
image_provider Link
image_provider()
Generates an infinite sequence of images from a directory.
Yields:
| Type | Description |
|---|---|
ndarray
|
Image data loaded by |
Source code in plantimager/commons/examples/cameraserver.py
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 | |