Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Apologies for asking stupid question but I am new to the world of networking and Programming so wanted some help
I want to communicate with my sensor which is connected via ethernet/IP. I have established connection but I am unable to send the ASCII setup command. What should I do to send ASCII command and get feedback? I tried doing so by the code given below.

sRN EIIpAddr is the command from device manual. This command when sent via terminal program gives proper feedback(i.e gives the ip of the device)

C++
message = "[STX]sRN EIIpAddr[ETX]"; // Command to be sent
if (send(s, message, strlen(message), 0) < 0)
{
    printf("Send failed");
    return 1;
}
printf("Data Send\n");

if ((recv_size = recv(s, server_reply, 2000, 0)) == SOCKET_ERROR)
{
    printf("recv failed");
}

printf("Reply received\n");


The output that I get is Data send but then I don't receive any feedback.
Posted
Updated 15-Jan-16 23:25pm
v3
Comments
Sergey Alexandrovich Kryukov 15-Jan-16 22:08pm    
Why do you call it "serial"?
The question does not really make any sense. Socket-based networking should include at least two sides. You say nothing about protocols uses and other important detail. This is... just nothing. Perhaps you need to learn some networking, IP protocol stack, some socket API, but forum is not a suitable device for learning from scratch. First, you need to learn some basics to become qualified for using the forum.
—SA
Garth J Lancaster 15-Jan-16 23:01pm    
As SAK says/alludes to, you really need to provide more information on the sensor, what protocols it expects, before you can be helped - that it connects through an ethernet connection is fine, but the sensor likely isnt sending you back anything because it cant interpret what you're sending it

It could be a very simple protocol with commands specified in text/using ascii characters, or it could be something a bit more complex like MODBUS or any other SCADA protocol - the point is, we cant guess that - please edit and update your question

btw : your string "[STX]sRN EIIpAddr[ETX]" - where did you get that from, the manual ? its encouraging that you may have such - but [STX] and [ETX] may 'mean' a special character for example .....

STX and ETX usually refer to ASCII control characters
Control character - Wikipedia, the free encyclopedia[^]
An ASCII control character can't be displayed, thus to show you where to put them, it is a common usage to show them as [STX] and [ETX] but you have to replace them by their ASCII codes.
It means that [STX] must be replaced by a single ASCII character of value 0x02.
It means that [ETX] must be replaced by a single ASCII character of value 0x03.

It is also possible that IpAddr should be replaced by something else. Only sensor documentation will tell you.

It is a good idea to look for tutorials and users forums.
 
Share this answer
 
It seems that you use a sensor described in this PDF document:
Telegrams for Configuring and Operating the LMS1xx, LMS5xx, TiM3xx, JEF300, JEF500[^].

But that describes the communication via a terminal program (serial connection). If the sensor is connected to a serial port, you must use serial communication rather than network functions. See Serial Communications[^] on how to do this.

As already noted in solution 1 and described in the manual, STX and ETX refer to special characters. So the string to be send should look like:
message = "\x02sRN EIIpAddr\x03";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900