industrialNETworXnetx

DrunkenHero

DrunkenHero

| 18.12.2009 | 10:50 | 27 replies

Open Class 1 Connection

Hi ,

I have a CIFX 50 RE as master and a slave, the used protocoll is Ethernet IP.

Now I want to open a Class 1 Connection with two assemblys (100,101).
But in the documentation of the EIP Scanner Protocoll I just found a way to open a
Class 3 connection (EtherNetIP Scanner Protocol API.pdf,page147).
Can somebody help me?

Regards
C.Huiskens

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 18.12.2009 | 15:01

Hi,

the Hilscher stack does not support Class 1 connections.
Only Class 0 / 3.

To open a Class 0 connection you have to perform a EIP_OBJECT_REGISTER_CONNECTION_REQ/CNF.

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 14.07.2010 | 11:33

Hi,

I'm also working with this card and would like
to know whether Class1 connections are now supported. Could you tell me how to open a Class1 connection using the cifx32DLL? I tried using EIP_OBJECT_CM_PACKET_OPEN_CONN_REQ_T but the API always returns TLR_E_EIP_OBJECT_UNKNOWN_CONNECTION.

Regards!

Here is my code:

CIFX_PACKET sCnReq = {0};
CIFX_PACKET sCnRsp = {0};
EIP_OBJECT_CM_PACKET_OPEN_CONN_REQ_T* psCnReq = (EIP_OBJECT_CM_PACKET_OPEN_CONN_REQ_T*) &sCnReq;
EIP_OBJECT_CM_PACKET_OPEN_CONN_CNF_T* psCnRsp = (EIP_OBJECT_CM_PACKET_OPEN_CONN_CNF_T*) &sCnRsp;
char pbString[100] = {0};
unsigned char* pbData;
char pbIpAddr[25] = {0};

unsigned char pbCnPath[] = {
0x34, /* Key segment */
0x04, /* Key format */
0x00, 0x00, /* VendorID */
0x00, 0x00, /* Device type */
0x00, 0x00, /* Product code */
0x00, 0x00, /* Major/Minor revision (Compatibility bit: 7 of major) */
0x20, 0x04, /* Logical class segment, class assembly */
0x24, 0x01, /* Logical instance segment */
0x2C, 0x64, /* Logical connection point segment */
0x2C, 0x74 /* Logical connection point segment */
};

sprintf(pbIpAddr, "%d.%d.%d.%d",
(0xC0A86407 >> 24) & 0xFF,
(0xC0A86407 >> 16) & 0xFF,
(0xC0A86407 >> 8) & 0xFF,
(0xC0A86407 & 0xFF));

// Fill packet header content
psCnReq->tHead.ulDest = RCX_PKT_COMM_CHANNEL_TOKEN;
psCnReq->tHead.ulSrc = 0;
psCnReq->tHead.ulDestId = 0;
psCnReq->tHead.ulSrcId = 0;
psCnReq->tHead.ulLen = (TLR_UINT32) (EIP_OBJECT_CM_OPEN_CONN_REQ_SIZE
+ sizeof(pbCnPath) + strlen(pbIpAddr));
psCnReq->tHead.ulId = 0xFFBB0000;
psCnReq->tHead.ulSta = 0;
psCnReq->tHead.ulCmd = EIP_OBJECT_CM_CLOSE_CONN_REQ;

// Fill CIP packet content
psCnReq->tData.ulConnectionSn = 0x01;
psCnReq->tData.ulTimeoutMult = 6;
psCnReq->tData.ulClassTrigger = 0x01;
psCnReq->tData.ulProRpi = 10000;
psCnReq->tData.ulProParams = 0x4808;
psCnReq->tData.ulConRpi = 10000;
psCnReq->tData.ulConParams = 0x2804;

pbData = &sCnReq.abData[0];
pbData += EIP_OBJECT_CM_OPEN_CONN_REQ_SIZE;

psCnReq->tData.ulHostDestSize = (TLR_UINT32) strlen(pbIpAddr);
psCnReq->tData.ulHostDestOffs = (TLR_UINT32) (pbData - &sCnReq.abData[0]);
memcpy(pbData, pbIpAddr, psCnReq->tData.ulHostDestSize);
pbData += psCnReq->tData.ulHostDestSize;

psCnReq->tData.ulPort = 0;
psCnReq->tData.ulOpenPathSize = sizeof(pbCnPath) / 2;
psCnReq->tData.ulClosePathSize = sizeof(pbCnPath) / 2;
psCnReq->tData.ulPathOffs = (TLR_UINT32) (pbData - &sCnReq.abData[0]);
memcpy(pbData, pbCnPath, sizeof(pbCnPath));
pbData += sizeof(pbCnPath);

psCnReq->tData.ulProConnPoint = 0x74;
psCnReq->tData.ulConConnPoint = 0x64;

dwRet = xChannelPutPacket(phChnHdl, &sCnReq, 1000);
dwRet = xChannelGetPacket(phChnHdl, sizeof(sCnRsp), &sCnRsp, 1000);
Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 14.07.2010 | 15:39

Hi,

the problem is, that the command does not match to the used package.

Please use "EIP_OBJECT_REGISTER_CONNECTION_REQ/CNF"

Regards
AJ

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 19.07.2010 | 19:07

Hi AJ,

that was a dumb error from my side, sorry!

Now I opened a Class1 connection and see the traffic on the wire. But I'm not able to write nor read data from and to the I/O segment from scanner side. The error 0x800C0021 is returned (COM-flag not set).

What requirements to the connection settings do I have to fulfill in order to successfully communicate with the target device in both directions? What is the source of the COM-flag error? I mean, both devices (the scanner and the adapter) are sending Class1 messages cyclically but I'm not able to write data from the scanner!

Hope you can help me!

Regards,
dlickay

p.s. I opened the connection using EIP_OBJECT_CM_OPEN_CONN_REQ because EIP_OBJECT_REGISTER_CONNECTION_REQ always returns 0xC0000124 (TLR_E_PARAMETER_ERROR) either using the same parameters as with EIP_OBJECT_CM_OPEN_CONN_REQ!

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 21.07.2010 | 08:46

Hi dlickay,

the function "EIP_OBJECT_CM_OPEN_CONN_REQ" is not the right choice. With this function you did not get the information if a connection is established. This works only for registered connections.

Regards
AJ

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 22.07.2010 | 17:23

Hi AJ,

okay, so you mean I should use EIP_OBJECT_REGISTER_CONNECTION_REQ. Using this packet I always get the error 0xC0000124 (TLR_E_PARAMETER_ERROR). I think the problem are the usImpDefLen, bImpDefSize and abImpDef fields. What do they stand for? The EtherNet/IP Protocol API do not realy describe how to fill them. Can you take a look at this code and maybe you find my error!

Thanks!

How do I close this connection? Which packet should I take?

CIFX_PACKET sCnReq = {0};
CIFX_PACKET sCnRsp = {0};
EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T* psCnReq = NULL;
EIP_OBJECT_PACKET_REGISTER_CONNECTION_CNF_T* psCnRsp = NULL;
unsigned char* pbData;

psCnReq = (EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T*) &sCnReq;
psCnRsp = (EIP_OBJECT_PACKET_REGISTER_CONNECTION_CNF_T*) &sCnRsp;

unsigned char pbCnPath[] = {
0x34, /* Key segment */
0x04, /* Key format */
0x64, 0x00, /* VendorID */
0x0C, 0x00, /* Device type */
0xab, 0xab, /* Product code */
0x01, 0x02, /* Major/Minor revision (Compatibility bit: 7 of major) */
0x20, 0x04, /* Logical class segment, class assembly */
0x24, 0x01, /* Logical instance segment */
0x2C, 0x64, /* Logical connection point segment */
0x2C, 0x74 /* Logical connection point segment */
};

// Fill packet header content
psCnReq->tHead.ulDest = RCX_PKT_COMM_CHANNEL_TOKEN;
psCnReq->tHead.ulSrc = 0;
psCnReq->tHead.ulDestId = 0;
psCnReq->tHead.ulSrcId = 0;
psCnReq->tHead.ulLen = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE + sizeof(pbCnPath);
psCnReq->tHead.ulId = 0x001;
psCnReq->tHead.ulSta = 0;
psCnReq->tHead.ulCmd = EIP_OBJECT_REGISTER_CONNECTION_REQ;

pbData = &sCnReq.abData[0];
pbData += EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE;

psCnReq->tData.usConnectionFlags = (2 << 4);
psCnReq->tData.usVendorID = 0x64;
psCnReq->tData.usProductType = 0x0c;
psCnReq->tData.usProductCode = 0xabab;
psCnReq->tData.bMinRev = 2;
psCnReq->tData.bMajRev = 1;
psCnReq->tData.bConnMultiplier = 6;
psCnReq->tData.bClassTrigger = 0x01;
psCnReq->tData.ulRpiOT = 100000;
psCnReq->tData.usNetParamOT = 0x4808;
psCnReq->tData.ulRpiTO = 100000;
psCnReq->tData.usNetParamTO = 0x4808;
psCnReq->tData.bOpenPathSize = sizeof(pbCnPath) / 2;
psCnReq->tData.ulPathOffset = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE;

psCnReq->tData.ulConnHandle = 0x12345678;
memcpy(&psCnReq->tData.abConnName[0], "CONN1", sizeof("CONN1"));
psCnReq->tData.bNameSize = sizeof("CONN1") / 2;
psCnReq->tData.usConnNameLen = sizeof("CONN1");

memcpy(pbData, pbCnPath, sizeof(pbCnPath));
vinay

vinay

| 03.08.2010 | 11:19

Hi

Hi AJ,

I used following code to register the connection with assembly instance 100 & 150 but getting error com-flag not set.. i think my parameters are not set properly. can anybody guide me?

struct

{

EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T tPacket;

 

unsigned char abData[1600 - sizeof

(EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T)];

} tPkt;

 

unsigned long

ulErr;

 

unsigned char

abPath[] = {

 

/* Port Segment IP Address 192.168.00.2 */

0x12, 0x0C, 0x31, 0x39, 0x32, 0x2E, 0x31, 0x36, 0x38, 0x2E, 0x30, 0x30, 0x2E, 0x32,

 

/* electrical key */

 

/*0x34, 0x04, 0x1B, 0x01, 0x0C, 0x00, 0x01, 0x10, 0x01, 0x01,*/

 

0x34, 0x04, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00,

 

 

/* connection path */

0x20, 0x04, 0x24, 0x01, 0x2C, 0x96, 0x2C, 0x64};

// I/P instance 150(96) & O/P instance 100(64)

 

tPkt.tPacket.tHead.ulSrc = (UINT32)0x10;

tPkt.tPacket.tHead.ulSrcId = 0;

tPkt.tPacket.tHead.ulDest = (UINT32)0x20;

tPkt.tPacket.tHead.ulDestId = 0;

tPkt.tPacket.tHead.ulSta = 0;

tPkt.tPacket.tHead.ulCmd = EIP_OBJECT_REGISTER_CONNECTION_REQ;

tPkt.tPacket.tHead.ulId = 1;

tPkt.tPacket.tHead.ulExt = 0;

 

/* connection Handle = unical number given by configuration software */

tPkt.tPacket.tData.ulConnHandle = atChannel[USED_EIMCFG_CHANNEL].hChannel;

//0x12345678;

 

/* Values can set to 0 are reserved at the moment */

tPkt.tPacket.tData.bGeneralStatus = 0x00;

tPkt.tPacket.tData.bReserved1 = 0x00;

tPkt.tPacket.tData.usExtendedStatus = 0x0000;

tPkt.tPacket.tData.usConnectionFlags = 0x0000;

 

/* Device Data of Adapter */

tPkt.tPacket.tData.usVendorID = 0x011B;

tPkt.tPacket.tData.usProductType = 0x000C;

tPkt.tPacket.tData.usProductCode = 0x0101;

tPkt.tPacket.tData.bMinRev = 0x01;

tPkt.tPacket.tData.bMajRev = 0x01;

 

/* not used */

tPkt.tPacket.tData.ulCSDataIdx = 0x00000000;

tPkt.tPacket.tData.bConnMultiplier = 0x03;

tPkt.tPacket.tData.bClassTrigger = 0x81;

tPkt.tPacket.tData.ulRpiOT = 1000;

//max its 3 sec

tPkt.tPacket.tData.usNetParamOT = 0x4804;

tPkt.tPacket.tData.ulRpiTO = 1000;

tPkt.tPacket.tData.usNetParamTO = 0x2804;

//max its 3 sec

tPkt.tPacket.tData.bOpenPathSize = 0x10;

//instead of 0x10

tPkt.tPacket.tData.bReserved2 = 0;

tPkt.tPacket.tData.ulPathOffset = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE;

tPkt.tPacket.tData.usConfig1Size = 0;

tPkt.tPacket.tData.ulConfig1Offset = 0;

tPkt.tPacket.tData.bNameSize = 0x08;

tPkt.tPacket.tData.bReserved3 = 0x00;

tPkt.tPacket.tData.usConnNameLen = 0x0008;

memcpy(&tPkt.tPacket.tData.abConnName[0],

"Connect1"

,8);

tPkt.tPacket.tData.usFormatNumber = 0x0001;

tPkt.tPacket.tData.bImpDefSize = 0x10;

tPkt.tPacket.tData.usImpDefLen = 0x0010;

 

 

/* Data of the connection are mapped into assemblies of the scanner */

 

tPkt.tPacket.tData.abImpDef[0] = 100;

tPkt.tPacket.tData.abImpDef[1] = 0;

tPkt.tPacket.tData.abImpDef[2] = 0;

tPkt.tPacket.tData.abImpDef[3] = 0;

tPkt.tPacket.tData.abImpDef[4] = 0;

tPkt.tPacket.tData.abImpDef[5] = 0;

tPkt.tPacket.tData.abImpDef[6] = 0;

tPkt.tPacket.tData.abImpDef[7] = 0;

tPkt.tPacket.tData.abImpDef[8] = 150;

tPkt.tPacket.tData.abImpDef[9] = 0;

tPkt.tPacket.tData.abImpDef[10] = 0;

tPkt.tPacket.tData.abImpDef[11] = 0;

tPkt.tPacket.tData.abImpDef[12] = 0;

tPkt.tPacket.tData.abImpDef[13] = 0;

tPkt.tPacket.tData.abImpDef[14] = 0;

tPkt.tPacket.tData.abImpDef[15] = 0;

 

 

tPkt.tPacket.tData.usConfig2Size = 0x0000;

tPkt.tPacket.tData.ulConfig2Offset = 0x00000000;

 

/* reserved shall be 0 */

tPkt.tPacket.tData.usProxyVendorID = 0x0000;

tPkt.tPacket.tData.usProxyProductType = 0x0000;

tPkt.tPacket.tData.usProxyProductCode = 0x0000;

tPkt.tPacket.tData.bProxyMinRev = 0x00;

tPkt.tPacket.tData.bProxyMajRev = 0x00;

 

memcpy(&tPkt.abData[0], &abPath[0],

sizeof

(abPath));

tPkt.tPacket.tHead.ulLen = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE +

(tPkt.tPacket.tData.bOpenPathSize << 1) +

tPkt.tPacket.tData.usConfig1Size +

tPkt.tPacket.tData.usConfig2Size;

ulErr = xChannelPutPacket( atChannel[USED_EIMCFG_CHANNEL].hChannel, (CIFX_PACKET*)&tPkt.tPacket, 0);

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 03.08.2010 | 12:51

Hi vinay,

I think there is a problem in your used package. I compared your code with the one I have and it is at some parts different (no I do not mean the IP-Address ;-) )

Please compare my code snippet with yours.

void EIMCFG_RegisterConnection1 ( void )
{
  struct {
    EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T tPacket;
    unsigned char abData[1600 - sizeof(EIP_OBJECT_PACKET_REGISTER_CONNECTION_REQ_T)];
  } tPkt;
  unsigned long ulErr;
  unsigned char abPath[] = {
    /* Port Segment IP Address 192.168.10.2 */
    0x12, 0x0C, 0x31, 0x39, 0x32, 0x2E, 0x31, 0x36, 0x38, 0x2E, 0x31, 0x30, 0x2E, 0x32,
    /* electrical key */
    0x34, 0x04, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00,
    /* connection path */
    0x20, 0x04, 0x24, 0x01, 0x2C, 0x64, 0x2C, 0x65};



  tPkt.tPacket.tHead.ulSrc = (UINT32)0x10;
  tPkt.tPacket.tHead.ulSrcId = 0;
  tPkt.tPacket.tHead.ulDest = (UINT32)0x20;
  tPkt.tPacket.tHead.ulDestId = 0;
  tPkt.tPacket.tHead.ulSta = 0;
  tPkt.tPacket.tHead.ulCmd = EIP_OBJECT_REGISTER_CONNECTION_REQ;
  tPkt.tPacket.tHead.ulId  = 1;
  tPkt.tPacket.tHead.ulExt  = 0;

  /* connection Handle = unical number given by configuration software */
  tPkt.tPacket.tData.ulConnHandle = 1;
  /* Values can set to 0 are reserved at the moment */ 
  tPkt.tPacket.tData.bGeneralStatus                      = 0x00;
  tPkt.tPacket.tData.bReserved1                          = 0x00;
  tPkt.tPacket.tData.usExtendedStatus                    = 0x0000;
  tPkt.tPacket.tData.usConnectionFlags                   = 0x0000;

  /* Device Data of Adapter */
  tPkt.tPacket.tData.usVendorID                          = 0x011B;     
  tPkt.tPacket.tData.usProductType                       = 0x000C;
  tPkt.tPacket.tData.usProductCode                       = 0x0101;
  tPkt.tPacket.tData.bMinRev                             = 0x01;
  tPkt.tPacket.tData.bMajRev                             = 0x01;
  /* not used */
  tPkt.tPacket.tData.ulCSDataIdx                         = 0x00000000;
  tPkt.tPacket.tData.bConnMultiplier                     = 0x03;
  tPkt.tPacket.tData.bClassTrigger                       = 0x01;
  tPkt.tPacket.tData.ulRpiOT                             = 0x000186A0;
  tPkt.tPacket.tData.usNetParamOT                        = 0x4826;
  tPkt.tPacket.tData.ulRpiTO                             = 0x000186A0;
  tPkt.tPacket.tData.usNetParamTO                        = 0x2826;
  tPkt.tPacket.tData.bOpenPathSize                       = 0x10;
  tPkt.tPacket.tData.bReserved2                          = 0;
  tPkt.tPacket.tData.ulPathOffset                        = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE;
  tPkt.tPacket.tData.usConfig1Size                       = 0;
  tPkt.tPacket.tData.ulConfig1Offset                     = 0;
  tPkt.tPacket.tData.bNameSize                           = 0x08;
  tPkt.tPacket.tData.bReserved3                          = 0x00;
  tPkt.tPacket.tData.usConnNameLen                       = 0x0008; 
  memcpy(&tPkt.tPacket.tData.abConnName[0], "Connect1",8);
  tPkt.tPacket.tData.usFormatNumber                      = 0x0001;
  tPkt.tPacket.tData.bImpDefSize                         = 0x10;
  tPkt.tPacket.tData.usImpDefLen                         = 0x0010;
 
  /* Data of the connection are mapped into assemblies of the scanner */
  ((EIP_CC_USER_ATTR_DATA_T*)&tPkt.tPacket.tData.abImpDef[0])->ulInstanceOT = 101;
  ((EIP_CC_USER_ATTR_DATA_T*)&tPkt.tPacket.tData.abImpDef[0])->ulInstanceTO = 100;
  tPkt.tPacket.tData.usConfig2Size                       = 0x0000;
  tPkt.tPacket.tData.ulConfig2Offset                     = 0x00000000;
  /* reserved shall be 0 */
  tPkt.tPacket.tData.usProxyVendorID                     = 0x0000;
  tPkt.tPacket.tData.usProxyProductType                  = 0x0000;
  tPkt.tPacket.tData.usProxyProductCode                  = 0x0000;
  tPkt.tPacket.tData.bProxyMinRev                        = 0x00;
  tPkt.tPacket.tData.bProxyMajRev                        = 0x00;
 
  memcpy(&tPkt.abData[0], &abPath[0], sizeof(abPath));

  tPkt.tPacket.tHead.ulLen = EIP_OBJECT_REGISTER_CONNECTION_REQ_SIZE +
                                                  (tPkt.tPacket.tData.bOpenPathSize << 1) +
                                                  tPkt.tPacket.tData.usConfig1Size +
                                                  tPkt.tPacket.tData.usConfig2Size;
  ulErr = xChannelPutPacket( atChannel[USED_EIMCFG_CHANNEL].hChannel, (CIFX_PACKET*)&tPkt.tPacket, 0); 
}

Regards
AJ

vinay

vinay

| 10.08.2010 | 11:32

AJ can you tell me about the parameter below! what should be the unical number given?

 

 

/* connection Handle = unical number given by configuration software */

 

tPkt.tPacket.tData.ulConnHandle =atChannel[bChannel].hChannel;

 

 

should this handle be the same as u get at the time of opening a channel? as shown below:

 

ulErr = xChannelOpen ( hDriver, uBoardInfo.tBoardInfo.abBoardName, bChannel, &atChannel[bChannel].hChannel);//handle (atChannel[bChannel].hChannel)

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 10.08.2010 | 11:36

Hi vinay,

for ulConnHandle you can try "2".

 

Regards
AJ

vinay

vinay

| 03.09.2010 | 08:25

with the help of EIP_OBJECT_REGISTER_CONNECTION_REQ/CNF-1A34 I have open class 1 cyclic connection. how to close the connection I have tried using EIP_OBJECT_CM_CLOSE_CONN_REQ/CNF – Close a Connection. But once i reopen or re-register the cyclic connection i'm getting error 0xC00000124. Can anyone tell me

how to close class 1 cyclic connection or unregister the connection?

thanks in advance

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 03.09.2010 | 10:34

Hi vinay,

actually you're doing the right things.

Just try using another value for ulConnHandle when re-registering the connection with EIP_OBJECT_REGISTER_CONNECTION_REQ.

 

 

vinay

vinay

| 06.09.2010 | 10:41

Hi kail,

 thanks for your response.. but there seems some issue my close connection request is successfull but as soon as i turn the BUS state to ON. the connection is reesatblished again. I dont know why this happens!!

My concern is I have opened cyclic connection with cmd 1A34 & now want to close that connection.

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 07.09.2010 | 08:50

Hi vinay,

Once a connection is registered it stays registered until a reset (ChannelInit or SystemStart) is performed.
Maybe this is the way you want to go.

Regards,
Kai

vinay

vinay

| 07.09.2010 | 11:54

Hi Kai,

Our requirement is to close the connection and re register new connection next time when required. if not could you please share me the sample code for opening class 1 cyclic connection using cmd 1A0E? actually the EIP protocol document gives an example but when i execute the command the hilscher card goes into hang state, the sys LED turns yellow (static).

your inputs would be highly appreciable.

regards,

vinay

 

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 08.09.2010 | 17:22

Hi Vinay,

here comes some code for you. Hope this is helpfull.
It consists of functions to perform basic configuration and to handle the Class 1 connection.

I additionally provide the configuration functions since I tested with them and got it to work, though.

This is the order I chose for the initial configuration:

EIMPF_RegisterAssembly ( 0x80000001, 32, 1000);
EIMPF_RegisterAssembly ( 0x80000002, 32, 1000);
EIMPF_SetDeviceInfo();
EIMPF_SetTcpConfig();

 Then you should be able to start and stop the connection using the functions

EIMPF_OpenConnection()

and

EIMPF_CloseConnection().

 

And now the rest of the code:

void EIMPF_RegisterAssembly ( unsigned long ulInstance, 
                              unsigned long ulSize, 
                              unsigned long ulOffset )
{
  EIP_OBJECT_AS_PACKET_REGISTER_REQ_T tPacket;
 
  tPacket.tHead.ulCmd   = EIP_OBJECT_AS_REGISTER_REQ;
  tPacket.tHead.ulSrc   = (UINT32)0x10;
  tPacket.tHead.ulSrcId  = 0;
  tPacket.tHead.ulDest   = (UINT32)0x20;
  tPacket.tHead.ulDestId  = 0;
  tPacket.tHead.ulSta   = 0;
  tPacket.tHead.ulLen   = EIP_OBJECT_AS_REGISTER_REQ_SIZE;
  tPacket.tHead.ulId    = 0;
  tPacket.tHead.ulExt    = 0;
   
  tPacket.tData.ulInstance = ulInstance;
  tPacket.tData.ulSize = ulSize;
  if (ulInstance & 1)
    tPacket.tData.ulFlags = 0;
  else
    tPacket.tData.ulFlags = EIP_AS_FLAG_READONLY;
  tPacket.tData.ulDPMOffset = ulOffset;
 
  xChannelPutPacket( hChannel, (CIFX_PACKET*)&tPacket, 0); 
}
void EIMPF_SetDeviceInfo(){
  EIP_OBJECT_ID_PACKET_SETDEVICEINFO_REQ_T    tDevPacket;
tDevPacket.tHead.ulCmd    = EIP_OBJECT_ID_SETDEVICEINFO_REQ;
  tDevPacket.tHead.ulSrc    = (UINT32)0x10;
  tDevPacket.tHead.ulDest   = (UINT32)0x20;
  tDevPacket.tHead.ulSrcId  = 0;
  tDevPacket.tHead.ulDestId = 0;
  tDevPacket.tHead.ulSta    = 0;
  tDevPacket.tHead.ulId     = 0;
  tDevPacket.tHead.ulLen    = EIP_OBJECT_ID_SETDEVICEINFO_REQ_SIZE;
     
  tDevPacket.tData.ulVendId         = 283;
  tDevPacket.tData.ulProductType    = 12;
  tDevPacket.tData.ulProductCode    = 0x0102;
  tDevPacket.tData.ulMajRev         = 1;
  tDevPacket.tData.ulMinRev         = 1;
  tDevPacket.tData.ulSerialNumber   = 0;
  tDevPacket.tData.abProductName[0] = 10;
  memcpy(&tDevPacket.tData.abProductName[1],
          "TestDevice",
          tDevPacket.tData.abProductName[0]);
  xChannelPutPacket( hChannel, (CIFX_PACKET*)&tDevPacket, 0); 
}
void EIMPF_SetTcpConfig(){
TCPIP_PACKET_IP_CMD_SET_CONFIG_REQ_T        tTcpPacket;
  unsigned long                               ulFlags = 0;
  tTcpPacket.tHead.ulCmd    = TCPIP_IP_CMD_SET_CONFIG_REQ;
  tTcpPacket.tHead.ulLen    = TCPIP_DATA_IP_CMD_SET_CONFIG_REQ_SIZE;
  tTcpPacket.tHead.ulSrc    = (UINT32)0x10;
  tTcpPacket.tHead.ulDest   = (UINT32)0x20;
  tTcpPacket.tHead.ulDestId = 0;
  tTcpPacket.tHead.ulSrcId  = 0;
  tTcpPacket.tHead.ulSta    = 0;
  tTcpPacket.tHead.ulId     = 0;
  tTcpPacket.tHead.ulRout   = 0;
  tTcpPacket.tHead.ulExt    = 0;
   
  ulFlags = 0;
  ulFlags |= IP_CFG_FLAG_SPEED_100MBIT;
  ulFlags |= IP_CFG_FLAG_AUTO_NEGOTIATE;
  ulFlags |= (IP_CFG_FLAG_IP_ADDR | IP_CFG_FLAG_NET_MASK | IP_CFG_FLAG_GATEWAY);
  tTcpPacket.tData.ulFlags            = ulFlags;
  tTcpPacket.tData.ulIpAddr           = 0xC0A8FD64; // 192.168.253.100
  tTcpPacket.tData.ulNetMask          = 0xFFFFFF00; // 255.255.255.0
  tTcpPacket.tData.ulGateway          = 0xC0A8FD01; // 192.168.253.1
  tTcpPacket.tData.abEthernetAddr[0]  = 0x00;
  tTcpPacket.tData.abEthernetAddr[1]  = 0x02;
  tTcpPacket.tData.abEthernetAddr[2]  = 0x63;
  tTcpPacket.tData.abEthernetAddr[3]  = 0x54;
  tTcpPacket.tData.abEthernetAddr[4]  = 0x45;
  tTcpPacket.tData.abEthernetAddr[5]  = 0x36;
   
  xChannelPutPacket( atChannel[USED_EIMPF_CHANNEL].hChannel, (CIFX_PACKET*)&tTcpPacket, 0); 
}
UINT8 abOpenConnPath[] = { 0x34, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                           0x00, 0x00, 0x20, 0x04, 0x24, 0x01, 0x2C, 0x64,0x2C, 0x65 };
UINT8 abIpAddr[] = "192.168.253.140"; // ip address of the target
void EIMPF_OpenConnection()
{
  EIP_OBJECT_CM_PACKET_OPEN_CONN_REQ_T tCPacket;
  DEFAULT_PACKET_T                     tDPacket;
  UINT32                               ulErr = 0;
  UINT8*                               pbData;
  /* Open Connection */
  tCPacket.tHead.ulCmd    = EIP_OBJECT_CM_OPEN_CONN_REQ;
  tCPacket.tHead.ulSrc    = (UINT32)0x10;
  tCPacket.tHead.ulSrcId  = 0;
  tCPacket.tHead.ulDest   = (UINT32)0x20;
  tCPacket.tHead.ulDestId = 0;
  tCPacket.tHead.ulSta    = 0;
  tCPacket.tHead.ulLen    = EIP_OBJECT_CM_OPEN_CONN_REQ_SIZE + sizeof(abIpAddr) + sizeof(abOpenConnPath);
  tCPacket.tHead.ulId     = 0;
  tCPacket.tHead.ulExt    = 0;
  tCPacket.tData.ulConnectionSn = 1;        /* serial number of the connection */
  tCPacket.tData.ulGRC          = 0;        /* Generic Error Code   */
  tCPacket.tData.ulERC          = 0;        /* Extendet Error Code  */
  /* Connection parameters.   */
  tCPacket.tData.ulTimeoutMult  = 3;
  tCPacket.tData.ulClassTrigger = 1;
  tCPacket.tData.ulProRpi       = 100000;
  tCPacket.tData.ulProParams    = 0x4810   
  tCPacket.tData.ulConRpi       = 100000;
  tCPacket.tData.ulConParams    = 0x2810;

  /* Connection path & module configuration.   */
  tCPacket.tData.ulHostDestSize   = 15;   /* length of the hostname/ip */
  tCPacket.tData.ulHostDestOffs   = sizeof(tCPacket.tData);
  tCPacket.tData.ulProdInhibit    = 1000; /* production inhibit time in ms */
  tCPacket.tData.ulPort           = 2222; // EtherNetIP port
  tCPacket.tData.ulOpenPathSize   = sizeof(abOpenConnPath)/2;
  tCPacket.tData.ulClosePathSize  = sizeof(abOpenConnPath)/2;
  tCPacket.tData.ulPathOffs       = sizeof(tCPacket.tData) + sizeof(abIpAddr);
  tCPacket.tData.ulConfig1Size    = 0;
  tCPacket.tData.ulConfig1Offs    = 0;
  tCPacket.tData.ulConfig2Size    = 0;
  tCPacket.tData.ulConfig2Offs    = 0;
  /* Data mapping information on our side.   */
  tCPacket.tData.ulClass        = 4;
  tCPacket.tData.ulInstance     = 1;
  tCPacket.tData.ulProConnPoint = 0x80000001;
  tCPacket.tData.ulConConnPoint = 0x80000002;
  tCPacket.tData.ulFwdOpenTimeout = 1000;
  /* store packet data into default packet */
  memcpy (&tDPacket, &tCPacket, sizeof(tCPacket));
 
  /* store ip address */
  memcpy(&tDPacket.abData[sizeof(tCPacket)-40], abIpAddr, sizeof(abIpAddr));
  /* store connection path */
  memcpy(&tDPacket.abData[sizeof(tCPacket)-40 + sizeof(abIpAddr)], abOpenConnPath, sizeof(abOpenConnPath));
  ulErr = xChannelPutPacket( atChannel[USED_EIMPF_CHANNEL].hChannel, (CIFX_PACKET*)&tDPacket, 0); 
}
UINT8 abCloseConnPath[] = { 0x34, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x20, 0x04, 0x24, 0x01, 0x2C, 0x64, 0x2C, 0x65 };
void EIMPF_CloseConnection()
{
  EIP_OBJECT_CM_PACKET_CLOSE_CONN_REQ_T  tClosePck;
  DEFAULT_PACKET_T                       tDPacket;
 
  tClosePck.tHead.ulDest           = 0x20;
  tClosePck.tHead.ulCmd            = EIP_OBJECT_CM_CLOSE_CONN_REQ;
  tClosePck.tHead.ulSrc            = 0x10;
  tClosePck.tHead.ulLen            = sizeof(EIP_OBJECT_CM_CLOSE_CONN_REQ_T) + sizeof(abCloseConnPath);
  tClosePck.tData.ulConnectionSn   = 1;
  tClosePck.tData.ulOpenPathSize   = 9;
  tClosePck.tData.ulClosePathSize  = 9;
  tClosePck.tData.ulPathOffs       = sizeof(tClosePck.tData);
  memcpy (&tDPacket, &tClosePck, sizeof(tClosePck));
  memcpy(&tDPacket.abData[sizeof(tClosePck,tData)], abCloseConnPath, sizeof(abCloseConnPath));
  xChannelPutPacket( atChannel[USED_EIMPF_CHANNEL].hChannel, (CIFX_PACKET*)&tDPacket, 0);  
}

 

vinay

vinay

| 09.09.2010 | 14:32

Hi kai,

 Thanks a lot for the inputs 'll get back if needed..

regards

vinay

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 17.09.2010 | 20:24

Hello Kai,

I've now adopted my code to that you posted and I see the Forward-Open request on the wire.
There's one problem remaining, maybe you can help!

I have the following configuration:

  • Scanner (CIFX-50RE):
    - Producing assembly (0x64, 2 bytes + RUN/IDLE)
    - Consuming assembly (0x74, 2 bytes)
  • Adapter (other device):
    - Producing assembly (0x74, 2 bytes)
    - Consuming assembly (0x64, 2 bytes + RUN/IDLE)

Now... I registered these 2 assemblies at the scanner using EIP_OBJECT_AS_PACKET_REGISTER_REQ_T with a size of 2 bytes each. The producing assembly has the EIP_AS_FLAG_RUNIDLE set while the consuming assembly is EIP_AS_FLAG_READONLY.

I've created a packet EIP_OBJECT_CM_PACKET_OPEN_CONN_REQ_T with ulProdParams and ulConParams set to a size of 2, which is the assembly size. Now, the Forward-Open should be opened with a size of 8 for O->T and a size of 4 for T->O. On the wire I see the size I specified in the packet. If I try to set ulProdParams and ulConParams to 8 resp. 4, got the error 0xC01F0012, invalid assembly size. How do you handle this? How do I specify the correct connection size?

Hope you can help!
Regards!

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 20.09.2010 | 14:43

Hi dlickay,

The flag EIP_AS_FLAG_RUNIDLE is used the other way round.
So, registering an assembly with the flag not set would result in a connection size that includes the 4byte.
On the other hand, setting the flag would reject the run/idle header.

Thus, for the producing scanner assembly you should not set the flag,
for the consuming assembly you should set the flag. Vice versa for the adapter.

The parameter ulProdParams and ulConParams should be set to 8 and 4, respectively. 

This should solve your problem.

Regards,
Kai

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 21.09.2010 | 08:53

Hi Kai,

thanks for your answer, is woking now! I'm still getting the CIFX_DEV_NO_COM_FLAG error but data can be exchanged between scanner and adapter. Do you have an idea where this error come from?

Regards,
dlickay

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 21.09.2010 | 12:40

Hi dlickay,

what cifx function are you using? And at what time?
Actually, the communication flag is set once the connection is established.

Regards,
Kai

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 21.09.2010 | 13:09

Hi,

I use xChannelIORead to read and xChannelIOWrite to write data (of course, while connection is open!).
The Class1 Connection is open and Bus-State is ON. It's a little bit strange, because I can write data to the adapter and read new data from the adapter too...

Maybe it has something to do with my SYCON.net configuration. The CIFX is configured as scanner within the configuration. The adapter is not included in this configuration. May this be the source of the error?

Regards,
dlickay

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 21.09.2010 | 14:48

Hi!

No, that shouldn't cause this behaviour. 
Does the "Communication LED" in Sycon's "General Diagnosis" page turn green when the connection is established? This signal is triggered by the COM_FLAG, too. So this might be a good indicator.

Do you read and write data while Sycon is open? If so, try it again while Sycon is closed.

Kai

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 21.09.2010 | 15:35

The LEDs looks as follows:


Sycon is normally closed while communicating. I only need it for the initial configuration of the Scanner!

Regards,
dlickay

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 21.09.2010 | 15:58

What firmware version are you using?

Regards,
Kai

Dennis Lickay

Dennis Lickay

Hirschmann Automation and Control GmbH

| 21.09.2010 | 16:13
  • Firmware

EtherNet/IP Scanner
2.1.19.0 (Build 19)

  • Driver

cifXDriver V1.0.1.0

Kai Michel

Kai Michel

Hilscher Gesellschaft für Systemautomation mbH

| 27.09.2010 | 11:29

Hi dlickay,

I've tried to reproduce the behavior you decribed with the version 2.1.19.0 but everything worked as expected.
At the moment I do not know what exactly could cause this behavior.
The version V2.1.19.0 is actually a pretty old one, so you may want to update to a newer one. It would be interesting whether or not another version behaves the same.

Regards,
Kai

Login