public void Initialize() { string dllPath = Path.Combine(Application.StartupPath, "peripheral", "aoto", "YPBoxLib", "YPGDriver.dll"); intPtr = Win32ApiInvoker.LoadLibrary(dllPath); IntPtr api = Win32ApiInvoker.GetProcAddress(intPtr, "OpenDevice"); openDevice = (OpenDevice)Marshal.GetDelegateForFunctionPointer(api, typeof(OpenDevice)); api = Win32ApiInvoker.GetProcAddress(intPtr, "GetSerialNumber"); getSerialNumber = (GetSerialNumber)Marshal.GetDelegateForFunctionPointer(api, typeof(GetSerialNumber)); api = Win32ApiInvoker.GetProcAddress(intPtr, "MotorRun"); motorRun = (MotorRun)Marshal.GetDelegateForFunctionPointer(api, typeof(MotorRun)); api = Win32ApiInvoker.GetProcAddress(intPtr, "MotorPoll"); motorPoll = (MotorPoll)Marshal.GetDelegateForFunctionPointer(api, typeof(MotorPoll)); api = Win32ApiInvoker.GetProcAddress(intPtr, "CloseDevice"); closeDevice = (CloseDevice)Marshal.GetDelegateForFunctionPointer(api, typeof(CloseDevice)); int ret = openDevice(ComNumber); }
/// <summary> /// Obtains an ODID in asynchronous mode. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnClickGetOdid(object sender, EventArgs e) { string MethodName = "GetOdid"; var task = OpenDevice.GetInstance(this).GetOdidAsync(); try { await task; if (task.IsCompleted) { OdidResult odid = task.Result; log.Info(MethodName, $"{odid.Id}"); } else { var exception = task.Exception; log.Error(MethodName, $"Error/Exception: {exception.Message}"); } } catch (Exception exception) { log.Error(MethodName, $"Error/Exception: {exception.Message}"); } }
internal static void Init() { #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif CloseDevice alcCloseDevice = null; OpenDevice alcOpenDevice = null; IsExtensionPresent alcIsExtensionPresent = null; GetIntegerv alcGetIntegerv = null; CreateContext alcCreateContext = null; MakeContextCurrent alcMakeContextCurrent = null; if (Environment.Is64BitProcess) { alcCloseDevice = Alc64.alcCloseDevice; alcOpenDevice = Alc64.alcOpenDevice; alcIsExtensionPresent = Alc64.alcIsExtensionPresent; alcGetIntegerv = Alc64.alcGetIntegerv; alcCreateContext = Alc64.alcCreateContext; alcMakeContextCurrent = Alc64.alcMakeContextCurrent; } else { alcCloseDevice = Alc32.alcCloseDevice; alcOpenDevice = Alc32.alcOpenDevice; alcIsExtensionPresent = Alc32.alcIsExtensionPresent; alcGetIntegerv = Alc32.alcGetIntegerv; alcCreateContext = Alc32.alcCreateContext; alcMakeContextCurrent = Alc32.alcMakeContextCurrent; } alcDeviceHandle = alcOpenDevice(null); if (alcDeviceHandle == IntPtr.Zero) { // TODO: Named devices throw new Exception("Could not find audio device."); } List <int> attributes = new List <int> { 4105, 0, }; if (alcIsExtensionPresent(alcDeviceHandle, "ALC_EXT_EFX")) { int[] alcInteger = new int[1]; alcGetIntegerv(alcDeviceHandle, 131065, 1, alcInteger); attributes.Add(131065); attributes.Add(alcInteger[0]); } attributes.Add(0); alcContextHandle = alcCreateContext(alcDeviceHandle, attributes.ToArray()); if (alcContextHandle == IntPtr.Zero) { alcCloseDevice(alcDeviceHandle); throw new Exception("Failed to create ALC context."); } alcMakeContextCurrent(alcContextHandle); #if DEBUG sw.Stop(); Console.WriteLine("Initializing ALC took {0} milliseconds.", sw.ElapsedMilliseconds); #endif }