INtime Tech

INtime Top


KPAmasterAPI


KPA EtherCAT MasterÀÇ ¾îÇø®ÄÉÀÌ¼Ç ÀÎÅÍÆäÀ̽º

KPA EtherCAT Master´Â INtime ¸®¾óŸÀÓ ¾îÇø®ÄÉÀ̼ǰúÀÇ Á¦ÈÞ¸¦ ½Ç½ÃÇϱâ À§Çؼ­, dzºÎÇÑ ¾îÇø®ÄÉÀÌ¼Ç ÀÎÅÍÆäÀ̽º ÇÔ¼ö(API)¸¦ Á¦°øÇϰí ÀÖ½À´Ï´Ù

 

KPA EtherCAT MasterÀÇ API À϶÷

Name Feature
EcatGetErrorMessage() Retrieves system message string that corresponds to the specified system message code.
EcatGetLastError() Retrieves the last error message.
EcatGetMaxTraceCount() Retrieves maximum number of trace buffers.
EcatGetTraceMode() Retrieves information about current trace mode.
EcatSetMaxTraceCount() Sets maximum number of trace buffers.
EcatSetTraceMode() Enables/disables trace mode.Enabled trace mode increases CPU load and results in loss of master stack performance.
EcatTraceCategory() Trace category(location) of a system(error) message.
EcatConnectMaster() Connects master to devices.
EcatCreateMaster() Creates master's resources and context.
EcatDownloadConfigAsString() Downloads a master configuration incrementally.
EcatDownloadProjectAsString() Downloads a master project incrementally.
EcatDriverIsAvailable() Acquires information about the state of a driver.
EcatGetAdapterList() Acquires a list of network adapters available for the master.
EcatGetMasterVersion() Gets master's version.
EcatIsMasterStarted() Checks whether master is started or not.
EcatLoadConfigFromFileA() [obsolete] Loads a configuration using the supplied file name (ASCII version).
EcatLoadConfigFromFileW() [obsolete] Loads a configuration using the supplied file name (unicode version).
EcatLoadConfigFromString() Loads a configuration incrementally using the supplied configuration (sub) string.
EcatLoadProjectAsString() Loads an ECAT Studio project incrementally using the supplied project (sub) string.
EcatSetAutoRecoveryTimeout() Sets autorecovery timeout.
EcatSetHotPlugTimeout() Sets Hot-Plug Timeout.
EcatStartCyclicOperation() Launches master-slaves cyclic data exchange.
EcatDisconnectMaster() Disconnects master from physical device.
EcatFreeMaster() Frees master's resources and context.
EcatStopCyclicOperation() Stops master-slaves cyclic data exchange.
EcatGetProcessImageSize() Gets the process image size.
EcatUpdateProcessImage() "Updates the process image, starts one cycle of data exchange.
EcatDoneReadInputs() Completes reading of Process image inputs.
EcatGetInputs() [obsolete] Gets Process image inputs.
EcatGetInputVariable() [obsolete] Gets Process image input variable.
EcatGetInputVariables() Acquires information about Process image input variables.
EcatStartReadInputs() Starts reading of Process image inputs.
EcatDoneWriteOutputs() Completes writing of Process image outputs.
EcatForceOutputVariable() Forces Process image output variable.
EcatGetOutputs() [obsolete] Gets Process image outputs.
EcatGetOutputsMask() Gets Process image outputs mask and its size.
EcatGetOutputVariable() [obsolete] Gets Process image output variable.
EcatGetOutputVariables() Acquires information about Process image output variables.
EcatSetOutputs() [obsolete] Sets Process image outputs.
EcatSetOutputVariable() [obsolete] Sets Process image output variable.
EcatStartWriteOutputs() Starts writing of Process image outputs.
EcatUnforceOutputVariable() Unforces Process image output variable.
EcatFoEClose() Closes FoE communication.
EcatFoEOpen() Opens FoE communication.
EcatFoERead() Reads block of data using FoE communication.
EcatFoEWrite() Writes block of data using FoE communication.
EcatAddCoEObject() Adds mailbox CoE task.
EcatSlaveODCreateObject() Creates internal object to work with slave object dictionary.
EcatSlaveODDestroyObject() Destroys Slave OD object.
EcatSlaveODGetDescription() Acquires object description.
EcatSlaveODGetEntryDescription() Acquires object entry description.
EcatSlaveODGetObjectsIndexes() Acquires object dictionary indexes.
EcatEnableWatchdog() Enables/disables watchdog.
EcatGetMasterNetworkState() Acquires the current network state of the master.
EcatGetMasterReqState() Acquires the previously requested(see EcatRequestMasterState) master's state(may differ from actual master's state).
EcatGetMasterState() Acquires the current state of the master.
EcatMasterNetworkState() Network states of a master and constants relevant to network state.
EcatRequestMasterState() Requests the state of the master.That means this function instructs the master to change its state.
EcatWatchdogIsEnabled() Acquires information about the state of watchdog.
EcatClearSlaveStateError() Clears slave state error.
EcatGetActiveSlaveCount() Acquires count of active slaves.
EcatGetSlaveActivePosIndex() Acquires active positions of slaves in the network.
EcatGetSlaveCount() Retrieves count of slaves in the current configuration.
EcatGetSlaveEmgMessagesCount() Gets count of slave's emergency messages.
EcatGetSlaveFixAddress() Gets the slave's fixed address.The function retrieves Slave's fixed address from the configuration.
EcatGetSlaveNextEmgMessage() Reads emergency messages from the slave.
EcatGetSlavePIInputsInfo() Gets information about Slave's Process Image Inputs. The function requests the information for Slave's inputs from the configuration.
EcatGetSlavePIOutputsInfo() Gets information about Slave Process Image Outputs. The function requests the information for Slave's outputs from the configuration.
EcatGetSlaveReqState() Gets previously requested slave's state.
EcatGetSlaveState() Gets slave state.
EcatGetSlaveStateByPosIndex() Returns detected states of Slaves.
EcatRequestSlaveState() Requests the state of the slave.
EcatGetPIInputsSnapshot() Takes snapshot of master's inputs or outputs(max 32 bits per cycle).
EcatGetProcessImageSnapshot() Takes snapshot of master's inputs or outputs(max 64 bits per cycle).
EcatEnableFrameLogger() Enables/disables frame logger.
EcatFrameLoggerIsEnabled() Checks on if frame logger is enabled.
EcatGetDLInfo() Gets DL information register contents by position index.
EcatGetDLInfoByFixAddress() Gets DL information register contents by fixed address.
EcatGetDLStatus() Gets DL status register contents by position index.
EcatGetDLStatusByFixAddress() Gets DL status register contents by fixed address.
EcatGetLastFrames() Gets information about last logged frames.
EcatReadEEPROMByFixAddress() Downloads EEPROM content by fixed address.
EcatReadEEPROMByPosIndex() Downloads EEPROM content by position index.
EcatReadMemoryByPosIndex() Acquire content of memory by position index.
EcatSSGetSIIContentEnumByPosIndex() [obsolete] Gets SII content.
EcatSSGetSlaveCount() Detects actual number of slaves in the network.
EcatUpdateEEPROMChecksumByPosIndex() Updates EEPROM checksum by position index.
EcatWriteEEPROMByFixAddress() Uploads EEPROM content by fixed address.
EcatWriteEEPROMByPosIndex() Uploads EEPROM content by position index.
EcatWriteMemoryByPosIndex() Write data to memory by position index.
EcatGetStatistics() Acquires composite statistics for master and used network interfaces.
EcatResetStatistics() Resets composite statistics of master and used network interfaces.
EcatExtCtrlTaskHandler() Handler for external control task.
EcatResetExtCtrlTaskHandler() Resets execution of external task handler and sets the handler to the default one (i.e. empty handler).
EcatSetExtCtrlTaskHandler() Sets handler of user task that is to be executed upon each completion of Process Image data update.
EcatStartTask() Defines the external task to be executed upon each completion of Process Image data update.
EcatMasterThreadCreate() Create thread(start) Create thread(kernel) and start it.
EcatMasterThreadDestroy() Destroy thread(stop). Stop thread(kernel) and destroy it.
EcatMasterThreadErrorInit() Initialize error object Attach error object to thread object.
EcatMasterThreadGetCurrentThreadId() Get current thread identifier.
EcatMasterThreadIsCurrentThread() Check if is it current thread.
EcatMasterThreadIsStarted() Check if thread is started.
EcatMasterThreadSetParams() Set Thread parameters Change parameters of thread object. Function available only before thread started(EcatMasterThreadCreate()).
EcatGetData() Retrieves values from the location in source buffer defined by bit size and bit offset.
EcatGetVariable() Retrieves values(total length not more than 32 bits) from the location in source buffer defined by bit size and bit offset.
EcatSetData() Writes input values to location in destination buffer defined by bit size and bit offset.
EcatSetVariable() Writes input values(total length not more than 32 bits) to location in destination buffer defined by bit size and bit offset.
EcatCreateEvent() Creates Ecat event synchronization object.
EcatDestroyEvent() Destroys Ecat event synchronization object.
EcatWaitEvent() Waits on an Ecat event synchronization object.

 

ÄÚµù »ùÇÃ

ÃʱâÈ­ ó¸®/Á¾·á ó¸®ÀÇ »ç·Ê

/*****************************************************************************
 *
 *  FUNCTION:          main
 *
 *  DESCRIPTION:       ¸ÞÀÎ
 *
 \*****************************************************************************/

 
void                 main(void)
 
{
     ECAT_HANDLE          hMaster
= ECAT_NULL;
     
const ECAT_WCHAR* pwszAdapter;
     ECAT_RESULT          iResult
= 0;
     ECAT_BYTE            byState
= 0;
     ECAT_BYTE            byReqState
= 0;
     ECAT_INT32           nWait
= 0;
     ECAT_WORD            wInputByteSize
= 0;
     ECAT_WORD            wOutputByteSize
= 0;
 
     
// INtimeI/O¼­ºñ½º ´ë±â
     
WaitForINtimeIO();
 
     printf
("KPAEcatSample Start... \n");
 
     
// KPA EtherCAT Master ÃʱâÈ­
     
if ( ECAT_FAILED(InitializeKPAMasterAPI(KPA_MASTER_RSLFILE_NAME))  )
     
{
         printf
("An error occurred while loading the %s module\n", KPA_MASTER_RSLFILE_NAME);
         
goto finish;
     
}
 
     
//³×Æ®¿öÅ© µð¹ÙÀ̽º ¸í Ãëµæ
     
if ( ECAT_FAILED(KPAGetAdapterName(0, &pwszAdapter))  )
     
{
         printf
("KPAGetAdapterName Error\n");
         
goto finish;
     
}
 
     
// EtherCAT Master »ý¼º
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnCreateMaster)(&hMaster))  )
     
{
         printf
("EcatCreateMaster Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatCreateMaster...  OK\n");
     
}
 
     memset
(&EcatTaskData, 0, sizeof(CtrlTask));
     
EcatTaskData.hMaster = hMaster;
 
     
//¸¶½ºÅÍ Á¢¼Ó
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnConnectMaster)(hMaster, ECAT_MASTER_REDUNDANCY_TYPE_NORMAL, pwszAdapter, ECAT_NULL, ECAT_NULL))  )
     
{
         printf
("EcatConnectMaster Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatConnectMaster...  OK\n");
     
}
 
     
//configuration fileµ¶Æ÷ÇÔ
     
if ( ECAT_FAILED(iResult = KPALoadConfiguration(hMaster, KPA_MASTER_CONFIGURATION_FILE_NAME, KPA_MASTER_CONFIGURATION_FILE_FOLDER))  )
     
{
         printf
("KPALoadConfiguration Error[0 x%04 X]  (%s)  File[%s%s]  \n",  
                             iResult
, get_error_message(iResult), KPA_MASTER_CONFIGURATION_FILE_FOLDER, KPA_MASTER_CONFIGURATION_FILE_NAME);
         
goto finish;
     
}
     
else
     
{
         printf
("KPALoadConfiguration...  OK\n");
     
}
 
     
//ÇÁ·Î¼¼½º À̹ÌÁö »çÀÌÁî Ãëµæ
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnGetProcessImageSize)(hMaster, &wInputByteSize, &wOutputByteSize))  )
     
{
         printf
("EcatGetProcessImageSize Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatGetProcessImageSize...  OK input=%d(bytes) output=%d(bytes)\n", wInputByteSize, wOutputByteSize );
     
}
 
     
//¾Æ¸£¹ÙÀÌÆ® »çÀÌÁî-->ºñÆ® »çÀÌÁî º¯È¯
     
EcatTaskData.wInputBitSize = wInputByteSize * 8;
     
EcatTaskData.wOutputBitSize = wOutputByteSize * 8;
 
     
//¸Þ¸ð¸® È®º¸ ÀÔ·Â µ¥ÀÌÅÍ
     
EcatTaskData.pbyInData = fnSetMemory( wInputByteSize, "EcatInData", "EtherCAT InData" );
     
if( EcatTaskData.pbyInData == NULL)
     
{
         printf
("fnSetMemory Error pbyInData\n");
         
goto finish;
     
}
     
else
     
{
         printf
("Allocate EcatInData Memory...  OK\n");
     
}
 
     
//¸Þ¸ð¸® È®º¸ Ãâ·Â µ¥ÀÌÅÍ
     
EcatTaskData.pbyOutData = fnSetMemory( wOutputByteSize, "EcatOutData", "EtherCAT OutData" );
     
if( EcatTaskData.pbyOutData == NULL)
     
{
         printf
("fnSetMemory Error pbyOutData\n");
         
goto finish;
     
}
     
else
     
{
         printf
("Allocate EcatOutData Memory...  OK\n");
     
}
 
 
     
// Callback ÇÔ¼ö µî·Ï
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnSetExtCtrlTaskHandler)(hMaster, ctrltask_handler, &EcatTaskData))  )
     
{
         printf
("EcatSetExtCtrlTaskHandler Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatSetExtCtrlTaskHandler...  OK\n");
     
}
 
     
//¸¶½ºÅÍ »çÀÌŬ¸¯ Åë½Å °³½Ã
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnStartCyclicOperation)(hMaster, MASTER_CYCLETIME, 0, ECAT_MASTER_BASE_PRIORITY))  )
     
{
         printf
("EcatStartCyclicOperation Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatStartCyclicOperation...  OK %d(ms)\n", MASTER_CYCLETIME);
     
}
 
     
//¸¶½ºÅÍ »óÅ ¿ä±¸
     byReqState
= EcatStateO;     // Operational
     
if ( ECAT_FAILED(iResult = (*s_Api.pfnRequestMasterState)(hMaster, byReqState))  )
     
{
         
(*s_Api.pfnSetAutoRecoveryTimeout)(hMaster, MASTER_CYCLETIME * 4 / 1000);
         printf
("EcatRequestMasterState Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
goto finish;
     
}
     
else
     
{
         printf
("EcatRequestMasterState state:  %s... \n", GetStateString(byReqState));
     
}
 
     nWait
= 10;
     
do
     
{
         
RtSleep(200);
         
//¸¶½ºÅÍ »óÅ üũ
         
if ( ECAT_FAILED(iResult = (*s_Api.pfnGetMasterState)(hMaster, &byState))  )
         
{
             printf
("EcatGetMasterState Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
             
goto finish;
         
}
 
         printf
("Master state:  %s\n", GetStateString(byState));
         
if(byState == byReqState)
             
break;
     
}
     
while (--nWait > 0);
 
 
     
// DI½º·¹µå »ý¼º(iWin32API·Î »ý¼º)
     hDiThread
= CreateThread(0, 0, (LPTHREAD_START_ROUTINE) EcatDi, (LPVOID)&EcatTaskData, 0, 0);
     
if(hDiThread ! = NULL)
     
{
         
//priorityÄ¡ ¼³Á¤ Iwin32 priority -8 = INtime priority 225
         
SetThreadPriority(hDiThread, -8);
     
}
 
     
// DO½º·¹µå »ý¼º(iWin32API·Î »ý¼º)
     hDoThread
= CreateThread(0, 0, (LPTHREAD_START_ROUTINE) EcatDo, (LPVOID)&EcatTaskData, 0, 0);
     
if(hDoThread ! = NULL)
     
{
         
//priorityÄ¡ ¼³Á¤ Iwin32 priority -12 = INtime priority 241
         
SetThreadPriority(hDoThread, -12);
     
}
 
     printf
("Press Enter to exit ->\n");
     getchar
();
 
 finish
:
     
if( hMaster ! = ECAT_NULL)
     
{
         
// Callback ÇÔ¼ö ¸®¼ÂÆ®
         
if ( ECAT_FAILED(iResult = (*s_Api.pfnResetExtCtrlTaskHandler)(hMaster))  )
         
{
             printf
("EcatResetExtCtrlTaskHandler Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
}
 
         
//¸¶½ºÅÍ »çÀÌŬ¸¯ Åë½Å Á¤Áö
         
if ( ECAT_FAILED(iResult = (*s_Api.pfnStopCyclicOperation)(hMaster))  )
         
{
             printf
("EcatStopCyclicOperation Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
}
 
         
//¸¶½ºÅÍ Àý´Ü
         
if ( ECAT_FAILED(iResult = (*s_Api.pfnDisconnectMaster)(hMaster))  )
         
{
             printf
("EcatDisconnectMaster Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
}
 
         
//¸¶½ºÅÍ ÇØ¹æ
         
if ( ECAT_FAILED(iResult = (*s_Api.pfnFreeMaster)(hMaster))  )
         
{
             printf
("EcatFreeMaster Error[0 x%04 X]  (%s)\n", iResult, get_error_message(iResult));
         
}
     
}
 
     printf
("KPAEcatSample End\n");
 
}

 


HOME | INtime