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
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 | |
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:
| Name | Type | Description |
|---|---|---|
decorator |
Callable[Callable[..., Any], Callable[..., Any]]
|
|
Source code in plantimager/commons/RPC.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | |
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:
| Name | Type | Description |
|---|---|---|
accepted_name |
str
|
Name of this device as accepted by the registry. |
Source code in plantimager/commons/RPC.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | |
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
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 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 1097 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 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | |
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
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 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 | |
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 | |