Reputation: 9
I need to send and receive some data via an ethernet connection from within a C or C++ program. I suppose I could use some other language like python if that makes it easier. I am working on a Windows XP PC, and while switching to Linux might not be the most convenient thing (it's my work's PC). I guess it's an option.
What I need to do is send some number, let's just say 42 for now, from my computer to a PLC on the other end of the ethernet cable. I know the PLC's IP address and port. I can send and receive data just fine when I enter it by hand into Hyperterminal or Putty. What I would like to do is have the program do this sending and receiving. Sending is all that is necessary, but receiving would be nice too.
So far, I have been trying to send data by using commands in window's command prompt. I figured that if this worked, I could use a system() command from inside the C program to do the job. So far the best I have managed to do is using putty.exe telnet:xxx.xxx.xxx.xxx:yyyy where the x's are the IP address of the PLC and the y's are the port number. This starts up putty with the proper connection to the PLC, but does not send anything. I saw someone suggest using echo 42 | putty.exe telnet:xxx.xxx.xxx.xxx:yyyy, but that just opened the putty connection and didn't send anything. Someone else suggested using net send xxx.xxx.xxx.xxx [message], but that just kept saying that the user name couldn't be found on my domain.
Does anyone have any suggestions on where to go from here? Are there any terminal programs that have commands that let you send data from the command prompt? Are there any commands to send data via putty from the command line? Thanks!
Upvotes: 0
Views: 11552