/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
- #region Using directives
-
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Text;
- using System.Collections;
- using _NI = NationalInstruments.NI4882;
- using Microsoft.SPOT.Test.Client.Common.SpotNetFramework.Modulator;
-
- #endregion
-
- namespace Microsoft.SPOT.Test.Client.Common.SpotNetFramework.GPIBController
- {
- public partial class ControllerService : ServiceBase
- {
- public ControllerService()
- {
- InitializeComponent();
- }
-
- private ArrayList m_DeviceArray = new ArrayList();
- private Hashtable m_AddressHash = new Hashtable();
- _NI.Board m_board = new _NI.Board(0);
-
- public void InitializeBus()
- {
- _NI.AddressCollection addrs = m_board.FindListeners();
- foreach (_NI.Address addr in addrs)
- {
- _NI.Device dev = new _NI.Device(0, addr);
- dev.Write("*IND?");
- string str = dev.ReadString();
- if (str.Length > 0)
- {
- if (-1 != str.IndexOf("8648A"))
- {
- m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
- }
- else
- {
- Console.WriteLine("Warning: GPIB device at address " + addr.ToString() + " is unknown");
- }
- }
- }
- }
-
- public void InitializeBus(Hashtable GPIBAddressMap)
- {
- m_AddressHash = GPIBAddressMap;
- _NI.AddressCollection addrs = m_board.FindListeners();
- foreach (_NI.Address addr in addrs)
- {
- if (m_AddressHash.ContainsKey(addr.PrimaryAddress))
- {
- switch ((ModulatorTypes)m_AddressHash[addr.PrimaryAddress])
- {
- case ModulatorTypes.HP8648A:
- m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
- break;
- case ModulatorTypes.Leader3216:
- m_DeviceArray.Add(new Leader3216Modulator(addr.PrimaryAddress));
- break;
- case ModulatorTypes.Leader3236:
- m_DeviceArray.Add(new Leader3236Modulator(addr.PrimaryAddress));
- break;
- }
- }
- else
- {
- _NI.Device dev = new _NI.Device(0, addr);
- dev.Write("*IND?");
- string str = dev.ReadString();
- if (str.Length > 0)
- {
- if (-1 != str.IndexOf("8648A"))
- {
- m_DeviceArray.Add(new HP8648AModulator(addr.PrimaryAddress));
- }
- }
- else
- {
- Console.WriteLine("Warning: GPIB device at address " + addr.ToString() + " is unknown");
- }
- }
- }
- }
- int DeviceCount()
- {
- return m_DeviceArray.Count;
- }
-
- public ModulatorBase GetDevice(int index)
- {
- ModulatorBase mb = m_DeviceArray[index] as ModulatorBase;
- mb.SetInUse();
- return mb;
- }
- public ModulatorBase GetDeviceType(ModulatorTypes mt)
- {
- foreach (ModulatorBase mb in m_DeviceArray)
- {
- if (!mb.InUse && mb.ModulatorType == mt)
- {
- mb.SetInUse();
- return mb;
- }
- }
- return null;
- }
-
- protected override void OnStart(string[] args)
- {
- // TODO: Add code here to start your service.
- }
-
- protected override void OnStop()
- {
- // TODO: Add code here to perform any tear-down necessary to stop your service.
- }
- }
- }