sensorB_simulator_v2
SensorB Modbus TCP Simulator
- Logs every client poll (READ) and simulator write (WRITE) at DEBUG.
- Also prints a concise [SEND] trace with tag name, dtype, eng value, and raw registers.
- Console/file logging is deterministic (handlers reset on each run).
- Endianness and update interval come from sim/config files.
USAGE python3 sensorB_simulator_v1.py [--debug]
CONFIG FILES (expected relative paths, override as needed) emsConfig/sensorB_modbus_config.json simulator_config/sensorB_register.json simulator_config/sensorB_register_values.json simulator_config/sensorB_sim_par.json
LoggingDataBlock
Bases: ModbusSequentialDataBlock
DataBlock that logs reads (polls) and writes when DEBUG is enabled.
Source code in EMS_template_codes/sensorB_simulator_v2.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
_coerce_meta(name_hint: str, meta: dict) -> Dict[str, Any]
Coerce a raw meta dict into the canonical shape used by the simulator.
Source code in EMS_template_codes/sensorB_simulator_v2.py
46 47 48 49 50 51 52 53 54 55 56 | |
flatten_reg_map(reg_map_any: Any) -> Dict[str, Dict[str, Any]]
Accepts multiple JSON shapes and returns {name: meta}.
Supported
- Dict[name]->meta
- Dict[category]->Dict[name]->meta
- List[meta with "name"]
Source code in EMS_template_codes/sensorB_simulator_v2.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get_values() -> Dict[str, Any]
Optional static overrides map: {name: value}
Source code in EMS_template_codes/sensorB_simulator_v2.py
257 258 259 260 | |
jitter(val, span, scale=0.3)
A gentle jitter around val within ± span*scale.
Source code in EMS_template_codes/sensorB_simulator_v2.py
221 222 223 | |
make_eng_value(meta: Dict[str, Any], static_vals: Dict[str, Any]) -> Any
Produce an engineering value either from static override or from range.
Source code in EMS_template_codes/sensorB_simulator_v2.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
pack_float32_to_words(value: float, endian: str) -> Tuple[int, int]
Pack float into two 16-bit registers.
Source code in EMS_template_codes/sensorB_simulator_v2.py
155 156 157 158 159 160 | |
🔁 Simulation Flow
flowchart TD
A[Start main()] --> B[...]
⚙️ Flow with Conditional Checks
flowchart TD
A[Start main()] --> B{Check something?}
B -- Yes --> C[Do X]
B -- No --> D[Exit]