debug.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import time
  2. import sys
  3. from nbus_hal.nbus_serial.serial_port import *
  4. from nbus_api.nbus_module_slave import NBusSlaveModule
  5. from nbus_api.nbus_bridge import NBusBridge
  6. from nbus_hal.nbus_serial.serial_config import *
  7. from nbus_api.nbus_sensor import NBusSensor
  8. from nbus_types.nbus_parameter_type import NBusParameterID
  9. import pandas as pd
  10. # example config
  11. config = {
  12. "port_name": "COM4",
  13. "baud": NBusBaudrate.SPEED_921600,
  14. "parity": NBusParity.NONE,
  15. "timeout": 1.0,
  16. "request_attempts": 1,
  17. "enable_log": True
  18. }
  19. if __name__ == "__main__":
  20. sys.exit
  21. port = NBusSerialPort(NBusSerialConfig(**config))
  22. #module1 = NBusSlaveModule(port, 9)
  23. #print(module1.cmd_get_sensor_type())
  24. #sys.exit()
  25. #sys.exit(0)
  26. bridge = NBusBridge(port, 0.05, 0.05)
  27. bridge.init_from_network()
  28. print(bridge.cmd_get_data())
  29. print(bridge.cmd_set_reset())
  30. print(bridge.cmd_get_slaves())
  31. print(bridge.cmd_get_format())
  32. bridge.start_data_streaming()
  33. time.sleep(5)
  34. print(bridge.fetch_chunk_from_stream())
  35. time.sleep(5)
  36. bridge.stop_data_streaming()
  37. print(bridge.fetch_chunk_from_stream())
  38. print(bridge.fetch_chunk_from_stream())
  39. df = bridge.fetch_all_from_stream()
  40. df.to_csv("data.csv", index=False)
  41. sys.exit()
  42. module1.scan()
  43. print(module1.cmd_get_echo(bytearray("ahoj", "ascii")))
  44. print(module1.cmd_get_format())
  45. print(module1.cmd_get_sensor_type())
  46. print(module1.cmd_get_data())
  47. #sys.exit(0)
  48. t0 = time.time()
  49. port.request_broadcast(NBusCommand.CMD_SET_START, bytearray([]))
  50. # time.sleep(1.0)
  51. for i in range(200):
  52. print(hex(port.get_port().read()[0]))
  53. port.request_broadcast(NBusCommand.CMD_SET_STOP, bytearray([]))
  54. # algoritmus hazel zvon
  55. while port.get_port().in_waiting:
  56. time.sleep(0.05)
  57. port.get_port().reset_input_buffer()
  58. print("flushed baby")
  59. # break
  60. print(module1.cmd_get_echo(bytearray("ahoj", "ascii")))