Ejemplo n.º 1
0
//---------------------------------------------------------------------------
//
// Function:    AppCbSync
//
// Description: sync event callback function called by event module within
//              kernel part (high priority).
//              This function sets the outputs, reads the inputs and runs
//              the control loop.
//
// Parameters:  void
//
// Returns:     tEplKernel      = error code,
//                                kEplSuccessful = no error
//                                otherwise = post error event to API layer
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel PUBLIC AppCbSync(void)
{
  tEplKernel EplRet = kEplSuccessful;
  EplRet = EplApiProcessImageExchange(&AppProcessImageCopyJob_g);
    
  if (EplRet != kEplSuccessful) {
    return EplRet;
  }
  return EplRet;
}
//---------------------------------------------------------------------------
//
// Function:    AppCbSync
//
// Description: sync event callback function called by event module within
//              kernel part (high priority).
//              This function sets the outputs, reads the inputs and runs
//              the control loop.
//
// Parameters:  void
//
// Returns:     tEplKernel      = error code,
//                                kEplSuccessful = no error
//                                otherwise = post error event to API layer
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel PUBLIC AppCbSync(void)
{
    tEplKernel          EplRet;
    int                 i;

    EplRet = EplApiProcessImageExchange(&AppProcessImageCopyJob_g);
    if (EplRet != kEplSuccessful)
    {
        return EplRet;
    }

    uiCnt_g++;

    nodeVar_g[0].m_uiInput = AppProcessImageOut_g.CN1_M00_Digital_Input_8_Bit_Byte_1;
    nodeVar_g[1].m_uiInput = AppProcessImageOut_g.CN32_M00_Digital_Input_8_Bit_Byte_1;
    nodeVar_g[2].m_uiInput = AppProcessImageOut_g.CN110_M00_Digital_Input_8_Bit_Byte_1;

    for (i = 0; (i < MAX_NODES) && (iUsedNodeIds_g[i] != 0); i++)
    {
        /* Running Leds */
        /* period for LED flashing determined by inputs */
        nodeVar_g[i].m_uiPeriod = (nodeVar_g[i].m_uiInput == 0) ? 1 : (nodeVar_g[i].m_uiInput * 20);
        if (uiCnt_g % nodeVar_g[i].m_uiPeriod == 0)
        {
            if (nodeVar_g[i].m_uiLeds == 0x00)
            {
                nodeVar_g[i].m_uiLeds = 0x1;
                nodeVar_g[i].m_iToggle = 1;
            }
            else
            {
                if (nodeVar_g[i].m_iToggle)
                {
                    nodeVar_g[i].m_uiLeds <<= 1;
                    if (nodeVar_g[i].m_uiLeds == APP_LED_MASK_1)
                    {
                        nodeVar_g[i].m_iToggle = 0;
                    }
                }
                else
                {
                    nodeVar_g[i].m_uiLeds >>= 1;
                    if (nodeVar_g[i].m_uiLeds == 0x01)
                    {
                        nodeVar_g[i].m_iToggle = 1;
                    }
                }
            }
        }

        if (nodeVar_g[i].m_uiInput != nodeVar_g[i].m_uiInputOld)
        {
            nodeVar_g[i].m_uiInputOld = nodeVar_g[i].m_uiInput;
        }

        if (nodeVar_g[i].m_uiLeds != nodeVar_g[i].m_uiLedsOld)
        {
            nodeVar_g[i].m_uiLedsOld = nodeVar_g[i].m_uiLeds;
        }
    }

    AppProcessImageIn_g.CN1_M00_Digital_Ouput_8_Bit_Byte_1 = nodeVar_g[0].m_uiLeds;
    AppProcessImageIn_g.CN32_M00_Digital_Ouput_8_Bit_Byte_1 = nodeVar_g[1].m_uiLeds;
    AppProcessImageIn_g.CN110_M00_Digital_Ouput_8_Bit_Byte_1 = nodeVar_g[2].m_uiLeds;

    return EplRet;
}
Ejemplo n.º 3
0
tEplKernel PUBLIC AppCbSync(void)
{
    tEplKernel          EplRet;

    EplRet = EplApiProcessImageExchange(&AppProcessImageCopyJob_g);
    if (EplRet != kEplSuccessful)
    {
        return EplRet;
    }

    uiCnt_g++;

#if 0
	static UINT uiDigitalModData = 1;
	int ch1;
	int ch2 = 0;
	static UINT uiCount = 0;
	static const UINT uiWait = 10;




	uiDigitalModData++;
	
	switch (AutoHome)
	{

		case 0:	//wait connection
		{	
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 0;

			if	(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord != 0)
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;
					AutoHome = 1;
					printf("Connection complete\n");
				}
			}
		}
		break;

		case 1:	//auto error acknowledge
		{
			if	(AppProcessImageOut_g.CN2_M00_OutChannel_REC_ErrorCode != 0)	//check if error
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 128;
					AutoHome = 0;
					printf("clear errors not complete\n");
				}
			}
			else	//no error
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 2;
					printf("No errors complete\n");
				}
			}
		}
		break;

		case 2:	//shutdown
		{
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 6;

			if(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord & 0x0001) // 0000000000000001 check ready to switch on
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 3;
					printf("Shutdown complete\n");
				}
			}
		}
		break;

		case 3:	//switch on
		{
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 7;

			if(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord & 0x0002) // 0000000000000010 check bit switched on
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 4;
					printf("Switch on complete\n");
				}
			}
		}
		break;

		case 4:	//enable homing
		{
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ModesOfOperation = 6;
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_HomingMethod = -128;
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 15;

			if(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord & 0x0004) // 0000000000000100 check mode bit enabled
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 5;
					printf("Enable homing complete\n");
				}
			}
		}
		break;

		case 5:	//start homing
		{
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 31;

			if(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord & 0x3000) // 0011000000000000 check homing done
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 6;
					printf("Start homing complete\n");
				}
			}
		}
		break;

		case 6:	//disable operation
		{
			AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 7;

			if(AppProcessImageOut_g.CN2_M00_OutChannel_REC_StatusWord & 0x0002) // 0000000000000010 check switched on
			{
				if ( ++uiCount > uiWait )
				{
					uiCount = 0;

					AutoHome = 10;
					printf("Auto homing complete\n");
				}
			}
		}
		break;

		case 10: //auto homing done
		{
			if (_kbhit())
			{
				ch1 = getchar();
				printf("%c", ch1);

				switch (ch1)
				{
					case '1':	//shutdown
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 6;
						break;
					}
					case '2':	//switch on
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 7;
						break;
					}
					case '3':	//enable homing operation
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ModesOfOperation = 6;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_HomingMethod = -128;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 15;
						break;
					}
					case '4':	//home
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 31;
						break;
					}
					case '5':	//disable operation
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 7;
						break;
					}
					case '6':	//enable position move operation
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ModesOfOperation = 1;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 15;
						break;
					}
					case '7':	//new set point
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 31;
						  AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetPosition = AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetPosition + 1000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileAcceleration = 5000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileDeceleration = 5000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileVelocity		= 1000;
						break;
					}
					case '8':	//new set point
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 31;
						  AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetPosition = AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetPosition - 1000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileAcceleration = 5000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileDeceleration = 5000;
						  AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileVelocity		= 1000;
						break;
					}

					case '9':	//enable profile velocity move operation
					{
						AppProcessImageIn_g.CN2_MC0_InputChannel_REC_Polarity = 0;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileAcceleration = 5000;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileDeceleration = 5000;
						AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetVelocity	= 5000;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ModesOfOperation = 3;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 15;
						break;
					}

					case '0':	//enable profile velocity move operation
					{
						AppProcessImageIn_g.CN2_MC0_InputChannel_REC_Polarity = 64;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileAcceleration = 5000;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ProfileDeceleration = 5000;
						AppProcessImageIn_g.CN2_M40_InputChannel_REC_TargetVelocity	= 5000;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ModesOfOperation = 3;
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 15;
						break;
					}

					case 'a':	//error reset
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 128;
						break;
					}
					case 'b':	//error reset
					{
						AppProcessImageIn_g.CN2_M80_InputChannel_REC_ControlWord = 0;
						
						break;
					}
				}
			}
		}
		break;
	}

#endif

    return EplRet;
}