AppGlobal.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Fietsclient
  8. {
  9. public class AppGlobal
  10. {
  11. private static AppGlobal _instance;
  12. public int[] StatusItemsChecked;
  13. Thread workerThread;
  14. public static AppGlobal Instance
  15. {
  16. get { return _instance ?? (_instance = new AppGlobal()); }
  17. }
  18. private KettlerBikeComm _bikeComm;
  19. private AppGlobal()
  20. {
  21. _bikeComm = new KettlerBikeComm();
  22. KettlerBikeComm.IncomingDataEvent += HandleBikeData; //initialize event
  23. }
  24. public void startComPort()
  25. {
  26. startComPort("COM4");
  27. }
  28. public void startComPort(string portname)
  29. {
  30. _bikeComm.initComm(portname);
  31. }
  32. public void startAskingData()
  33. {
  34. workerThread = new Thread(() => workerThreadLoop());
  35. workerThread.Start();
  36. }
  37. private void workerThreadLoop()
  38. {
  39. while(true)
  40. {
  41. Thread.Sleep(1000);
  42. _bikeComm.sendData(KettlerBikeComm.STATUS);
  43. }
  44. }
  45. //event handler
  46. private void HandleBikeData(string[] data)
  47. {
  48. //doe iets ermee...
  49. }
  50. public void closeComPort()
  51. {
  52. if (workerThread != null)
  53. workerThread.Suspend();
  54. _bikeComm.closeComm();
  55. }
  56. }
  57. }