⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 root.c

📁 SERCOSII卡驱动,通过该驱动程序可以在windowXp与RTX环境下运行自己编写的数控软件实现对数控设备的驱动。
💻 C
字号:
#include "Functions.h"


void 
main( int argc, char *argv[] )
{
	BOOL   bret ;
	DWORD  ret,PROCESSID;

	///////////
	char chName[61],chUnit[10];
	ULONG ulAttribute,ulMin,ulMax,ulData,ulFail;
	USHORT *uspData,usActPhase;
	ULONG *plCommandValue,*plActualValue,*plCommandValue1
		,*plActualValue1,ulLoop,ulRet;
	HANDLE  hSyncData,hMDTChannel,hATChannel,hLifeCounter;
	T_CYC_DATA *pSCycleMDTData,*pSCycleATData;

	//////////

	strcpy( SCS_Task[ROOT].Name, "ROOT");
	SCS_Task[ROOT].TaskID = GetCurrentThreadId();
	SCS_Task[ROOT].TaskHandle = GetCurrentThread();
	SCS_Task[ROOT].Status = STARTED;

	bret = RtSetThreadPriority( SCS_Task[ROOT].TaskHandle,
                              RT_PRIORITY_MAX);
	Init_SHM();
	RtPrintf("SERCANS II Started1\n");
//	PROCESSID = GetCurrentProcessId();
//	TerminateProcess(PROCESSID,0);
	if(SercansInit())
		return;
	create_parameter_handler_tasks();
	start_parameter_handler_tasks();
	get_exist_drives();
	get_nc_serc_cyc();
//read parameter test
/*	ChangePhase(0);
	do
	{
		GetPhase( &usActPhase);
		if(usActPhase == 0) break;
		Sleep(10);
	}while(1);

	CRead_Y_Minimum(4,&ulMin);
	//RtPrintf("chUnit:%s\n",chUnit);
	RtPrintf("ulMin:%d\n",ulMin);

	CRead_Y_Attribute(4,&ulAttribute);
	RtPrintf("Read_Y_Attribute ulAttribute=0x%08x\n",ulAttribute);
	CRead_Y_Parameter(4,&ulData);
	RtPrintf("Read_Y_Parameter ulData=%d\n",ulData);

	ulFail = CRead_Y_Parameter(4,&ulData);
	if (ulFail == 0)
		RtPrintf("Read_Y_Parameter Y4 ulData=0x%08x\n",ulData);
	else
		RtPrintf("Read_Y_Parameter ulFail=0x%08x\n",ulFail);
	ulFail = CRead_Y_Parameter(5,&ulData);
	if (ulFail == 0)
		RtPrintf("Read_Y_Parameter Y5 ulData=0x%08x\n",ulData);
	else
		RtPrintf("Read_Y_Parameter ulFail=0x%08x\n",ulFail);

//	ulFail=Write_Y_Parameter(56,0x393F,FALSE);
//	RtPrintf("Write_Y_Parameter Y56 ulFail=0x%08x\n",ulFail);

	ret = CRead_Y_Parameter(2,&ulData);
	RtPrintf("Read_Y_Parameter ulFail=0x%08x\n",ret);
	if (ret == 0){
		RtPrintf("Read_Y_Parameter Parameter Y2 SVCH_FINISHED *pulData=0x%08x\n",ulData);
		uspData=(USHORT*)ulData;
		RtPrintf("Read_Y_Parameter 2 uspData[0]=0x%08x\n",uspData[0]);
		RtPrintf("Read_Y_Parameter 2 uspData[2]=%d\n",uspData[2]);
		RtPrintf("Read_Y_Parameter 2 uspData[3]=%d\n",uspData[3]);
	}
	else 
		RtPrintf("Read_Y_Parameter FAILED ulFail=0x%08x\n",ret);
	uspData[0]=2;
	uspData[2]=1;
//	uspData[3]=2;


	ulFail=CWrite_Y_Parameter(2,ulData);
	RtPrintf("Write_Y_Parameter ulFail=0x%08x\n",ulFail);

	ulFail = CRead_A_Parameter(7,1,&ulData);
	if (ulFail == 0)
		RtPrintf("Read_A_Parameter Drive1 A7 ulData=%d\n",ulData);
	else
		RtPrintf("Read_A_Parameter Drive1 A7 ulFail=0x%08x\n",ulFail);


	ChangePhase(2);
	do
	{
		GetPhase( &usActPhase);
		if(usActPhase == 2) break;
		Sleep(10);
	}while(1);
	//change position data scaling type to rotary.
	CWrite_S_Parameter(0,76,1,0x42);

	//change opration mode to position
	CWrite_S_Parameter(0,32,1,0xB);

	ulFail = CRead_S_Parameter(0,32,1,&ulData);
	if (ulFail == 0)
		RtPrintf("Read_S_Parameter Drive1 S32 ulData=0x%08x\n",ulData);
	else
		RtPrintf("Read_S_Parameter Drive1 ulFail=0x%08x\n",ulFail);

	ulFail = CRead_P_Name(0,4,1,chName);
	if (ulFail == 0)
		RtPrintf("Read_P_Name Drive1 P4 ulData=%s\n",chName);
	else
		RtPrintf("Read_P_Name Drive1 ulFail=0x%08x\n",ulFail);

	ulFail = CRead_P_Parameter(0,4,1,&ulData);
	if (ulFail == 0)
		RtPrintf("Read_P_Parameter Drive1 P4 ulData=0x%08x\n",ulData);
	else
		RtPrintf("Read_P_Parameter Drive1 ulFail=0x%08x\n",ulFail);


	ChangePhase(4);
	do
	{
		GetPhase( &usActPhase);
		if(usActPhase == 4) break;
		Sleep(10);
	}while(1);
/*
	RtPrintf("main (long*)&ipc_handles.CYCLE_DATA_MDT[1]=%d\n",
		*((long*)&ipc_handles.CYCLE_DATA_AT[0].usData[0]));
	plCommandValue = (long*)&ipc_handles.CYCLE_DATA_MDT[0].usData[0];
	plActualValue = (long*)&ipc_handles.CYCLE_DATA_AT[0].usData[0];

	* plCommandValue = * plActualValue;
	RtPrintf("plActualValue0=%d\n",	*plActualValue);
	while( (ipc_handles.CYCLE_DATA_AT[0].usControl & 0xC000) != 0x8000)
		Sleep(10);
	RtPrintf("plActualValue=%d\n",	*plActualValue);

	ipc_handles.CYCLE_DATA_MDT[0].usControl = 0xE000;
	while( (ipc_handles.CYCLE_DATA_AT[0].usControl & 0xC000) != 0xC000)
		Sleep(10);

	for(ulLoop=0;ulLoop<3600;ulLoop++)
	{
		synch_cycle_data(ipc_handles.REAL_CNL);
		*plCommandValue +=1000;

		trigger_lifecounter(ipc_handles.SOFT_SYNC);
	}
	ipc_handles.CYCLE_DATA_MDT[0].usControl = 0x0000;
*/
//////////////////////////////////////////////////////////
//	by sharemem											//
//////////////////////////////////////////////////////////
  // Init the life-counter function
 /* ulRet=init_lifecounter (&hLifeCounter);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }

  // Init the access to cyclic-data
  ulRet=init_synch (&hSyncData);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }

  // open the cyclic command value channel
  ulRet=open_mdt_channel (&pSCycleMDTData, &hMDTChannel);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }
  
  // open the cyclic actual value channel
  ulRet=open_at_channel (&pSCycleATData, &hATChannel);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }

  // just for an easy access to the first drive parameter S-0-0036
  plCommandValue = (long*)&pSCycleMDTData[0].usData[0];

  // just for an easy access to the first drive parameter S-0-0051
  plActualValue = (long*)&pSCycleATData[0].usData[0];

  // set the command value to the actual value
 
  RtPrintf("plCommandValue =%d\n",*plCommandValue);
  // wait until drive control section ready to operate (drive status word)
  while( (pSCycleATData[0].usControl & 0xC000) != 0x8000 )
    Sleep(10);
  RtPrintf("plCommandValue =%d\n",*plActualValue);
 *plCommandValue = *plActualValue;

  // set drive start / drive enable / drive on 
  // at control word for drive 1
  pSCycleMDTData[0].usControl = 0xE000;
 // RtPrintf("*plCommandValue=%d\n",*plCommandValue);

  // wait until drive is ready (drive status word)
  while( (pSCycleATData[0].usControl & 0xC000) != 0xC000 )
    Sleep(10);


  // Activate live counter 
  ulRet=CWrite_Y_Parameter(9,              // Identnumber Y-0-0009 
										        0);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }

    // set thread priority to max
  RtSetThreadPriority( GetCurrentThread(), RT_PRIORITY_MAX);
  
  // gives a command position from 0 to 360 degree  
  for( ulLoop=0; ulLoop< 3600 ; ulLoop++ )
  {
    // syncronisation to cyclic access
    ulRet=synch_cycle_data (hSyncData);

    // set new value
    *plCommandValue += 1000;

    // Increment the lifecounter
    ulRet=trigger_lifecounter (hLifeCounter);
  }

  // Deactivate live counter 
  ulRet=CWrite_Y_Parameter	(9,							// Identnumber Y-0-0009 
														 0);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }

  // set drive off 
  // at cntrol word for drive 1
  pSCycleMDTData[0].usControl = 0x0000;

  // close the cyclic command value channel
  ulRet=close_mdt_channel (hMDTChannel);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }
 
  // close the cyclic actual value channel
  ulRet=close_at_channel (hATChannel);
  if( ulRet != 0 )
  {
    // see documentation for explanation
    return(-1);
  }
*/
//read parameter test
	RtWaitForSingleObject(ipc_handles.TERMINATE_FLAG,INFINITE);

	TerminateThread(SCS_Task[ROOT].TaskHandle,0);
	
//	SCS_Task[ROOT].Status = SUSPENDED;
//	ret = SuspendThread( GetCurrentThread() );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -