コード例 #1
0
        public static void SetUpBeforeClass()
        {
            compressor = new Compressor();

            fakePressureSwitch = new DigitalOutput(11);

            fakeCompressor = new AnalogInput(1);

            fakeSolenoid1 = new DigitalInput(12);
            fakeSolenoid2 = new DigitalInput(13);

            if (RobotBase.IsSimulation)
            {
                /*
                 * pressureSwitchCallback = (s, o) =>
                 * {
                 *  var comp = SimData.GetPCM(0).Compressor;
                 *  comp.PressureSwitch = o;
                 *  comp.On = o;
                 *  double voltage = o ? CompressorOffVoltage : CompressorOnVoltage;
                 *  SimData.AnalogIn[1].Voltage = voltage;
                 * };
                 */
                pressureSwitchCallback = (string name, HAL_Value value) =>
                {
                    SimData.PCM[0].SetPressureSwitch(value.GetBoolean());
                    SimData.PCM[0].SetCompressorOn(value.GetBoolean());
                    double voltage = value.GetBoolean() ? CompressorOffVoltage : CompressorOnVoltage;
                    SimData.AnalogIn[1].SetVoltage(voltage);
                };
                callbackId = SimData.DIO[11].RegisterValueCallback(pressureSwitchCallback, false);
            }
        }
コード例 #2
0
        public void TestNotifyDictRemoveCallback()
        {
            int            count        = 0;
            string         key          = null;
            dynamic        value        = -5;
            NotifyCallback mockDelegate = (string name, HAL_Value halValue) =>
            {
                count++;
                key   = name;
                value = halValue.GetBoolean();
            };

            SimData.ResetHALData(false);

            int uid = SimData.AnalogIn[0].RegisterVoltageCallback(mockDelegate, false);

            SimData.AnalogIn[0].SetVoltage(1.25);

            SimData.AnalogIn[0].CancelVoltageCallback(uid);

            SimData.AnalogIn[0].SetVoltage(13.84);

            Assert.AreEqual(1, count);
            Assert.AreEqual("Voltage", key);
            Assert.AreEqual(1.25, value);
        }
コード例 #3
0
ファイル: CLfunc.cs プロジェクト: ReijiPochi/ImageBuilder2016
 public static extern IntPtr clCreateContext(
     IntPtr[] properties,
     int deviceCount,
     IntPtr[] devices,
     NotifyCallback pfnNotify,
     IntPtr userData,
     out int errorCode);
コード例 #4
0
        public static void AttachAio(int input, int output)
        {
            NotifyCallback callback = (key, value) =>
            {
                SimData.AnalogIn[input].SetVoltage(value.GetDouble());
            };

            SimData.AnalogOut[output].RegisterVoltageCallback(callback);
        }
コード例 #5
0
 public VictorMotorFixture() : base()
 {
     currentCallback = (s, o) =>
     {
         double current = freeCurrent * o.GetDouble();
         SimData.PDP[0].SetCurrent(TestBench.VictorPdpChannel, current);
     };
     callbackId = SimData.PWM[TestBench.VictorChannel].RegisterSpeedCallback(currentCallback);
 }
コード例 #6
0
 public void Notify(int percent, string Message)
 {
     if (Operations_PB.InvokeRequired)
     {
         NotifyCallback d = new NotifyCallback(Notify);
         this.Invoke(d, new object[] { percent, Message });
     }
     else
     {
         Operations_PB.Value = percent;
         Operations_L.Text   = Message;
     }
 }
コード例 #7
0
        public void TestDoubleSolenoid()
        {
            using (DoubleSolenoid solenoid = new DoubleSolenoid(0, 1))
            {
                NotifyCallback solenoid1Callback = null;
                NotifyCallback solenoid2Callback = null;

                int callback1Id = -1;
                int callback2Id = -1;

                if (RobotBase.IsSimulation)
                {
                    solenoid1Callback = (s, o) =>
                    {
                        SimData.DIO[12].SetValue(!o.GetBoolean());
                    };
                    callback1Id = SimData.PCM[0].RegisterSolenoidOutputCallback(0, solenoid1Callback);

                    solenoid2Callback = (s, o) =>
                    {
                        SimData.DIO[13].SetValue(!o.GetBoolean());
                    };
                    callback2Id = SimData.PCM[0].RegisterSolenoidOutputCallback(1, solenoid2Callback);
                }

                solenoid.Set(DoubleSolenoid.Value.Off);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Off));

                solenoid.Set(DoubleSolenoid.Value.Forward);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(!fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Forward));

                solenoid.Set(DoubleSolenoid.Value.Reverse);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(!fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Reverse));

                if (RobotBase.IsSimulation)
                {
                    SimData.PCM[0].CancelSolenoidOutputCallback(0, callback1Id);
                    SimData.PCM[0].CancelSolenoidOutputCallback(1, callback2Id);
                }
            }
        }
コード例 #8
0
ファイル: NotifyEventArgs.cs プロジェクト: illden/Scut
 /// <summary>
 ///
 /// </summary>
 internal void OnCallback()
 {
     try
     {
         NotifyCallback handler = Callback;
         if (handler != null)
         {
             handler.BeginInvoke(this, EndCallback, null);
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Notify callback error:{0}", ex);
     }
 }
コード例 #9
0
 public void Load(FlxBasic objectOrGroup1, FlxBasic objectOrGroup2 = null, NotifyCallback notifyCallback = null, ProcessingCallback processingCallback = null)
 {
     Add(objectOrGroup1, A_LIST);
     if (objectOrGroup2 != null)
     {
         Add(objectOrGroup2, B_LIST);
         _useBothLists = true;
     }
     else
     {
         _useBothLists = false;
     }
     _notifyCallback     = notifyCallback;
     _processingCallback = processingCallback;
 }
コード例 #10
0
        public static void AttachRelay(int relay, int a, int b)
        {
            NotifyCallback fwdCallback = (key, value) =>
            {
                SimData.DIO[a].SetValue(value.GetBoolean());
            };

            NotifyCallback revCallback = (key, value) =>
            {
                SimData.DIO[b].SetValue(value.GetBoolean());
            };

            SimData.Relay[relay].RegisterForwardCallback(fwdCallback);
            SimData.Relay[relay].RegisterReverseCallback(revCallback);
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        internal void OnCallback()
        {
            //try
            //{
            NotifyCallback handler = Callback;

            if (handler != null)
            {
                handler(this);
            }
            //}
            //catch (Exception ex)
            //{
            //    TraceLog.WriteError("Notify callback error:{0}", ex);
            //}
        }
コード例 #12
0
        public int RegisterSolenoidOutputCallback(int channel, NotifyCallback callback, bool initialNotify = false)
        {
            HAL_NotifyCallback modCallback = (IntPtr namePtr, IntPtr param, ref HAL_Value value) =>
            {
                string varName = ReadUTF8String(namePtr);
                callback?.Invoke(varName, value);
            };
            int uid = HALSIM_RegisterPCMSolenoidOutputCallback(Index, channel, modCallback, IntPtr.Zero, initialNotify);

            if (!m_solenoidOutputCallbacks[channel].TryAdd(uid, modCallback))
            {
                HALSIM_CancelPCMSolenoidOutputCallback(Index, channel, uid);
                throw new ArgumentException("Key cannot be added multiple times to the dictionary");
            }
            return(uid);
        }
コード例 #13
0
        public int RegisterInitializedCallback(NotifyCallback callback, bool initialNotify = false)
        {
            HAL_NotifyCallback modCallback = (IntPtr namePtr, IntPtr param, ref HAL_Value value) =>
            {
                string varName = ReadUTF8String(namePtr);
                callback?.Invoke(varName, value);
            };
            int uid = HALSIM_RegisterDigitalPWMInitializedCallback(Index, modCallback, IntPtr.Zero, initialNotify);

            if (!m_initializedCallbacks.TryAdd(uid, modCallback))
            {
                HALSIM_CancelDigitalPWMInitializedCallback(Index, uid);
                throw new ArgumentException("Key cannot be added multiple times to the dictionary");
            }
            return(uid);
        }
        public void RunNotifySocket()
        {
            //this runs on a background thread
            IPAddress  bindAddress  = IPAddress.Parse(this.clientIP);
            IPEndPoint bindEndPoint = new IPEndPoint(bindAddress, this.clientPort);

            receiverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            receiverSocket.Bind(bindEndPoint);
            receiverSocket.Listen(int.MaxValue);

            Console.WriteLine("\n ########## \n Notify Socket Created");

            Socket tcpClient;


            tcpClient = receiverSocket.Accept();
            byte[] buffer = new byte[2048];

            while (true)
            {
                try
                {
                    Array.Clear(buffer, 0, buffer.Length);
                    int    byteRecv     = tcpClient.Receive(buffer, 0, buffer.Length, SocketFlags.None);
                    string receviedData = Encoding.ASCII.GetString(buffer, 0, byteRecv);
                    if (receviedData.Contains("BYE"))
                    {
                        break;
                    }
                    Console.WriteLine("\n ################# \n received {0}", receviedData);
                    //post to the main ui thread to run the get recent info function
                    NotifyCallback d = new NotifyCallback(GetRecentInfo);
                    this.Invoke(d);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Didnt work" + e.Message);
                }
            }

            receiverSocket.Close();
        }
コード例 #15
0
        //Does a 2 way attachment for the jumpers
        public static void AttachDioPins(int input, int output)
        {
            NotifyCallback callback = (key, value) =>
            {
                if (!SimData.DIO[output].GetIsInput())
                {
                    SimData.DIO[input].SetValue(value.GetBoolean());
                }
            };

            SimData.DIO[output].RegisterValueCallback(callback);


            NotifyCallback callback2 = (key, value) =>
            {
                if (!SimData.DIO[input].GetIsInput())
                {
                    SimData.DIO[output].SetValue(value.GetBoolean());
                }
            };

            SimData.DIO[input].RegisterValueCallback(callback2);
        }
コード例 #16
0
        public void Dispose()
        {
            _headA = null;
            _headB = null;

            _tailA = null;
            _tailB = null;

            _northWestTree = null;
            _northEastTree = null;

            _southEastTree = null;
            _southWestTree = null;

            _object             = null;
            _processingCallback = null;
            _notifyCallback     = null;

            Exists = false;

            next             = _cachedTreesHead;
            _cachedTreesHead = this;
            _NUM_CACHED_QUAD_TREES++;
        }
コード例 #17
0
 public unsafe partial int SetMemObjectDestructor([Flow(FlowDirection.In)] nint memobj, [Flow(FlowDirection.In), PinObjectAttribute(PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] void *user_data);
コード例 #18
0
        // .\WMIMon.exe "[-filter=regularexpression]" "[-stop=[start|end|none]]"   [-log=all|filter] [-action=powershellpipeline]]
        static void Main(string[] args)
        {
            string filter = "";

            StopCondition uStop        = StopCondition.none;
            bool          LogOnFilter  = true;
            UInt64        IfStopStatus = 0;
            bool          bAction      = false;
            string        PipeLine     = "";
            Runspace      runSpace     = RunspaceFactory.CreateRunspace();

            runSpace.Open();

            Dictionary <UInt64, string> PendingOp = new Dictionary <UInt64, string>();



            foreach (string arg in args)
            {
                Match m;

                m = Regex.Match(arg, "-(f|fi|fil|filt|filt|filte|filter)=(.+)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    filter = m.Groups[2].ToString().ToLower();
                    Console.WriteLine("Parsing:\tfiltering on {0}", filter);
                    if (!IsValidRegex(filter))
                    {
                        Console.WriteLine("Parsing:\tInvalid regular expression {0}", filter);
                        return;
                    }
                    continue;
                }

                m = Regex.Match(arg, "-(s|st|sto|stop)=(start|end|none)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    string stop = m.Groups[2].ToString().ToLower();
                    uStop = StopCondition.none;
                    if (stop == "start")
                    {
                        uStop = StopCondition.start;
                    }
                    else if (stop == "end")
                    {
                        uStop = StopCondition.stop;
                    }
                    Console.WriteLine("Parsing:\twill stop if filter matches {0}", stop);
                    continue;
                }
                m = Regex.Match(arg, "-(l|lo|log)=(all|filter)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    string log = m.Groups[2].ToString().ToLower();
                    Console.WriteLine("Parsing:\tlogging option : {0} ", log);
                    if (log == "all")
                    {
                        LogOnFilter = false;
                    }
                    else
                    {
                        LogOnFilter = true;
                    }


                    continue;
                }
                m = Regex.Match(arg, "-(i|if|ifs|ifsto|ifstop|ifstops|ifstopst|ifstopstat|ifstopstatu|ifstopstatus)=(0x[0-9,a-f]+|[0-9,a-f]+)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    // bAction = true;
                    IfStopStatus = Convert.ToUInt64(m.Groups[2].ToString(), 16);
                    Console.WriteLine("Parsing:\tPowershell will end if status is : 0x{0:x} ", IfStopStatus);
                    continue;
                }

                m = Regex.Match(arg, "-(a|ac|act|acti|actio|action)=(.+)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    bAction  = true;
                    PipeLine = m.Groups[2].ToString();
                    Console.WriteLine("Parsing:\tPowershell action when filter is found : {0} ", PipeLine);
                }
                else
                {
                    Console.WriteLine("Parsing:\tInvalid argument {0}\n", arg);
                    Console.WriteLine(
                        @"
Usage:  WmiMon [-filter=regular_expression_string] [-stop=start|end|none] [-ifstopstatus=hexadecimal_value] [-log=all|filter] [action=pipeline]
                  default WmiMon [-filter=.*] [-stop=none] [-log=all]

will monitor WMI activity. By default all WMI activities are displayed. 

You can filter the output with the -filter switch.

You can stop the application :
- if the filtering is successfull. Stop will occur at activity startup  if -stop=start is specified.
      If -stop=end is specified we will wait for the end of the activity to stop the monitoring
        Warning : if many records match the filtering pattern , memory usage  may increase  
- if the filtering is successfull and _ifstopstatus condition is meet
    Warning : if many records match the filtering pattern , memory usage for this query may be hudge  

For all filtered items or if a stop condition is meet , the pipeline action will be executed         
Powershell variables WMIMON_* will be set in Powershell runspace to reflect the current WMI activity.
Your Powershell actions may use these variables (client PID, client computer, client user, stop status, WMI query,...)  

N.B: WMIMon is based on RealTime ETL notification. ETL infrastructure doesn't guarantee that all events will be received.
N.B: WMI Stop operation logging may occur after a delay based on client (get-cim* cmdlets cleanup occurs immediately 
     This is not true with get-wmiobject cmdlet).

Feel Free to report any bug or suggestion to [email protected]

Example: 
"

                        );

                    return;
                }
            }

            var exitEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                exitEvent.Set();
            };


            NotifyCallback Notify = (string OutStr, bool bError) =>
            {
                if (bError)
                {
                    Console.WriteLine("******! Error  {0}", OutStr);
                }
                else
                {
                    Console.WriteLine("***** {0}", OutStr);
                }
            };
            GetResultCallBack Result = (string OutStr, UInt32 GroupId, UInt32 OpId) =>
            {
                bool   bDisplay        = true;
                bool   bStopOperation  = false;
                UInt64 StopStatus      = 0;
                string ClientProcessId = "";
                string Executable      = "";
                string Computer        = "";
                string User            = "";
                bool   bFilter         = (filter.Length != 0) ? true : false;
                bool   bFilterMatch    = false;
                bool   bStop           = false;

                string PendingQuery = "";
                bool   bDisplayStop = false;

                Match m;
                m = Regex.Match(OutStr, "^\\d\\d:\\d\\d:\\d\\d.\\d\\d\\d Stop Op=\\d+ 0x([0-9a-fA-F]+)", RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    bStopOperation = true;
                    bDisplayStop   = true;
                    StopStatus     = Convert.ToUInt64(m.Groups[1].ToString(), 16);


                    if (bFilter)
                    {
                        bDisplayStop = false;

                        //is this operation in the Pending list
                        if (PendingOp.TryGetValue(OpId, out PendingQuery))
                        {
                            m = Regex.Match(PendingQuery, "^\\d\\d:\\d\\d:\\d\\d.\\d\\d\\d .* _ClientProcessId=(\\d+) \\[(.*)\\] (.*) (.*) ", RegexOptions.IgnoreCase);
                            if (m.Success)
                            {
                                ClientProcessId = m.Groups[1].ToString();
                                Executable      = m.Groups[2].ToString();
                                Computer        = m.Groups[3].ToString();
                                User            = m.Groups[4].ToString();
                                bDisplayStop    = true;
                            }
                            PendingOp.Remove(OpId);
                            if ((IfStopStatus != 0) && (StopStatus == IfStopStatus))
                            {
                                bStop = true;
                            }
                            else if (StopCondition.stop == uStop)
                            {
                                bStop = true;
                            }
                            // Console.WriteLine("==== Debug : Removing Pending Stop {0} \\ {1}\\ bStop {2} ", OutStr, PendingQuery , bStop );
                        }
                    }
                }
                else
                {
                    bStopOperation = false;
                    m = Regex.Match(OutStr, "^\\d\\d:\\d\\d:\\d\\d.\\d\\d\\d .* _ClientProcessId=(\\d+) \\[(.*)\\] (.*) (.*) ", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        ClientProcessId = m.Groups[1].ToString();
                        Executable      = m.Groups[2].ToString();
                        Computer        = m.Groups[3].ToString();
                        User            = m.Groups[4].ToString();
                    }
                }
                if (!bStopOperation)
                {
                    if (bFilter)
                    {
                        string          outwithoutn = OutStr.Replace("\n", "");
                        MatchCollection mFilter     = Regex.Matches(outwithoutn, filter, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                        if (mFilter.Count > 0)
                        {
                            bFilterMatch = true;
                        }
                    }
                }
                // at this point
                // bFilter ==> if filter
                // bFilterMatch ==> if filter match
                // bLogFilter ==> true -log=filter
                //            ==> false -log=all
                // uStop ==> StopCondition.none , StopCondition.start , StopCondition.end
                // bAction == TRUE ==> pipeline
                bDisplay = false;

                if (bFilter)
                {
                    bDisplay = false;
                    if (bFilterMatch && LogOnFilter == true)
                    {
                        bDisplay = true;
                    }
                    else if (LogOnFilter == false)
                    {
                        bDisplay = true;
                    }
                    if (uStop == StopCondition.start && bFilterMatch)
                    {
                        bStop = true;
                    }
                    else if (uStop == StopCondition.stop && bFilterMatch)
                    {
                        // TODO : add to stoppending list
                    }
                    if (bFilter && bFilterMatch)
                    {
                        PendingOp.Add(OpId, OutStr);
                        // Console.WriteLine("==== Debug Adding {0} in Pending list ", OpId);
                    }
                }
                else
                {
                    bDisplay = true;
                }
                if (bDisplay || bDisplayStop)
                {
                    Console.WriteLine("***** {0}", OutStr);
                }

                if ((bAction && bFilter && bFilterMatch) | (bStop && bFilter))
                {
                    // TODO Execute Pipeline
                    runSpace.SessionStateProxy.SetVariable("WMIMON_PID", ClientProcessId);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_EXECUTABLE", Executable);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_COMPUTER", Computer);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_USER", User);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_STOPSTATUS", StopStatus);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_ACTIVITY", OutStr);
                    runSpace.SessionStateProxy.SetVariable("WMIMON_RELATEDACTIVITY", PendingQuery);
                    Pipeline pipeline = runSpace.CreatePipeline();
                    String   script   = PipeLine + " | out-string ";
                    pipeline.Commands.AddScript(script);

                    Collection <PSObject> Results;
                    try
                    {
                        Results = pipeline.Invoke();
                        foreach (PSObject PsObj  in Results)
                        {
                            Console.WriteLine(PsObj.ToString());
                        }
                    }
                    catch (PSInvalidOperationException ioe)
                    {
                        Console.WriteLine("Powershell Error: " + ioe.Message);
                        pipeline.Stop();
                        pipeline = null;
                    }
                    catch (System.Management.Automation.RuntimeException error)
                    {
                        ErrorRecord e = error.ErrorRecord;
                        Console.WriteLine("Powershell Error: {0}{1} ", e.ToString(), e.InvocationInfo.PositionMessage);
                        pipeline.Stop();
                        pipeline = null;
                    }
                }

                if (bStop)
                {
                    exitEvent.Set();
                }
            };

            IntPtr Context = (IntPtr)1;
            IntPtr Handle  = exitEvent.SafeWaitHandle.DangerousGetHandle();

            try
            {
                StartAndWait((IntPtr)Handle, Context, Notify, Result); // cf https://msdn.microsoft.com/en-us/library/7esfatk4(VS.71).aspx
            }
            catch (SystemException e)
            {
                Console.WriteLine("Unexpected error {0} ", e);
            }
        }
 public static unsafe int SetMemObjectDestructor <T0>(this AppleSetMemObjectDestructor thisApi, [Flow(FlowDirection.In)] nint memobj, [Flow(FlowDirection.In), PinObjectAttribute(PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] Span <T0> user_data) where T0 : unmanaged
 {
     // SpanOverloader
     return(thisApi.SetMemObjectDestructor(memobj, pfn_notify, out user_data.GetPinnableReference()));
 }
コード例 #20
0
 public Observer(NotifyCallback callback)
 {
     this.callback = callback;
 }
コード例 #21
0
ファイル: FlxG.cs プロジェクト: mayur70/MonoFlixelEngine
        /// <summary>
        /// Call this function to see if one `FlxObject` overlaps another within `FlxG.worldBounds`.
        /// Can be called with one object and one group, or two groups, or two objects,
        /// whatever floats your boat! For maximum performance try bundling a lot of objects
        /// together using a `FlxGroup` (or even bundling groups together!).
        ///
        /// NOTE: does NOT take objects' `scrollFactor` into account, all overlaps are checked in world space.
        ///
        /// NOTE: this takes the entire area of `FlxTilemap`s into account (including "empty" tiles).
        ///       Use `FlxTilemap#overlaps()` if you don't want that.
        /// </summary>
        /// <param name="objectOrGroup1">The first object or group you want to check.</param>
        /// <param name="objectOrGroup2">The second object or group you want to check. If it is the same as the first,Flixel knows to just do a comparison within that group.</param>
        /// <param name="notifyCallback">A function with two `FlxObject` parameters -e.g. `onOverlap(object1:FlxObject, object2:FlxObject)` -that is called if those two objects overlap.</param>
        /// <param name="processingCallback">A function with two `FlxObject` parameters -e.g. `onOverlap(object1:FlxObject, object2:FlxObject)` -that is called if those two objects overlap.If a `ProcessCallback` is provided, then `NotifyCallback`will only be called if `ProcessCallback` returns true for those objects!</param>
        /// <returns>Whether any overlaps were detected.</returns>
        public static bool Overlap(FlxBasic objectOrGroup1 = null, FlxBasic objectOrGroup2 = null, NotifyCallback notifyCallback = null, ProcessingCallback processingCallback = null)
        {
            if (objectOrGroup1 == null)
            {
                objectOrGroup1 = Game.CurrentState;
            }
            if (objectOrGroup1 == objectOrGroup2)
            {
                objectOrGroup2 = null;
            }
            FlxQuadTree.Divisions = WorldDivisions;
            FlxQuadTree quadTree = FlxQuadTree.Recycle(WorldBounds.X, WorldBounds.Y, WorldBounds.Width, WorldBounds.Height);

            quadTree.Load(objectOrGroup1, objectOrGroup2, notifyCallback, processingCallback);
            bool result = quadTree.Execute();

            quadTree.Dispose();
            return(result);
        }
コード例 #22
0
        public void TestSolenoid()
        {
            Reset();

            using (Solenoid solenoid1 = new Solenoid(0))
                using (Solenoid solenoid2 = new Solenoid(1))
                {
                    NotifyCallback solenoid1Callback = null;
                    NotifyCallback solenoid2Callback = null;
                    int            callback1Id       = -1;
                    int            callback2Id       = -1;

                    if (RobotBase.IsSimulation)
                    {
                        solenoid1Callback = (string s, HAL_Value val) =>
                        {
                            SimData.DIO[12].SetValue(!val.GetBoolean());
                        };
                        callback1Id = SimData.PCM[0].RegisterSolenoidOutputCallback(0, solenoid1Callback, false);

                        solenoid2Callback = (s, o) =>
                        {
                            SimData.DIO[13].SetValue(!o.GetBoolean());
                        };
                        callback2Id = SimData.PCM[0].RegisterSolenoidOutputCallback(1, solenoid2Callback);
                    }

                    solenoid1.Set(false);
                    solenoid2.Set(false);

                    Timer.Delay(SolenoidDelayTime);

                    Assert.That(fakeSolenoid1.Get());
                    Assert.That(fakeSolenoid2.Get());
                    Assert.That(!solenoid1.Get());
                    Assert.That(!solenoid2.Get());

                    solenoid1.Set(true);
                    solenoid2.Set(false);

                    Timer.Delay(SolenoidDelayTime);

                    Assert.That(!fakeSolenoid1.Get());
                    Assert.That(fakeSolenoid2.Get());
                    Assert.That(solenoid1.Get());
                    Assert.That(!solenoid2.Get());

                    solenoid1.Set(false);
                    solenoid2.Set(true);

                    Timer.Delay(SolenoidDelayTime);

                    Assert.That(fakeSolenoid1.Get());
                    Assert.That(!fakeSolenoid2.Get());
                    Assert.That(!solenoid1.Get());
                    Assert.That(solenoid2.Get());

                    solenoid1.Set(true);
                    solenoid2.Set(true);

                    Timer.Delay(SolenoidDelayTime);

                    Assert.That(!fakeSolenoid1.Get());
                    Assert.That(!fakeSolenoid2.Get());
                    Assert.That(solenoid1.Get());
                    Assert.That(solenoid2.Get());

                    if (RobotBase.IsSimulation)
                    {
                        SimData.PCM[0].CancelSolenoidOutputCallback(0, callback1Id);
                        SimData.PCM[0].CancelSolenoidOutputCallback(1, callback2Id);
                    }
                }
        }
コード例 #23
0
 public unsafe int SetMemObjectDestructor <T0>([Flow(FlowDirection.In)] int memobj, [Flow(FlowDirection.In), Ultz.SuperInvoke.InteropServices.PinObjectAttribute(Ultz.SuperInvoke.InteropServices.PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] Span <T0> user_data) where T0 : unmanaged
 {
     // IntPtrOverloader
     return(SetMemObjectDestructor(new IntPtr(memobj), pfn_notify, user_data));
 }
コード例 #24
0
 public abstract int SetMemObjectDestructor <T0>([Flow(FlowDirection.In)] IntPtr memobj, [Flow(FlowDirection.In), Ultz.SuperInvoke.InteropServices.PinObjectAttribute(Ultz.SuperInvoke.InteropServices.PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] Span <T0> user_data) where T0 : unmanaged;
コード例 #25
0
ファイル: FlxG.cs プロジェクト: mayur70/MonoFlixelEngine
 /// <summary>
 /// Call this function to see if one `FlxObject` collides with another within `FlxG.worldBounds`.
 /// Can be called with one object and one group, or two groups, or two objects,
 /// whatever floats your boat! For maximum performance try bundling a lot of objects
 /// together using a FlxGroup (or even bundling groups together!).
 ///
 /// This function just calls `FlxG.overlap` and presets the `ProcessCallback` parameter to `FlxObject.separate`.
 ///  To create your own collision logic, write your own `ProcessCallback` and use `FlxG.overlap` to set it up.
 ///  NOTE: does NOT take objects' `scrollFactor` into account, all overlaps are checked in world space.
 /// </summary>
 /// <param name="objectOrGroup1">The first object or group you want to check.</param>
 /// <param name="objectOrGroup2">The second object or group you want to check. If it is the same as the first,Flixel knows to just do a comparison within that group.</param>
 /// <param name="notifyCallback"> A function with two `FlxObject` parameters -e.g. `onOverlap(object1:FlxObject, object2:FlxObject)` -that is called if those two objects overlap.</param>
 /// <returns>Whether any objects were successfully collided/separated.</returns>
 public static bool Collide(FlxBasic objectOrGroup1 = null, FlxBasic objectOrGroup2 = null, NotifyCallback notifyCallback = null)
 {
     return(Overlap(objectOrGroup1, objectOrGroup2, notifyCallback, FlxObject.Separate));
 }
 //
 // Summary:
 //     Notifies the user of one or more GPIB events by invoking the user callback.
 //
 // Parameters:
 //   mask:
 //     Bit mask of GPIB events to notice.
 //
 //   callback:
 //     Pointer to the delegate method NationalInstruments.NI4882.NotifyCallback.
 //
 //   userData:
 //     User-defined reference data for the callback.
 //
 // Exceptions:
 //   NationalInstruments.NI4882.GpibException:
 //     The NI-488.2 driver returns an error as a result of calling this method.
 //
 //   System.ObjectDisposedException:
 //     This member is called after the NationalInstruments.NI4882.Board.Dispose()
 //     method has been called directly from your code or indirectly through a finalizer.
 //
 //   System.DllNotFoundException:
 //     The NI-488.2 driver library cannot be found.
 //
 //   System.EntryPointNotFoundException:
 //     A required operation in the NI-488.2 driver library cannot be found.
 //
 //   System.ArgumentException:
 //      mask is invalid or nonzero.
 //     -or-
 //     callback is null.
 //
 //   System.InvalidOperationException:
 //      The inner exception is set to the NationalInstruments.NI4882.GpibException
 //     due to one of the following conditions:
 //     A different process owns a lock for the interface.
 //     -or-
 //     Nonexistent GPIB interface.
 //     -or-
 //     Asynchronous I/O operation in progress.
 //     -or-
 //     The current NI-488.2 driver cannot perform notification on one or more of
 //     the specified mask bits.
 //
 // Remarks:
 //     If mask is nonzero, NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     monitors the events specified by mask, and when one or more of the events
 //     is true, the callback is invoked. The only valid mask bits are NationalInstruments.NI4882.GpibStatusFlags.IOComplete,
 //     NationalInstruments.NI4882.GpibStatusFlags.Timeout, NationalInstruments.NI4882.GpibStatusFlags.End,
 //     and NationalInstruments.NI4882.GpibStatusFlags.DeviceServiceRequest. If NationalInstruments.NI4882.GpibStatusFlags.Timeout
 //     is set in the notify mask, and one or more of the other specified events
 //     has not already occurred, NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     calls the callback method when the NationalInstruments.NI4882.Board.IOTimeout
 //     period has elapsed. If NationalInstruments.NI4882.GpibStatusFlags.Timeout
 //     is not set in the Notify mask, the callback is not called until one or more
 //     of the specified events occur.
 //     Notification on NationalInstruments.NI4882.GpibStatusFlags.DeviceServiceRequest
 //     is not guaranteed to work if automatic serial polling is disabled. By default,
 //     automatic serial polling is enabled.
 //     A device can have only one outstanding NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     call at any one time. If a current NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     is in effect for the device, it is replaced by a subsequent NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     call. An outstanding NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     call for NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     can be canceled by a subsequent NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     call for a device that has a mask of zero.
 //     If a NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     call is outstanding and one or more of the GPIB events it is waiting on become
 //     true, the callback is invoked.
 //     Notification occurs when the state of one or more of the mask bits is true.
 //     Therefore, if a request is made to be notified when NationalInstruments.NI4882.GpibStatusFlags.IOComplete
 //     is true, and NationalInstruments.NI4882.GpibStatusFlags.IOComplete is currently
 //     true, the callback is invoked immediately.  In Measurement Studio Technology
 //     Preview 1, NationalInstruments.NI4882.NotifyData.SetReenableMask(NationalInstruments.NI4882.GpibStatusFlags)
 //     does not work correctly. To work around this problem, call NationalInstruments.NI4882.Device.Notify(NationalInstruments.NI4882.GpibStatusFlags,NationalInstruments.NI4882.NotifyCallback,System.Object)
 //     every time after the NationalInstruments.NI4882.NotifyCallback returns.
 public void Notify(GpibStatusFlags mask, NotifyCallback callback, object userData);
コード例 #27
0
 static extern void StartAndWait(IntPtr Handle, IntPtr Context, [MarshalAs(UnmanagedType.FunctionPtr)] NotifyCallback Notify, [MarshalAs(UnmanagedType.FunctionPtr)] GetResultCallBack Result);
コード例 #28
0
 public partial int SetMemObjectDestructor <T0>([Flow(FlowDirection.In)] nint memobj, [Flow(FlowDirection.In), PinObjectAttribute(PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] out T0 user_data) where T0 : unmanaged;
コード例 #29
0
 public abstract unsafe int SetMemObjectDestructor([Flow(FlowDirection.In)] IntPtr memobj, [Flow(FlowDirection.In), Ultz.SuperInvoke.InteropServices.PinObjectAttribute(Ultz.SuperInvoke.InteropServices.PinMode.UntilNextCall)] NotifyCallback pfn_notify, [Flow(FlowDirection.Out)] void *user_data);
コード例 #30
0
        private void Notify(NotifyEventArgs e)
        {
            if ((this != null && InvokeRequired) ||
                (txtLog != null && txtLog.InvokeRequired) ||
                (dgvResult != null && dgvResult.InvokeRequired) ||
                (statusStrip1 != null && statusStrip1.InvokeRequired))
            {
                NotifyCallback d = new NotifyCallback(Notify);
                this.BeginInvoke(d, e);
            }
            else
            {
                string text = e.Status.ToString() + ": " + e.Message;

                if (e.Status == OperationStatus.PAUSED ||
                    e.Status == OperationStatus.RESUMED ||
                    e.Status == OperationStatus.STOPPED)
                {
                    this.Enabled = true;
                    MessageBox.Show(e.Message);
                    lblStatus.Text = e.Message;
                }

                if (e.Status == OperationStatus.BUILDING_FILE_LIST ||
                    e.Status == OperationStatus.CALCULATING_CRC ||
                    e.Status == OperationStatus.BUILDING_DUPLICATE_LIST ||
                    e.Status == OperationStatus.READY ||
                    e.Status == OperationStatus.COMPLETE)
                {
                    lblStatus.Text      = text;
                    pgCount.Visible     = true;
                    pgCount.Maximum     = e.TotalCount;
                    pgCount.Value       = e.CurrentCount;
                    pgCount.ToolTipText = e.CurrentCount + "/" + e.TotalCount;
                }

                if (e.Status == OperationStatus.STOPPED)
                {
                    btnSearch.Enabled = true;
                    btnStop.Enabled   = false;
                    btnPause.Enabled  = false;
                }

                if (e.Status == OperationStatus.COMPLETE)
                {
                    btnSearch.Enabled = true;
                    btnStop.Enabled   = false;
                    btnPause.Enabled  = false;
                    if (e.DupList != null)
                    {
                        Fill(e.DupList);
                    }
                }

                if (chkLog.Checked)
                {
                    if (e.Status == OperationStatus.CALCULATING_CRC ||
                        e.Status == OperationStatus.ERROR ||
                        e.Status == OperationStatus.BUILDING_DUPLICATE_LIST)
                    {
                        txtLog.Text += text + Environment.NewLine;
                    }
                    else if (chkLogAll.Checked)
                    {
                        txtLog.Text += text + Environment.NewLine;
                    }
                }

                if (chkBFL.Checked && e.Status == OperationStatus.BUILDING_FILE_LIST)
                {
                    Logger.Info(text);
                }
                else if (chkCCRC.Checked && e.Status == OperationStatus.CALCULATING_CRC)
                {
                    Logger.Debug(text);
                }
                else if (chkBDL.Checked && e.Status == OperationStatus.BUILDING_DUPLICATE_LIST)
                {
                    Logger.Debug(text);
                }
                else if (chkCOMP.Checked && e.Status == OperationStatus.COMPARING)
                {
                    Logger.Debug(text);
                }
                else if (chkFIL.Checked && e.Status == OperationStatus.FILTERING)
                {
                    Logger.Debug(text);
                }
                else if (e.Status != OperationStatus.BUILDING_FILE_LIST &&
                         e.Status != OperationStatus.CALCULATING_CRC &&
                         e.Status != OperationStatus.BUILDING_DUPLICATE_LIST &&
                         e.Status != OperationStatus.COMPARING &&
                         e.Status != OperationStatus.FILTERING)
                {
                    Logger.Debug(text);
                }
            }
        }
コード例 #31
0
 static extern IntPtr Start(IntPtr Context, [MarshalAs(UnmanagedType.FunctionPtr)] NotifyCallback Notify, [MarshalAs(UnmanagedType.FunctionPtr)] GetResultCallBack Result);