Jump to content
OMRON Forums

Ehernet Protocol


SilentLee

Recommended Posts

Hi,

We want to use RTX as host system. According to Ethernet Protocal, we write programs to communicate with clipper through sockets. If we send no-line commands, clipper would do Corresponding action such as "#2j+". But if we send single-line commands, the charcters responsed is null such as "I122". WHY? The programs are as follows:

 

main:

void main()

{

char Cmd_Clear = 18;

char Cmd1[10] = "I122=55";

char Cmd2[10] = "I122";

char *I122str = NULL;

 

 

Cmd[7] = 13; //Add at the end of sending command,

Cmd[4] = 13; //whether add or not ,the result is the same

 

InitPmacEthernet(); //Build connection

 

PmacSockPortSend(Cmd_Clear);

PmacSockSendLine("#2j+"); //Motor2 forward

 

PmacSockGetResponse(Cmd2,I122str);

printf("The original value of I122 is %s\n",I122str);

 

PmacSockGetResponse(Cmd2,I122str);

printf("Now, The value of I122 is %s\n",I122str);

 

Sleep(10000);

ClosePmacEthernet();

}

 

SUBfunction:

int InitPmacEthernet()

{

int Ret;

 

if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)

{

printf("WSAStartup failed with error %d\n", Ret);

return WSA_START_ERROR;

}

 

// Create a new socket to make a client connection.

if ((sock = socket(AF_INET, SOCK_STREAM, 0))

== INVALID_SOCKET)

{

printf("socket failed with error %d\n", WSAGetLastError());

WSACleanup();

return SOCKET_CREATE_ERROR;

}

 

PmacAddr.sin_family = AF_INET;

PmacAddr.sin_port = htons(PMACPORT);

PmacAddr.sin_addr.s_addr = inet_addr(PMACIP);

 

// Make a connection to the server with socket s.

 

printf("We are trying to connect to %s:%d...\n",

inet_ntoa(PmacAddr.sin_addr), htons(PmacAddr.sin_port));

 

if (connect(sock, (SOCKADDR *) &PmacAddr, sizeof(PmacAddr))

== SOCKET_ERROR)

{

printf("connect failed with error %d\n", WSAGetLastError());

closesocket(sock);

WSACleanup();

Sleep(3000);

return CONNECT_ERROR;

}

 

printf("Our connection succeeded.\n");

Sleep(2000);

return 0;

}

int CALLBACK PmacSockGetResponse(char *outstr, char *instr)

{

EthCmd.RequestType = VR_DOWNLOAD;

EthCmd.Request = VR_PMAC_GETRESPONSE;

EthCmd.wValue = 0;

EthCmd.wIndex = 0;

EthCmd.wLength = htons( (WORD)strlen(outstr));

strncpy((char *)&EthCmd.bData[0],outstr,(WORD)strlen(outstr));

 

send(sock,(char*)&EthCmd,ETHERNETCMDSIZE + strlen(outstr),0);

recv(sock,(char*)&instr,1400,0);

return 0;

}

int CALLBACK PmacSockSendLine(char *outstr)

{

EthCmd.RequestType = VR_DOWNLOAD;

EthCmd.Request = VR_PMAC_SENDLINE;

EthCmd.wValue = 0;

EthCmd.wIndex = 0;

EthCmd.wLength = htons( (WORD)strlen(outstr));

strncpy((char *)&EthCmd.bData[0],outstr,(WORD)strlen(outstr));

 

send(sock, (char *)&EthCmd, ETHERNETCMDSIZE + strlen(outstr),0);

recv(sock,(char *)&EthCmd,1,0);

 

return 0;

}

 

The result is:

1.jpg.4544999713c968e7b504cded471637ba.jpg

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

I think you are moving the pointer around instead of just putting data into it.

Should

recv(sock,(char*)&instr,1400,0);

be

recv(sock,(char*)instr,1400,0);

?

 

 

Hi,

We want to use RTX as host system. According to Ethernet Protocal, we write programs to communicate with clipper through sockets. If we send no-line commands, clipper would do Corresponding action such as "#2j+". But if we send single-line commands, the charcters responsed is null such as "I122". WHY? The programs are as follows:

 

main:

void main()

{

char Cmd_Clear = 18;

char Cmd1[10] = "I122=55";

char Cmd2[10] = "I122";

char *I122str = NULL;

 

 

Cmd[7] = 13; //Add at the end of sending command,

Cmd[4] = 13; //whether add or not ,the result is the same

 

InitPmacEthernet(); //Build connection

 

PmacSockPortSend(Cmd_Clear);

PmacSockSendLine("#2j+"); //Motor2 forward

 

PmacSockGetResponse(Cmd2,I122str);

printf("The original value of I122 is %s\n",I122str);

 

PmacSockGetResponse(Cmd2,I122str);

printf("Now, The value of I122 is %s\n",I122str);

 

Sleep(10000);

ClosePmacEthernet();

}

 

SUBfunction:

int InitPmacEthernet()

{

int Ret;

 

if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)

{

printf("WSAStartup failed with error %d\n", Ret);

return WSA_START_ERROR;

}

 

// Create a new socket to make a client connection.

if ((sock = socket(AF_INET, SOCK_STREAM, 0))

== INVALID_SOCKET)

{

printf("socket failed with error %d\n", WSAGetLastError());

WSACleanup();

return SOCKET_CREATE_ERROR;

}

 

PmacAddr.sin_family = AF_INET;

PmacAddr.sin_port = htons(PMACPORT);

PmacAddr.sin_addr.s_addr = inet_addr(PMACIP);

 

// Make a connection to the server with socket s.

 

printf("We are trying to connect to %s:%d...\n",

inet_ntoa(PmacAddr.sin_addr), htons(PmacAddr.sin_port));

 

if (connect(sock, (SOCKADDR *) &PmacAddr, sizeof(PmacAddr))

== SOCKET_ERROR)

{

printf("connect failed with error %d\n", WSAGetLastError());

closesocket(sock);

WSACleanup();recv(sock,(char*)&instr,1400,0);

Sleep(3000);

return CONNECT_ERROR;

}

 

printf("Our connection succeeded.\n");

Sleep(2000);

return 0;

}

int CALLBACK PmacSockGetResponse(char *outstr, char *instr)

{

EthCmd.RequestType = VR_DOWNLOAD;

EthCmd.Request = VR_PMAC_GETRESPONSE;

EthCmd.wValue = 0;

EthCmd.wIndex = 0;

EthCmd.wLength = htons( (WORD)strlen(outstr));

strncpy((char *)&EthCmd.bData[0],outstr,(WORD)strlen(outstr));

 

send(sock,(char*)&EthCmd,ETHERNETCMDSIZE + strlen(outstr),0);

recv(sock,(char*)&instr,1400,0);

return 0;

}

int CALLBACK PmacSockSendLine(char *outstr)

{

EthCmd.RequestType = VR_DOWNLOAD;

EthCmd.Request = VR_PMAC_SENDLINE;

EthCmd.wValue = 0;

EthCmd.wIndex = 0;

EthCmd.wLength = htons( (WORD)strlen(outstr));

strncpy((char *)&EthCmd.bData[0],outstr,(WORD)strlen(outstr));

 

send(sock, (char *)&EthCmd, ETHERNETCMDSIZE + strlen(outstr),0);

recv(sock,(char *)&EthCmd,1,0);

 

return 0;

}

 

The result is:

Link to comment
Share on other sites

I have modificated programs as you advised, but it did not work. Here are the programs, could you help me to find problems?

The header file can't be attached, I have changed it to txt file. Just rename the file.Thanks!

 

I think you are moving the pointer around instead of just putting data into it.

Should

recv(sock,(char*)&instr,1400,0);

be

recv(sock,(char*)instr,1400,0);

?

main.c

pmacethernet1.c

pmacethernet1.txt

Link to comment
Share on other sites

I have modificated programs as you advised, but it did not work. Here are the programs, could you help me to find problems?

The header file can't be attached, I have changed it to txt file. Just rename the file.Thanks!

 

I think you are moving the pointer around instead of just putting data into it.

Should

recv(sock,(char*)&instr,1400,0);

be

recv(sock,(char*)instr,1400,0);

?

 

Go to this forum link.

 

http://forums.deltatau.com/showthread.php?tid=57

 

In the zip file in the pmaceth/src folder is a functioning getresponse.

 

Don't worry that the title is Linux Driver and Comm for Turbo PMAC.zip because ethernet socket communication is very portable.

Link to comment
Share on other sites

I has received the data with the help of wireshark. Thanks

I have modificated programs as you advised, but it did not work. Here are the programs, could you help me to find problems?

The header file can't be attached, I have changed it to txt file. Just rename the file.Thanks!

 

I think you are moving the pointer around instead of just putting data into it.

Should

recv(sock,(char*)&instr,1400,0);

be

recv(sock,(char*)instr,1400,0);

?

 

Go to this forum link.

 

http://forums.deltatau.com/showthread.php?tid=57

 

In the zip file in the pmaceth/src folder is a functioning getresponse.

 

Don't worry that the title is Linux Driver and Comm for Turbo PMAC.zip because ethernet socket communication is very portable.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...