industrialNETworXnetx

houzenan

houzenan

| 26.08.2010 | 06:47 | 10 replies

question on Class 3 connection communication

After opened a Class 3 connection, How to implement non-cyclic communication using this class 3 connection ?

Could you post some codes as example?

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 26.08.2010 | 12:37

Hi houzenan,

Here is some example code:

 

/* 
Open a class 3 connection with request packet interval set to 10 sec
*/
void EIMPF_OpenCl3Connection(void * hChannel, unsigned long aulAdapterIpAddress)
{
  unsigned long ulErr = 0;
  EIP_OBJECT_PACKET_OPEN_CL3_REQ_T tReq;
 
  tReq.tHead.ulSrc = 0x10;
  tReq.tHead.ulDest = 0x20;
  tReq.tHead.ulLen = sizeof(EIP_OBJECT_OPEN_CL3_REQ_T);
  tReq.tHead.ulCmd = EIP_OBJECT_OPEN_CL3_REQ;
  tReq.tHead.ulId = 0;
  tReq.tHead.ulSta = 0;
  tReq.tHead.ulExt = 0;

tReq.tData.ulIPAddr = aulAdapterIpAddress;
  tReq.tData.ulTime = 10000000; /* RPI usec */
  tReq.tData.ulTimeoutMult = 4;
  ulErr = xChannelPutPacket( hChannel, (CIFX_PACKET*)&tReq, 0);
}
/* 
This function processes the confirmation packet of the EIP_OBJECT_OPEN_CL3_REQ packet
*/
unsigned long EIMPF_OpenCl3Connection_Cnf(EIP_OBJECT_PACKET_OPEN_CL3_REQ_T *ptPacket;)
{
  printf( "\n\n Open Connection Cnf: %lx %lx\n", ptPacket->tHead.ulCmd, ptPacket->tHead.ulSta); 
  if (ptPacket->tHead.ulSta == 0)
    ulConnectionHandle = ptPacket->tData.ulConnection;
  return ulConnectionHandle;
}
/* 
Closes the class 3 connection
*/
void EIMPF_CloseCl3Connection(void * hChannel, unsigned long ulConnectionHandle)
{
  unsigned long ulErr = 0;
  EIP_OBJECT_PACKET_CLOSE_CL3_REQ_T tReq;
 
  tReq.tHead.ulSrc = 0x10;
  tReq.tHead.ulDest = 0x20;
  tReq.tHead.ulLen = sizeof(EIP_OBJECT_CLOSE_CL3_REQ_T);
  tReq.tHead.ulCmd = EIP_OBJECT_CLOSE_CL3_REQ;
  tReq.tHead.ulId = 0;
  tReq.tHead.ulSta = 0;
  tReq.tHead.ulExt = 0; 



tReq.tData.ulConnection = ulConnectionHandle;
  ulErr = xChannelPutPacket( hChannel, (CIFX_PACKET*)&tReq, 0);
}
/* Sending class 3 message using the opened connection */
void EIMPF_ConnectedCl3Request(void * hChannel, unsigned long ulConnectionHandle)
{
  unsigned long ulErr = 0;
  EIP_OBJECT_PACKET_CONNECT_MESSAGE_REQ_T tReq;
 
  tReq.tHead.ulSrc = 0x10;
  tReq.tHead.ulDest = 0x20;
  tReq.tHead.ulLen = EIP_OBJECT_CONNECT_MESSAGE_REQ_SIZE;
  tReq.tHead.ulCmd = EIP_OBJECT_CONNECT_MESSAGE_REQ;
  tReq.tHead.ulId = ulIndex;
  tReq.tHead.ulSta = 0;
  tReq.tHead.ulExt = 0;







 
tReq.tData.ulConnection = ulConnectionHandle;
  /* Get Attribute Single of Identity Object Instance 1 Attribute 7 ( Product Name) */
  tReq.tData.bService = 0xE;
  tReq.tData.bReserved =  0;
  tReq.tData.usClass =     1;
  tReq.tData.usInstance =  1;
  tReq.tData.usAttribute = 7;
  ulErr = xChannelPutPacket( hChannel, (CIFX_PACKET*)&tReq, 0);
}

It's important to know that once the class 3 connection is opened (EIMPF_OpenCl3Connection), the class 3 messages (EIMPF_ConnectedCl3Request) need to be sent repeatedly with a maximum interval of the adjusted timeout, which is in this example set to 40 sec ( timeout multiplier is set to 4). Otherwise the connection will be closed automatically.

Hope this helps you. :-)

Kai

hc@jvl.dk

hc@jvl.dk

| 26.08.2010 | 15:44

Hi all

 

I have a different perspective since i am constructing a Adapter, not a scanner. I am using the EIPDemo as a base and my problem is that I have registered a class 3 connection and succeeded in sending data from the scanner to my adapter, but I am not able to construct a response package.

My response package looks like this:

ptRespPck->tHead.ulSrc = (UINT32)0x10;
  ptRespPck->tHead.ulSrcId = 0;
  ptRespPck->tHead.ulDest = (UINT32)0x20;
  ptRespPck->tHead.ulDestId = pvPck->tHead.ulSrcId;
  //ptRespPck->tHead.ulSta = 0;
  ptRespPck->tHead.ulCmd = EIP_OBJECT_CL3_SERVICE_RES;
  ptRespPck->tHead.ulId  = 1;
  ptRespPck->tHead.ulExt  = 0;

  ptRespPck->tData.ulConnectionId = pvPck->tData.ulConnectionId;
  ptRespPck->tData.ulService = pvPck->tData.ulService;
  ptRespPck->tData.ulObject = pvPck->tData.ulObject;
  ptRespPck->tData.ulInstance =  pvPck->tData.ulInstance;
  ptRespPck->tData.ulAttribute =  pvPck->tData.ulAttribute;
  //... GRCC, ERCC error handling NOT IMPLEMENTED
 // ptRespPck->tData.abData[0] = 0xAA;


 //Send response package back
 TLR_QUE_SENDPACKET_FIFO_INTERN((TLR_HANDLE)ptRsc->tRem.hEipObjectQue , ptRespPck, TLR_INFINITE);

 

What am i doing wrong, it seems like I am crashing the class 3 connection and the emulator in Hitop generated an error if i put in a breakpoint.

Thx. in advance.

regards to all.

 

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 26.08.2010 | 17:08

Hi hc@jvl.dk,

It looks like you are not setting the packet length according to your length of data.

Could that be the problem?

Regards,

Kai

houzenan

houzenan

| 26.08.2010 | 18:14

Hi Kai ,

I try to follow your guide by sending packet using sycon.net.   packet from 192.168.0.200 to 192.168.0.210

my project in sycon.net

communication is well ,and IO monitor can do IO data exchange.

Then , I send open connection req packet:

IPAddr:C0(192)A8(168)00(0)D2(210)

Time:0x00989680(10000000)

TimeoutMult: 0x00000004(4)

however, connection failed. could you tell me what's wrong with it ?

 

 

 

 

houzenan

houzenan

| 27.08.2010 | 06:20

I have known the reason.

IPAddr:C0(192)A8(168)00(0)D2(210)   should be d2 00 a8 c0 !

now, I have successfully gotten the connection's handle.  thanks to your code.

However,  when I send the "EIP_OBJECT_PACKET_CONNECT_MESSAGE_REQ" packet .

the sycon.net shows "packet 343: No answer Recieved by device in time ".

and in my adapter's sycon.net ,the packet moniter revieved nothing .

could you do me a favour ?

 

 

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 27.08.2010 | 10:26

Hi houzenan,

This is probably not a problem of the packet or its content.

It seems you used Sycon and another application in parallel. In this case it happens that a confirmation packet is picked up by the wrong application and the other application runs in a timeout with the error you described. 

Just make sure you only use one application to send packets to the EtherNet/IP stack.

 

houzenan

houzenan

| 27.08.2010 | 14:04

i just use sycon.net's packet monitor. first, open connection, second, before connection timeout, send message request.

houzenan

houzenan

| 28.08.2010 | 18:03

Thank you Mr. Kai,

houzenan

houzenan

| 28.08.2010 | 18:04

I have found the problem .

sycon.net is "big-endians". an unsigned long 0x12345678 will be shown as "78 56 34 12" in sycon.net.

I send the wrong packet. What a stupid mistake !  :(

Then, I managed to run the code you give in VS2003, and your code works well !  :)

Thank you , Kai .

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 30.08.2010 | 07:55

houzenan wrote:

sycon.net is "big-endians". an unsigned long 0x12345678 will be shown as "78 56 34 12" in sycon.net.

You are wrong on that one.

SYCON.NET is little-endian, which is proven by your sample.

On Little Endian a DWORD with the value 0x12345678 will be inserted into memory as 78 56 34 12

On Big Endian a DWORD of 0x12345678 will be placed as 12 34 56 78 in memory.

http://wiki.answers.com/Q/What_is_the_difference_between_big_endian_and_little_endian

 

Regards,

MT

Login