AppGlobal.cs.orig 1.6 KB

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