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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - VinceLaTaupe

Pages: [1]
1
Network / Re: Receiving incomplete data: How to control?
« on: July 11, 2017, 03:34:40 pm »
Got it !

However in this case I cannot receive multiple messages because of my structure : My program communicate with a controller card. Therefore the controller responds a simple message only when I ask him to.

But I'll try to do as you said just to practice !

Thank you again Laurent !

2
Network / Re: Receiving incomplete data: How to control?
« on: July 11, 2017, 03:01:17 pm »
Fastest resolved problem ever !

It works perfectly, just needed a little do{}while() loop ...

Quite easy, sorry for bothering...

My code for those who'd like :

bool status = false;
        int i(0);
        do {
                socket.receive(data, 64, received);

                if (data[received - 1] != '\r')
                {
                        str += data;
                        status = false;
                }
                else
                {
                        data[received - 1] = '\0';
                        str += data;
                        status = true;
                }
                ++i;
        } while (statut == false);
       
        std::cout << "Message received in " << i << " times: \n" << str << std::endl;
 


3
Network / Re: Receiving incomplete data: How to control?
« on: July 11, 2017, 02:38:09 pm »
This is very well explained in the socket tutorial:
Quote
The last difference is about the way data is transported. TCP is a stream protocol: there's no message boundary, if you send "Hello" and then "SFML", the remote machine might receive "HelloSFML", "Hel" + "loSFML", or even "He" + "loS" + "FML".

So you have to find a way to detect the end of the message within the received stream of data. If the communication protocol has no concept of boundaries, then there's no other choice but to rely on the number of bytes received.

I forgot this one ...

Well I can't predict the number of bytes received ...
As is I'm not sure there is a special incomming communication protocol, I'll check this way.

But I think that the last byte sent is the carriage return "\r". But not sure I can detect it with something like :
if (data[received-1] != '\r')
//receive again and again
 

This character is always the last one no ?

Thank you for you response Laurent.

4
Network / Receiving incomplete data: How to control?
« on: July 11, 2017, 01:39:52 pm »
Hi everyone.
Thank you by advance for your help !

I have an issue and I don't know the cause.
J'ai un problème dont je n'arrive pas à identifier tout à fais la cause. First of all, I can not use the sf :: Packet class because I do not handle the "server side".

I am supposed to receive a generic message of about 60 bytes.

So I created a buffer of size 64. The problem is that at the reception I do not get the 61bytes, at least not all the time and that's what I do not understand ...
Sometimes I get the whole message, sometimes not.

The problem is that when I do not receive the whole message, the status returned is still sf::Socket::Done, therefore, no way for me to analyze whether my message is complete or not to re-call the receive() function ...

Here is my code "abbreviated" and the associated answers:

int main()
{
        sf::TcpSocket socket;
        std::cout << "Connexion" << std::endl;
       
        sf::Socket::Status status = socket.connect("192.168.127.254", 9001);
        std::cout << status << std::endl;

        size_t received(1);
        char data[64] = { 0 };
        std::string str{ "" };

        str =  "#1Z1|\r" ;

        if (socket.send(&str[0], str.size()) != sf::Socket::Done)
                std::cout << "ERROR sending" << std::endl;
        else
                std::cout << "Message sent : " << str << std::endl;

        status = socket.receive(data, 64, received);

        if ( status != sf::Socket::Done)
                std::cout << "ERROR reception. Status : " << status << std::endl; // Just for illustration
        else
        {
                data[received - 1] = '\0';
                str = data;
                std::cout << "Message received: " << str << " (" << received << ")" << std::endl;
                std::cout << "Status : " << status << std::endl;
        }

        // To prove that there are still some:
        if (received != 61)
        {
                status = socket.receive(data, 64, received);

                if (status != sf::Socket::Done)
                        std::cout << "ERROR reception. Status : " << status << std::endl; // Just to illustrate
                else
                {
                        data[received - 1] = '\0';
                        str = data;
                        std::cout << "Message received : " << str << " (" << received << ")" << std::endl;
                        std::cout << "Status : " << status << std::endl;
                }
        }
}
 

Here are the results in the windows console, first when it works properly and sencondly when it doesn't :

(click to show/hide)


Status 0 correspond to sf::Socket::Done.

You see well that sometimes I do not get everything, and yet the program returns me a Done status ...

An idea of the problem and how to solve it?

Thanks by advance,
Vincent.

PS : I'm beginner, sorry if I made big mistake :p

5
Network / Re: Connecting to a motor controller.
« 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 :)

6
Network / Re: Connecting to a motor controller.
« 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 !

7
Network / Re: Connecting to a motor controller.
« 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 ? 

8
Network / Re: Connecting to a motor controller.
« 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

9
Network / Re: Connecting to a motor controller.
« 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 ?

10
Network / 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

Pages: [1]
anything