예제 #1
0
 public unsafe static void StartHW(int freq)
 {
     if (!(ExtIO._dllHandle == IntPtr.Zero) && ExtIO._startHW != null)
     {
         ExtIO.logInfo("StartHW(), freq=" + freq.ToString());
         if (!ExtIO._isHWInit)
         {
             ExtIO.OpenHW(true);
         }
         if (ExtIO._iqBuffer != null)
         {
             ExtIO._iqBuffer.Dispose();
         }
         ExtIO._iqBuffer = null;
         ExtIO._iqPtr    = null;
         int num = ExtIO._startHW(freq);
         ExtIO.logResult("StartHW: ");
         if (num <= 0)
         {
             ExtIO.logInfo("StartHW() returned " + num);
             throw new Exception("ExtIO StartHW() returned " + num);
         }
         ExtIO._isHWStarted = true;
         ExtIO._sampleCount = num;
         ExtIO._iqBuffer    = UnsafeBuffer.Create(ExtIO._sampleCount, sizeof(Complex));
         ExtIO._iqPtr       = (Complex *)(void *)ExtIO._iqBuffer;
         ExtIO.logInfo("StartHW succeeded, samplecount=" + ExtIO._sampleCount.ToString() + ", iqBuffer created.");
     }
 }
예제 #2
0
 public static bool OpenHW(bool setCallback = true)
 {
     if (!ExtIO._isHWInit)
     {
         ExtIO.HWInit(setCallback);
     }
     if (!(ExtIO._dllHandle == IntPtr.Zero) && ExtIO._isHWInit && !ExtIO._isHWStarted)
     {
         ExtIO.logInfo("OpenHW()");
         bool flag = false;
         try
         {
             flag = ExtIO._openHW();
         }
         catch (Exception ex)
         {
             ExtIO.logInfo("OpenHW: " + ex.Message);
         }
         if (flag)
         {
             ExtIO.ShowGUI();
         }
         else
         {
             ExtIO.logResult("OpenHW: ");
         }
         return(flag);
     }
     return(false);
 }
예제 #3
0
 public static void CloseLibrary()
 {
     if (ExtIO._isHWStarted)
     {
         ExtIO.StopHW();
     }
     if (ExtIO._isHWInit)
     {
         ExtIO.CloseHW();
     }
     if (!(ExtIO._dllHandle == IntPtr.Zero))
     {
         ExtIO.logInfo("CloseLibrary()");
         try
         {
             ExtIO.FreeLibrary(ExtIO._dllHandle);
         }
         catch (Exception ex)
         {
             ExtIO.logInfo("FreeLibrary: " + ex.Message);
         }
         ExtIO.logResult("FreeLibrary: ");
         ExtIO._dllHandle = IntPtr.Zero;
     }
 }
예제 #4
0
 public static void HWInit(bool setCallback)
 {
     if (!(ExtIO._dllHandle == IntPtr.Zero) && !ExtIO._isHWInit && !ExtIO._isHWStarted)
     {
         ExtIO.logInfo("HWInit()");
         StringBuilder stringBuilder  = new StringBuilder(256);
         StringBuilder stringBuilder2 = new StringBuilder(256);
         int           hwType         = 0;
         try
         {
             ExtIO._isHWInit = ExtIO._initHW(stringBuilder, stringBuilder2, ref hwType);
         }
         catch (Exception ex)
         {
             ExtIO.logInfo("InitHW: " + ex.Message);
         }
         ExtIO.logResult("InitHW: ");
         ExtIO._name   = stringBuilder.ToString();
         ExtIO._model  = stringBuilder2.ToString();
         ExtIO._hwType = (HWTypes)hwType;
         if (!ExtIO._isHWInit)
         {
             ExtIO.logInfo("InitHW() returned " + ExtIO._isHWInit + ", ");
             ExtIO._isHWInit = true;
             ExtIO.CloseHW();
             throw new ApplicationException("InitHW() returned " + ExtIO._isHWInit);
         }
         ExtIO.logInfo("InitHW: " + ExtIO._name + ", " + ExtIO._model + ", type=" + hwType.ToString());
         if (setCallback)
         {
             ExtIO.logInfo("SetCallback: ");
             try
             {
                 ExtIO._setCallback(ExtIO._callbackInst);
             }
             catch (Exception ex2)
             {
                 ExtIO.logInfo("SetCallback: " + ex2.Message);
             }
         }
     }
 }
예제 #5
0
        public static void UseLibrary(string fileName)
        {
            if (ExtIO._dllHandle != IntPtr.Zero)
            {
                ExtIO.CloseLibrary();
            }
            ExtIO.logInfo("UseLibrary(), dll=" + fileName);
            try
            {
                ExtIO._dllHandle = ExtIO.LoadLibrary(fileName);
            }
            catch (Exception ex)
            {
                ExtIO.logInfo("LoadLibrary: " + ex.Message);
            }
            ExtIO.logResult("LoadLibrary:");
            if (ExtIO._dllHandle == IntPtr.Zero)
            {
                ExtIO.logInfo("LoadLibrary(), Unable to load DLL file: " + fileName);
                throw new Exception("Unable to load ExtIO library " + fileName);
            }
            ExtIO._dllName     = fileName;
            ExtIO._initHW      = null;
            ExtIO._openHW      = null;
            ExtIO._startHW     = null;
            ExtIO._stopHW      = null;
            ExtIO._closeHW     = null;
            ExtIO._setHWLO     = null;
            ExtIO._tuneChanged = null;
            ExtIO._getHWLO     = null;
            ExtIO._getHWSR     = null;
            ExtIO._getStatus   = null;
            ExtIO._showGUI     = null;
            ExtIO._hideGUI     = null;
            ExtIO._setCallback = null;
            IntPtr procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "InitHW");

            if (procAddress != IntPtr.Zero)
            {
                ExtIO._initHW = (dInitHW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dInitHW));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "OpenHW");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._openHW = (dOpenHW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dOpenHW));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "StartHW");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._startHW = (dStartHW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dStartHW));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "StopHW");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._stopHW = (dStopHW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dStopHW));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "CloseHW");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._closeHW = (dCloseHW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dCloseHW));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "SetCallback");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._setCallback = (dSetCallback)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dSetCallback));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "SetHWLO");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._setHWLO = (dSetHWLO)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dSetHWLO));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "TuneChange");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._tuneChanged = (dTuneChanged)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dTuneChanged));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "GetHWLO");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._getHWLO = (dGetHWLO)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dGetHWLO));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "GetHWSR");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._getHWSR = (dGetHWSR)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dGetHWSR));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "GetTune");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._getTune = (dGetTune)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dGetTune));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "GetStatus");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._getStatus = (dGetStatus)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dGetStatus));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "ShowGUI");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._showGUI = (dShowGUI)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dShowGUI));
            }
            procAddress = ExtIO.GetProcAddress(ExtIO._dllHandle, "HideGUI");
            if (procAddress != IntPtr.Zero)
            {
                ExtIO._hideGUI = (dHideGUI)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(dHideGUI));
            }
            if (ExtIO._initHW != null && ExtIO._openHW != null && ExtIO._startHW != null && ExtIO._setHWLO != null && ExtIO._getStatus != null && ExtIO._setCallback != null && ExtIO._stopHW != null && ExtIO._closeHW != null)
            {
                return;
            }
            ExtIO.FreeLibrary(ExtIO._dllHandle);
            ExtIO._dllHandle = IntPtr.Zero;
            ExtIO.logInfo("LoadLibrary(), ExtIO DLL is not valid, not all entries found.");
            throw new ApplicationException("ExtIO DLL is not valid, not all entries found.");
        }