PatientModel.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace FietsClientV2
  8. {
  9. class PatientModel
  10. {
  11. private static PatientModel _patientModel;
  12. public static PatientModel patientModel { get { return _patientModel ?? (_patientModel = new PatientModel()); } }
  13. private DataHandler dataHandler;
  14. private Thread workerThread;
  15. private PatientModel()
  16. {
  17. dataHandler = new DataHandler();
  18. DataHandler.IncomingDataEvent += HandleBikeData; //initialize event
  19. }
  20. public void startComPort(string portname)
  21. {
  22. dataHandler.initComm(portname);
  23. }
  24. public void startAskingData()
  25. {
  26. workerThread = new Thread(() => workerThreadLoop());
  27. workerThread.Start();
  28. }
  29. private void workerThreadLoop()
  30. {
  31. while (true)
  32. {
  33. Thread.Sleep(1000);
  34. dataHandler.sendData(DataHandler.STATUS);
  35. }
  36. }
  37. //event handler
  38. private void HandleBikeData(string[] data)
  39. {
  40. //doe iets ermee...
  41. }
  42. public void closeComPort()
  43. {
  44. if (workerThread != null)
  45. workerThread.Interrupt();
  46. dataHandler.closeComm();
  47. }
  48. }
  49. }