ECS NDIS Example

1 Example project

Use the ECS SimpleConfigExample from our Knowledge Base

KB → Software → LFW Host Examples → EtherCAT Slave

For netX90:


2 ECS Sources

The ECS Sources in the ECS SimpleConfigExample are in the folder:

netXStudio_ECSV5_simpleConfig_V3.0.0.0\netX 90 - EtherCAT Slave - simpleConfig V3.0.0.0\Components\cifXApplicationDemoECS\Sources


3 ECS Sourccode changes

Go to the EoE Guide and do the same changes.

ECS EoE Example

Activate NDIS:

Verify that FDL has 4th MAC address

Change the sourcecode in the file AppSockIF_DemoApplication.c.

Connect your TCP/IP Stack with App_SendEth_FrameReq  and AppEthernet_Recv_Frame. Here an endless while loop sends a frame with random choosen values to the network which can be seen in a trace.

uint32_t Socket_StartConfiguration( APP_DATA_T* ptAppData )
{
	...

    while (1)
    {
    App_SendEth_FrameReq( &ptAppData->aptChannels[SOCK_DEMO_CHANNEL_INDEX]->tPacket );
    ulRet = Pkt_SendReceivePacket( ptAppData, SOCK_DEMO_CHANNEL_INDEX, &ptAppData->aptChannels[SOCK_DEMO_CHANNEL_INDEX]->tPacket, TXRX_TIMEOUT );
    if( ulRet != CIFX_NO_ERROR )
      return ulRet;
	}
	...
	//    AppSock_WaitForInterfaceConfiguration( ptAppData );
	...
	//    ulRet = AppSock_SetupSocket( ptAppData );
}



void App_SendEth_FrameReq( CIFX_PACKET* ptPkt )
{
  ETHERNET_IF_SEND_ETH_FRAME_REQ_T* ptPktSendEth         = (ETHERNET_IF_SEND_ETH_FRAME_REQ_T*)ptPkt;
  memset( &ptPkt->tHeader, 0, sizeof(ptPkt->tHeader));

  ptPktSendEth->tHead.ulDest = HIL_PACKET_DEST_DEFAULT_CHANNEL;
  ptPktSendEth->tHead.ulCmd  = ETHERNET_IF_SEND_ETH_FRAME_REQ;
  ptPktSendEth->tHead.ulLen  = 60;
  ptPktSendEth->tData.abDestMacAddr[0]=0x01;
  ptPktSendEth->tData.abDestMacAddr[1]=0x02;
  ptPktSendEth->tData.abDestMacAddr[2]=0x03;
  ptPktSendEth->tData.abDestMacAddr[3]=0x04;
  ptPktSendEth->tData.abDestMacAddr[4]=0x05;
  ptPktSendEth->tData.abDestMacAddr[5]=0x06;
  ptPktSendEth->tData.abSrcMacAddr[0]=0x03;
  ptPktSendEth->tData.abSrcMacAddr[1]=0x04;
  ptPktSendEth->tData.abSrcMacAddr[2]=0x05;
  ptPktSendEth->tData.abSrcMacAddr[3]=0x06;
  ptPktSendEth->tData.abSrcMacAddr[4]=0x07;
  ptPktSendEth->tData.abSrcMacAddr[5]=0x08;

  ptPktSendEth->tData.abData[6]=0x1;
  ptPktSendEth->tData.abData[7]=0x1;
  ptPktSendEth->tData.abData[8]=0x1;
  ptPktSendEth->tData.abData[9]=0x1;
  ptPktSendEth->tData.abData[10]=0x1;
}

Change the sourcecode in the file AppSockIF_DemoApplicationFunctions.c.

Get Frames for the 4th MAC Address as Indication.

Disable all cases for the Socket functions and add the case for the Ethernet Interface functions.

uint32_t AppEthernet_Recv_Frame(APP_DATA_T *ptAppData, CIFX_PACKET* ptPkt)
{
  //ETHERNET_IF_RECV_ETH_FRAME_IND_T *ptInd = (ETHERNET_IF_RECV_ETH_FRAME_IND_T *) ptPkt;
  ETHERNET_IF_RECV_ETH_FRAME_RSP_T *ptRes = (ETHERNET_IF_RECV_ETH_FRAME_RSP_T *) ptPkt;

  ptRes->tHead.ulCmd   |= 0x01;
  ptRes->tHead.ulLen = 0;
  ptRes->tHead.ulSta = 0;

  Pkt_SendPacket(ptAppData, SOCK_DEMO_CHANNEL_INDEX , ptPkt, TX_TIMEOUT);
  return 0;
}

bool     AppSock_PacketHandler( CIFX_PACKET* ptPacket,  void* pvUserData)
{
...
  switch( ptAppData->aptChannels[SOCK_DEMO_CHANNEL_INDEX]->tPacket.tHeader.ulCmd )
  {
        case ETHERNET_IF_RECV_ETH_FRAME_IND:
          AppEthernet_Recv_Frame(ptAppData, &ptAppData->aptChannels[SOCK_DEMO_CHANNEL_INDEX]->tPacket);

//        case SOCK_CMD_SOCKET_CNF:
// 			...
//          break;
    default:
...
}

With TwinCAT and the new ESI with EoE bring the slave to PreOP. As soon as the salve is in preop, it is possbile to see the ECS Frame from the Ethernet Interface.