examples/CANOpenShell/CANOpenShell.c
changeset 568 84fb13d1b3d2
parent 559 8543e7edae4a
child 605 f91ee161b3a1
equal deleted inserted replaced
567:8c71fdc46735 568:84fb13d1b3d2
    95 int get_info_step = 0;
    95 int get_info_step = 0;
    96 /* Callback function that check the read SDO demand */
    96 /* Callback function that check the read SDO demand */
    97 void CheckReadInfoSDO(CO_Data* d, UNS8 nodeid)
    97 void CheckReadInfoSDO(CO_Data* d, UNS8 nodeid)
    98 {
    98 {
    99 	UNS32 abortCode;
    99 	UNS32 abortCode;
   100 	UNS32 data;
   100 	UNS32 data=0;
   101 	UNS32 size=64;
   101 	UNS32 size=64;
   102 
   102 
   103 	if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != SDO_FINISHED)
   103 	if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != SDO_FINISHED)
   104 		printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
   104 		printf("Master : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
   105 
   105 	else
       
   106 	{
       
   107 		/* Display data received */
       
   108 		switch(get_info_step)
       
   109 		{
       
   110 			case 1:
       
   111 					printf("Device type     : %x\n", data);
       
   112 					break;
       
   113 			case 2:
       
   114 					printf("Vendor ID       : %x\n", data);
       
   115 					break;
       
   116 			case 3:
       
   117 					printf("Product Code    : %x\n", data);
       
   118 					break;
       
   119 			case 4:
       
   120 					printf("Revision Number : %x\n", data);
       
   121 					break;
       
   122 		}
       
   123 	}
   106 	/* Finalize last SDO transfer with this node */
   124 	/* Finalize last SDO transfer with this node */
   107 	closeSDOtransfer(CANOpenShellOD_Data, nodeid, SDO_CLIENT);
   125 	closeSDOtransfer(CANOpenShellOD_Data, nodeid, SDO_CLIENT);
   108 
   126 
   109 	/* Display data received */
       
   110 	switch(get_info_step)
       
   111 	{
       
   112 		case 1:
       
   113 				printf("Device type     : %x\n", data);
       
   114 				break;
       
   115 		case 2:
       
   116 				printf("Vendor ID       : %x\n", data);
       
   117 				break;
       
   118 		case 3:
       
   119 				printf("Product Code    : %x\n", data);
       
   120 				break;
       
   121 		case 4:
       
   122 				printf("Revision Number : %x\n", data);
       
   123 				break;
       
   124 	}
       
   125 	GetSlaveNodeInfo(nodeid);
   127 	GetSlaveNodeInfo(nodeid);
   126 }
   128 }
   127 
   129 
   128 /* Retrieve node informations located at index 0x1000 (Device Type) and 0x1018 (Identity) */
   130 /* Retrieve node informations located at index 0x1000 (Device Type) and 0x1018 (Identity) */
   129 void GetSlaveNodeInfo(UNS8 nodeid)
   131 void GetSlaveNodeInfo(UNS8 nodeid)
   156 
   158 
   157 /* Callback function that check the read SDO demand */
   159 /* Callback function that check the read SDO demand */
   158 void CheckReadSDO(CO_Data* d, UNS8 nodeid)
   160 void CheckReadSDO(CO_Data* d, UNS8 nodeid)
   159 {
   161 {
   160 	UNS32 abortCode;
   162 	UNS32 abortCode;
   161 	UNS32 data;
   163 	UNS32 data=0;
   162 	UNS32 size=64;
   164 	UNS32 size=64;
   163 
   165 
   164 	if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != SDO_FINISHED)
   166 	if(getReadResultNetworkDict(CANOpenShellOD_Data, nodeid, &data, &size, &abortCode) != SDO_FINISHED)
   165 		printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
   167 		printf("\nResult : Failed in getting information for slave %2.2x, AbortCode :%4.4x \n", nodeid, abortCode);
   166 	else
   168 	else
   298 }
   300 }
   299 
   301 
   300 int NodeInit(int NodeID, int NodeType)
   302 int NodeInit(int NodeID, int NodeType)
   301 {
   303 {
   302 	if(NodeType)
   304 	if(NodeType)
   303 	{
       
   304 		CANOpenShellOD_Data = &CANOpenShellMasterOD_Data;
   305 		CANOpenShellOD_Data = &CANOpenShellMasterOD_Data;
   305 	}
   306 	else
   306 	else
       
   307 	{
       
   308 		CANOpenShellOD_Data = &CANOpenShellSlaveOD_Data;
   307 		CANOpenShellOD_Data = &CANOpenShellSlaveOD_Data;
   309 	}
       
   310 
   308 
   311 	/* Load can library */
   309 	/* Load can library */
   312 	LoadCanDriver(LibraryPath);
   310 	LoadCanDriver(LibraryPath);
   313 
   311 
   314 	/* Define callback functions */
   312 	/* Define callback functions */
   472 	printf("Finishing.\n");
   470 	printf("Finishing.\n");
   473 
   471 
   474 	// Stop timer thread
   472 	// Stop timer thread
   475 	StopTimerLoop(&Exit);
   473 	StopTimerLoop(&Exit);
   476 
   474 
       
   475 	/* Close CAN board */
       
   476 	canClose(CANOpenShellOD_Data);
       
   477 
   477 init_fail:
   478 init_fail:
   478 	TimerCleanup();
   479 	TimerCleanup();
   479 	return 0;
   480 	return 0;
   480 }
   481 }
   481 
   482