Ejemplo n.º 1
0
 /// <summary>
 /// Fnction for AI buffer ready event for general operation.
 /// </summary>
 unsafe static void ai_buf_ready_func_for_general_op()
 {
     // Process AI data of ready buffer HERE
     // Transfer data from kernel to user
     Int32[] Data_array = new Int32[daqCard.GetSampleCountsPerChannel()];
     try
     {
         daqCard.TransferBuffer(Data_array);
         if (motionCard.currentDirection != MotionDirection.Stop)
         {
             // Copy data to update buffer(List)
             listHandler.ai_dataList.Add(Data_array);
         }
         else
         {
             Console.WriteLine("In ai_buf_ready_func_for_general_op, return event is going to be set");
             Returned_event.Set(); // Signal Returned Event to call AsyncClear, which will call back ai_done_cbfunc.
         }
     }
     catch (InvalidOperationException e)
     {
         Console.WriteLine(e.Message);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Function for AI buffer ready event during find return point operation.
        /// </summary>
        unsafe static void ai_buf_ready_func_for_find_rtn_pt()
        {
            // Transfer data from kernel to user
            Int32[] Data_array          = new Int32[daqCard.GetSampleCountsPerChannel()];
            double  ReturnningStopPoint = 0.1;//set stop point to 0.1mm when returning

            try
            {
                daqCard.TransferBuffer(Data_array);
                if (motionCard.currentDirection != MotionDirection.Stop)
                {
                    // Copy data to update buffer(List)
                    listHandler.ai_dataList.Add(Data_array);

                    // Pressing: Check AI raw data. See if load cell's pressure is over limit
                    if (motionCard.currentDirection == MotionDirection.Pressing && daqCard.GetLatestVoltageValue() > GetForceLimitInMillivolt())
                    {
                        // Stop Servo and Return
                        motionCard.Stop(); // the stop function will trigger "Move Done" Event
                        RecordReturnPosistion(daqCard.GetlatestEncoderValue());
                    }

                    // Returning: Check Encoder raw data. See if it reutrns to ReturnningStopPoint
                    if (motionCard.currentDirection == MotionDirection.Returning && daqCard.GetlatestEncoderValue() * config_para.encoder_unit_to_mm < ReturnningStopPoint)
                    {
                        // Done. Stop Servo.
                        motionCard.Stop();
                        Returned_event.Set(); // Signal Returned Event to call AsyncClear, which will call back ai_done_cbfunc.
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
        }