Hi everyone !
I'm new in networking and I installed and followed the tutorial on the SFML Network Library.
I'd still have some question about how to connect to a motor controller. Here is my situation :
I have 3 motor controllers, connected to my computer through an ethernet port (actually they are connected by RS485 to a RJ45/RS485 adapter which is connected to my computer,
here it is)
I have very simple commands to send/receive to/from the controller such as :
#2y1 *ENTER* //Charging the 1st pre-saved program in the 2nd controller (activate the motor for 5s for example)
Echo from the controller 2y1 // Controller received and understood the command.
#1A *ENTER* // Execute the program.
Echo 1A
In this example the echo isn't
really necessary, but for some actions (reading controller's I/O) it is important :
#1Y *ENTER* //Read I/O of the 1st controller
ECHO : 1Y+<a serie of bits to interprate>
I already worked with PuTTY and this adapter and it was working.Knowing this, I establised the following (please, correct me if I'm wrong) :
- The topology to use is Client-Client (I only have to program one of them)
- The sockets to use are TCP socket (except for reading I/O if I want a very quick response all the time)
- I can't use the built-in function using the packets (because of the extra-bytes used)
Because of that, I was thinking about using only UDP sockets, because I'm not very handy by playing with bytes...
With this, I made a first test program, but it isn't working. It seems that I can connect and send datas, but I'm not sure that they are received :
#include <iostream>
#include <SFML/Network.hpp>
int main()
{
std::cout << "Test SFMFL\n--------------------------\n";
std::cout << "Network connexion\n" << std::endl;
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("192.168.127.254", 9001); //Connecting to the adapter
if (status!= sf::Socket::Done)
std::cout << "Connexion failed"<< std::endl;
else
{
std::cout << "Connexion success"<< std::endl; // Every time this text is displayed.
char code[4];
code[0]='#';code[1]='1';code[2]='y';code[3]='1'; // I don't know if I have to add a '\n' char to valid the line...
std::cout << "Sending the code..." <<std::endl;
if (socket.send(code,4) != sf::Socket::Done)
std::cout << "error while sending" << std::endl;
else
{
std::cout << "success" << std::endl; //I came to this point too.
//But from this point, nothing else works, I can't read the echo (the propgram freeze beacause of locking //sockets) traducing that I don't have any echo from the controller...
}
}
}
I tested to send directly '#1y1' and then '#1A' but the motors doesn't move.
It means that the message is sent, but the controller don't receive it :/
Thank you very much by advance for your help !
Vince