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: