program_core.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from typing import Optional
  2. from program_public_tools import ProgramPublicTools
  3. from instrument_controller import InstrumentController
  4. from serial_device_controller import SerialDeviceController
  5. from powerline_adapter import PowerlineAdapter
  6. from local_file_service import LocalFileService
  7. class ProgramCore(object):
  8. def __init__(self, pubtools: Optional[ProgramPublicTools]):
  9. if pubtools is None:
  10. pubtools = ProgramPublicTools()
  11. self.pubtools: ProgramPublicTools = pubtools
  12. self.serial_controller: SerialDeviceController = SerialDeviceController(self.pubtools)
  13. self.powerline_adapter: PowerlineAdapter = PowerlineAdapter(self.pubtools)
  14. self.local_file_service: LocalFileService = LocalFileService()
  15. self.start_core()
  16. self.instrument_controller: InstrumentController = InstrumentController(self.pubtools)
  17. self.instrument_controller.auto_connect()
  18. if self.instrument_controller.services.digital_oscilloscope is not None:
  19. self.instrument_controller.services.digital_oscilloscope.keep_listening()
  20. if self.instrument_controller.services.digital_multimeter is not None:
  21. self.instrument_controller.services.digital_multimeter.keep_listening()
  22. # def reboot_serial_controller(self):
  23. # self.serial_controller.release_inter_source()
  24. # del self.serial_controller
  25. # self.serial_controller: SerialDeviceController = SerialDeviceController(self.pubtools)
  26. # self.serial_controller.auto_connect()
  27. def start_core(self):
  28. self.local_file_service.start()
  29. self.auto_connect()
  30. def auto_connect(self):
  31. self.serial_controller.auto_connect()
  32. self.powerline_adapter.init()
  33. self.local_file_service.start()