internal static void InitializeComForFinalizerThread() { InitializeCom(); // Prevent re-initialization of COM model on finalizer thread t_comState |= ComState.Locked; s_comInitializedOnFinalizerThread = true; }
private static void InitializeComForThreadPoolThread() { // Initialized COM - take advantage of implicit MTA initialized by the finalizer thread SpinWait sw = new SpinWait(); while (!s_comInitializedOnFinalizerThread) { RuntimeImports.RhInitializeFinalizerThread(); sw.SpinOnce(0); } // Prevent re-initialization of COM model on threadpool threads t_comState |= ComState.Locked; }
private static void UninitializeCom() { if ((t_comState & ComState.InitializedByUs) == 0) { return; } #if ENABLE_WINRT Interop.WinRT.RoUninitialize(); #else Interop.Ole32.CoUninitialize(); #endif t_comState &= ~ComState.InitializedByUs; }
public override CmdLineResult handleCommand(CmdLineStruct pCmd) { // Gestion héritée des commandes CmdLineResult lCmdLineResult = base.handleCommand(pCmd); if (lCmdLineResult.CmdAccepted) { return(lCmdLineResult); } // Accès aux états de base if (pCmd.Line == "q") { return(new CmdLineResult(true, "", "Exiting", true, true)); } // Changement d'états StateBase lNewSate = null; if ((pCmd.Line == "thrust") || (pCmd.Line == "t")) { lNewSate = new ThrustChangingState(); } else if (pCmd.Line == "pid") { lNewSate = new PIDChangingState(); } else if (pCmd.Line == "com") { lNewSate = new ComState(); } else if (pCmd.Line == "open") { lNewSate = new InFlightState(); } if (lNewSate != null) { setSubState(lNewSate); return(new CmdLineResult(true, "", "", true, false)); } // Fin return(new CmdLineResult(false, "Unknown command", "", false, false)); }
private static void InitializeCom(ApartmentState state = ApartmentState.MTA) { if ((t_comState & ComState.InitializedByUs) != 0) { return; } #if ENABLE_WINRT int hr = Interop.WinRT.RoInitialize( (state == ApartmentState.STA) ? Interop.WinRT.RO_INIT_SINGLETHREADED : Interop.WinRT.RO_INIT_MULTITHREADED); #else int hr = Interop.Ole32.CoInitializeEx(IntPtr.Zero, (state == ApartmentState.STA) ? Interop.Ole32.COINIT_APARTMENTTHREADED : Interop.Ole32.COINIT_MULTITHREADED); #endif if (hr < 0) { // RPC_E_CHANGED_MODE indicates this thread has been already initialized with a different // concurrency model. We stay away and let whoever else initialized the COM to be in control. if (hr == HResults.RPC_E_CHANGED_MODE) { return; } // CoInitializeEx returns E_NOTIMPL on Windows Nano Server for STA if (hr == HResults.E_NOTIMPL) { throw new PlatformNotSupportedException(); } throw new OutOfMemoryException(); } t_comState |= ComState.InitializedByUs; // If the thread has already been CoInitialized to the proper mode, then // we don't want to leave an outstanding CoInit so we CoUninit. if (hr > 0) { UninitializeCom(); } }
private static void InitializeExistingThreadPoolThread() { #if PROJECTN InitializeCom(); #else // Take advantage of implicit MTA initialized by the finalizer thread SpinWait sw = new SpinWait(); while (!s_comInitializedOnFinalizerThread) { RuntimeImports.RhInitializeFinalizerThread(); sw.SpinOnce(0); } #endif // Prevent re-initialization of COM model on threadpool threads t_comState |= ComState.Locked; ThreadPool.InitializeForThreadPoolThread(); }
public void SetState(ComState state) { switch (state) { case ComState.OFF: this.Visibility = Visibility.Hidden; break; case ComState.TARGET: this.Visibility = Visibility.Visible; Canvas.SetTop(amRect, GAP); break; case ComState.NON_TARGET: this.Visibility = Visibility.Visible; Canvas.SetTop(amRect, SIZE - amRect.Height - GAP); break; } }
public Coms() { string last = Hawesome.Tools.GetConfig("Com"); List <string> ports = SerialPort.GetPortNames().ToList(); if (ports.Contains(last)) { ports.Remove(last); ports.Insert(0, last); } byte[] snd = new byte[] { 0x01, 0x43, 0x00, 0x00, 0x00, 0x01 }; Task.Factory.StartNew(new Action(() => { for (int i = 0; i < ports.Count; i++) { Com com = new Com(ComType.SP, ports[i]); try { byte[] rcv = com.Execute(snd); if (rcv != null && rcv.Length > 0) { loadData(com); Hawesome.Tools.SetConfig("Com", ports[i]); break; } } catch { } finally { com.Dispose(); } ComState state = (i == ports.Count - 1) ? ComState.FAILED : ComState.LOADING; Update(this, new ComsEventArgs((i + 1) * 100 / ports.Count, 0, state)); } })); }
public ComsEventArgs(int comValue, int importValue, ComState state = ComState.LOADING) { ComValue = comValue; ImportValue = importValue; State = state; }
public ComStateChangedEvent(int cpuIndex, ComState comState) { CpuIndex = cpuIndex; ComState = comState; }