123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace ANT_Managed_Library
- {
-
-
-
- public static class ANT_Common
- {
-
-
-
-
- static public bool autoResetIsEnabled = true;
- #region constants
- #if EXT_FUNCTIONALITY
- #warning "The Extended build is for internal use only, and even then, only for specific projects, do not use without discussing with the ANT team"
- internal const String ANT_UNMANAGED_WRAPPER = "ANT_WrappedLib_Ext.dll";
- #else
- internal const String ANT_UNMANAGED_WRAPPER = "ANT_WrappedLib.dll";
- #endif
- internal const String ANT_SI_LIBRARY = "DSI_SiUSBXp_3_1.DLL";
- internal const String ANT_SI_LIBRARY2 = "DSI_CP210xManufacturing_3_1.dll";
- #endregion
- #region DLL imports
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
- private static extern UInt32 ANT_GetNumDevices();
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
- private static extern int ANT_EnableDebugLogging();
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
- private static extern void ANT_DisableDebugLogging();
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
- private static extern int ANT_SetDebugLogDirectory(string pcDirectory);
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
- private static extern int ANT_DebugThreadInit(string pucName);
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
- private static extern int ANT_DebugThreadWrite(string pcMessage);
- [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int ANT_DebugResetTime();
- #endregion
-
-
-
- public static UInt32 getNumDetectedUSBDevices()
- {
- return ANT_GetNumDevices();
- }
-
-
-
-
- public static void checkUnmanagedLibrary()
- {
-
- if (!System.IO.File.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ANT_UNMANAGED_WRAPPER)))
- throw new ANT_Exception(ANT_UNMANAGED_WRAPPER + " not found in working directory");
-
- }
-
-
-
-
- public static void checkUSBLibraries()
- {
- String missingLibs = null;
-
- if (!System.IO.File.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ANT_SI_LIBRARY)))
- {
- missingLibs = ANT_SI_LIBRARY;
- }
- if (!System.IO.File.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ANT_SI_LIBRARY2)))
- {
- if (missingLibs != null)
- {
- missingLibs += ", " + ANT_SI_LIBRARY2;
- }
- else
- {
- missingLibs = ANT_SI_LIBRARY2;
- }
- }
- if (missingLibs != null)
- {
- throw new ANT_Exception(missingLibs + " not found in working directory");
- }
- }
-
-
-
-
-
-
-
- public static bool enableDebugLogs()
- {
- return ANT_EnableDebugLogging() == 1;
- }
-
-
-
-
-
-
-
-
- public static void enableDebugLogs(string debugPath)
- {
- enableDebugLogs();
- setDebugLogDirectory(debugPath);
- }
-
-
-
- public static void disableDebugLogs()
- {
- ANT_DisableDebugLogging();
- }
-
-
-
-
-
-
-
-
-
-
-
- public static bool setDebugLogDirectory(string directoryPath)
- {
- if (!System.IO.Directory.Exists(directoryPath))
- throw new ANT_Exception("Path does not exist");
- return ANT_SetDebugLogDirectory(directoryPath) == 1;
- }
-
-
-
-
-
-
-
-
- internal static bool initDebugLogThread(string name)
- {
- return ANT_DebugThreadInit(name) == 1;
- }
-
-
-
-
-
- internal static bool writeToDebugLog(string message)
- {
- return ANT_DebugThreadWrite(message) == 1;
- }
- }
- }
|