SFML community forums

Help => Network => Topic started by: VinceLaTaupe on June 15, 2017, 11:44:26 am

Title: Connecting to a motor controller.
Post by: VinceLaTaupe on June 15, 2017, 11:44:26 am
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 (http://www.brainboxes.com/product/es-320/1-port-rs422-485-ethernet-to-serial-adapter))

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) :

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
Title: Re: Connecting to a motor controller.
Post by: Laurent on June 15, 2017, 11:57:51 am
How (mode, settings) do you connect to your adapter in putty?
Title: Re: Connecting to a motor controller.
Post by: VinceLaTaupe on June 15, 2017, 01:38:02 pm
Thank you for your response.

I'm not sur about what you're talking. Is the screenshot attached is enough to describe my settings ?
Title: Re: Connecting to a motor controller.
Post by: Laurent on June 15, 2017, 01:44:55 pm
Yes. Looks good.

Maybe you should monitor the exchanged data (with WireShark for example) and search for differences between putty and your program.
Title: Re: Connecting to a motor controller.
Post by: VinceLaTaupe on June 15, 2017, 02:04:44 pm
Ok I'll try. Thanks for the clue !
I'll be b ack if I have an issue  :P
Title: Re: Connecting to a motor controller.
Post by: VinceLaTaupe on June 15, 2017, 03:32:00 pm
Hey Laurent.
I'm back with some results, but I don't know how to analyse them.

Attached to this post, there are 3 screens shots, 1 for the packet sending from my computer to the BB (brainbox adapter) called putty-send, and the other are the same : putty receive, and prog-send. I don't have any data received with my program...

I don't know what I need to observe. I saw with putty there are 4 lines between sending and receiving (#3625->#3629).

Can you help me on what you I focus on ? 
Title: Re: Connecting to a motor controller.
Post by: Laurent on June 15, 2017, 04:07:55 pm
I'm afraid I won't be able to help you further, sorry :(
Title: Re: Connecting to a motor controller.
Post by: VinceLaTaupe on June 15, 2017, 04:18:30 pm
 :'(

Well, if you're interested, I found something : The line after the first send, putty send a 2 bytes packet : 0x0d and 0x0a, I added it in my packet, and my program went further  ;D Just need to check the code errors now  :o

Thanks for your help.

If anyone else is reading, your help is welcomed !
Title: Re: Connecting to a motor controller.
Post by: Laurent on June 15, 2017, 06:40:23 pm
Quote
0x0d and 0x0a
This is "\r\n". It is often used as line termination sequence in text protocols.
Title: Re: Connecting to a motor controller.
Post by: VinceLaTaupe on June 16, 2017, 10:35:44 am
Yup, I learned that yesterday ! :p

It's all working now !
Thank you for the tip to use WireShark, saved my day :)