Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Connecting to a motor controller.  (Read 3990 times)

0 Members and 2 Guests are viewing this topic.

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Connecting to a motor controller.
« 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)

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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Connecting to a motor controller.
« Reply #1 on: June 15, 2017, 11:57:51 am »
How (mode, settings) do you connect to your adapter in putty?
Laurent Gomila - SFML developer

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Connecting to a motor controller.
« Reply #2 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Connecting to a motor controller.
« Reply #3 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.
Laurent Gomila - SFML developer

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Connecting to a motor controller.
« Reply #4 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

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Connecting to a motor controller.
« Reply #5 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 ? 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Connecting to a motor controller.
« Reply #6 on: June 15, 2017, 04:07:55 pm »
I'm afraid I won't be able to help you further, sorry :(
Laurent Gomila - SFML developer

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Connecting to a motor controller.
« Reply #7 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 !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Connecting to a motor controller.
« Reply #8 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.
Laurent Gomila - SFML developer

VinceLaTaupe

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Connecting to a motor controller.
« Reply #9 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 :)