Good evening for everyone,i'm a new user....
I try to send and recieve data from etn21 via tcp with c# code....
with this method i create a new connection:
private static Socket ConnectSocket(string server, int port)
{
Socket s = null;
IPHostEntry hostEntry = null;
hostEntry = Dns.GetHostEntry(server);
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
so return to me an istance of shoket....
after i send to etn21 this command:
fins_tcp_header[0] = 0x46;
fins_tcp_header[1] = 0x49;
fins_tcp_header[2] = 0x4E;
fins_tcp_header[3] = 0x53;
fins_tcp_header[4] = 0x00;/* Length */
fins_tcp_header[5] = 0x00;
fins_tcp_header[6] = 0x00;
fins_tcp_header[7] = 0x0C;
fins_tcp_header[8] = 0x00;/* Command */
fins_tcp_header[9] = 0x00;
fins_tcp_header[10] = 0x00;
fins_tcp_header[11] = 0x00;
fins_tcp_header[12] = 0x00;/* Error Code */
fins_tcp_header[13] = 0x00;
fins_tcp_header[14] = 0x00;
fins_tcp_header[15] = 0x00;
fins_tcp_header[16] = 0x00;
fins_tcp_header[17] = 0x00;/* Client Node Add */
fins_tcp_header[18] = 0x00;
fins_tcp_header[19] = 0x00;
fins_tcp_header[20] = 0x00;/*AUTOMATICALLY GET FINS CLIENT FINS NODE NUMBER*/
s.Send(fins_tcp_header, fins_tcp_header.Length, 0);
do
{
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
cli_node_no = bytesReceived[19];
srv_node_no = bytesReceived[23];
}
and the etn21 response correctly : 80 (server node) and 239 (client node) and the TCP led on module is on
so after i send the command to read 3 DM:
fins_cmnd1[0] = 0x46; //'F';
fins_cmnd1[1] = 0x49; //'I';
fins_cmnd1[2] = 0x4E; //'N';
fins_cmnd1[3] = 0x53; //'S';
fins_cmnd1[4] = 0x00;/* Length */
fins_cmnd1[5] = 0x00;
fins_cmnd1[6] = 0x00;
fins_cmnd1[7] = 0x1A;
fins_cmnd1[8] = 0x00;/* Command */
fins_cmnd1[9] = 0x00;
fins_cmnd1[10] = 0x00;
fins_cmnd1[11] = 0x02;
fins_cmnd1[12] = 0x00;/* Error Code */
fins_cmnd1[13] = 0x00;
fins_cmnd1[14] = 0x00;
fins_cmnd1[15] = 0x00;
fins_cmnd[16] = 0x80; /* ICF */
fins_cmnd[17] = 0x00; /* RSV */
fins_cmnd[18] = 0x03; /* GCT */
fins_cmnd[19] = 0x00; /* DNA */
fins_cmnd[20] = 0x50;//srv_node_no.ToString("x"); /* DA1 */
fins_cmnd[21] = 0x00; /* DA2 */
fins_cmnd[22] = 0x00; /* SNA */
fins_cmnd[23] = 0xEF;//cli_node_no.ToString("x"); /* SA1 */
fins_cmnd[24] = 0x00; /* SA2 */
fins_cmnd[25] = 0x07;//++sid; /* SID */
fins_cmnd[26] = 0x01; /* MRC */
fins_cmnd[27] = 0x01; /* SRC */
fins_cmnd[28] = 0x82;
fins_cmnd[29] = 0x00;
fins_cmnd[30] = 0x01;
fins_cmnd[31] = 0x00;
fins_cmnd[32] = 0x00;
fins_cmnd[33] = 0x03;
s1.Send(fins_cmnd, fins_cmnd.Length, 0);
But here when i execute this command the TCP led on module turn off and the data recieved are incorrect
What i mistake????
Can someone help to me???