PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/client_v4_2_comm/Test/PortingKitTest/Archive/Commmon/SpotNetFramework/GPIBController/GPIBControllerService.cs

#
C# | 125 lines | 114 code | 9 blank | 2 comment | 11 complexity | 4c4aa765be7aca37025e303027ed1497 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, MIT, MPL-2.0-no-copyleft-exception
  1. #region Using directives
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.ServiceProcess;
  8. using System.Text;
  9. using System.Collections;
  10. using _NI = NationalInstruments.NI4882;
  11. using Microsoft.SPOT.Test.Client.Common.SpotNetFramework.Modulator;
  12. #endregion
  13. namespace Microsoft.SPOT.Test.Client.Common.SpotNetFramework.GPIBController
  14. {
  15. public partial class ControllerService : ServiceBase
  16. {
  17. public ControllerService()
  18. {
  19. InitializeComponent();
  20. }
  21. private ArrayList m_DeviceArray = new ArrayList();
  22. private Hashtable m_AddressHash = new Hashtable();
  23. _NI.Board m_board = new _NI.Board(0);
  24. public void InitializeBus()
  25. {
  26. _NI.AddressCollection addrs = m_board.FindListeners();
  27. foreach (_NI.Address addr in addrs)
  28. {
  29. _NI.Device dev = new _NI.Device(0, addr);
  30. dev.Write("*IND?");
  31. string str = dev.ReadString();
  32. if (str.Length > 0)
  33. {
  34. if (-1 != str.IndexOf("8648A"))
  35. {
  36. m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
  37. }
  38. else
  39. {
  40. Console.WriteLine("Warning: GPIB device at address " + addr.ToString() + " is unknown");
  41. }
  42. }
  43. }
  44. }
  45. public void InitializeBus(Hashtable GPIBAddressMap)
  46. {
  47. m_AddressHash = GPIBAddressMap;
  48. _NI.AddressCollection addrs = m_board.FindListeners();
  49. foreach (_NI.Address addr in addrs)
  50. {
  51. if (m_AddressHash.ContainsKey(addr.PrimaryAddress))
  52. {
  53. switch ((ModulatorTypes)m_AddressHash[addr.PrimaryAddress])
  54. {
  55. case ModulatorTypes.HP8648A:
  56. m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
  57. break;
  58. case ModulatorTypes.Leader3216:
  59. m_DeviceArray.Add(new Leader3216Modulator(addr.PrimaryAddress));
  60. break;
  61. case ModulatorTypes.Leader3236:
  62. m_DeviceArray.Add(new Leader3236Modulator(addr.PrimaryAddress));
  63. break;
  64. }
  65. }
  66. else
  67. {
  68. _NI.Device dev = new _NI.Device(0, addr);
  69. dev.Write("*IND?");
  70. string str = dev.ReadString();
  71. if (str.Length > 0)
  72. {
  73. if (-1 != str.IndexOf("8648A"))
  74. {
  75. m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
  76. }
  77. }
  78. else
  79. {
  80. Console.WriteLine("Warning: GPIB device at address " + addr.ToString() + " is unknown");
  81. }
  82. }
  83. }
  84. }
  85. int DeviceCount()
  86. {
  87. return m_DeviceArray.Count;
  88. }
  89. public ModulatorBase GetDevice(int index)
  90. {
  91. ModulatorBase mb = m_DeviceArray[index] as ModulatorBase;
  92. mb.SetInUse();
  93. return mb;
  94. }
  95. public ModulatorBase GetDeviceType(ModulatorTypes mt)
  96. {
  97. foreach (ModulatorBase mb in m_DeviceArray)
  98. {
  99. if (!mb.InUse && mb.ModulatorType == mt)
  100. {
  101. mb.SetInUse();
  102. return mb;
  103. }
  104. }
  105. return null;
  106. }
  107. protected override void OnStart(string[] args)
  108. {
  109. // TODO: Add code here to start your service.
  110. }
  111. protected override void OnStop()
  112. {
  113. // TODO: Add code here to perform any tear-down necessary to stop your service.
  114. }
  115. }
  116. }