| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- from nbus_api.nbus_module_slave import NBusSlaveModule
- from nbus_hal.nbus_serial.serial_port import *
- from nbus_hal.nbus_serial.serial_config import *
- # example config
- config = {
- "port_name": "COM14",
- "baud": NBusBaudrate.SPEED_921600,
- "parity": NBusParity.NONE,
- "timeout": 1.0,
- "flush_delay": 3.0,
- "request_attempts": 1,
- "enable_log": False
- }
- BRIDGE_ACQUIRE_WAIT = 0.5
- BRIDGE_STREAM_INTERVAL = 5.0
- if __name__ == "__main__":
- # create port
- port = NBusSerialPort(NBusSerialConfig(**config))
- # create module
- module = NBusSlaveModule(port, 5, BRIDGE_ACQUIRE_WAIT)
- # run commands
- try:
- # initialize module
- module.init()
- # perform stream commands
- print(f"START STREAM FOR {BRIDGE_STREAM_INTERVAL} SECONDS")
- module.start_streaming()
- time.sleep(BRIDGE_STREAM_INTERVAL)
- module.stop_streaming()
- print(f"STOP STREAM AFTER {BRIDGE_STREAM_INTERVAL} SECONDS")
- df = module.fetch_full_stream()
- print("STREAM DATA ", df)
- df.to_csv("data.csv", index=False)
- except Exception as e:
- print("EXCEPTION ", str(e))
- finally:
- port.flush()
- port.close()
|