Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Implementation not communicating #5

Open
danimasa opened this issue Jul 17, 2020 · 5 comments
Open

C++ Implementation not communicating #5

danimasa opened this issue Jul 17, 2020 · 5 comments

Comments

@danimasa
Copy link

I'm having a problem running code from the C++ implementation.

I copied robust_serial.hpp to my project and implemented a class to read and write information to the serial port using std::fstream.

std::fstream serial_port;
serial_port.open(device, ios::in|ios::out|ios::app|ios::binary);
write_order(serial_port, SEND);
write_i32(serial_port, id);

The implementation in my arduino is like that:

setup() {
    Serial.begin(SERIAL_BAUD);
}

loop() {
    if(Serial.available() > 0)
    {
        Order order_received = read_order();
        switch(order_received)
        {
            case SEND:
                 uint32_t ID = (uint32_t) read_i32();
        }
    }
}

So I adjust the stty from the terminal:
stty 115200 -F /dev/ttyACM0

But the data is not arriving to the arduino board, but i noticed that if I use a sniffer like interceptty like that:
interceptty /dev/ttyACM0

That create a bind to the /dev/pts/3, and if I connect to that port the data is Ok and is arriving to arduino. But if I remove the interceptty and connect direct to the /dev/ttyACM0 it stop working again. And if I start interceptty and kept it running I can communicate either, even with the /dev/ttyACM0 port.

What could be intercepting my communication with the board?

@araffin
Copy link
Owner

araffin commented Jul 17, 2020

Hello,

I copied robust_serial.hpp to my project and implemented a class to read and write information to the serial port using std::fstream.

Why didn't you use the examples from https://github.com/araffin/cpp-arduino-serial/tree/2075fd8f203483af9c82caffba4bdbc84024ea63/examples ?

EDIT: your implementation looks like the same as in the examples

@araffin
Copy link
Owner

araffin commented Jul 17, 2020

What could be intercepting my communication with the board?

To be honest, I have no idea... I usually had trouble reading packets coming from the Arduino, not the opposite way.
Are you also using the arduino code from this repo?

@danimasa
Copy link
Author

danimasa commented Jul 20, 2020

Hello @araffin

Why didn't you use the examples from https://github.com/araffin/cpp-arduino-serial/tree/2075fd8f203483af9c82caffba4bdbc84024ea63/examples ?

EDIT: your implementation looks like the same as in the examples

I used the code from file_read_write.cpp example.

Are you also using the arduino code from this repo?

Yes, I'm using exacly the same implementation used in slave.cpp. But I'm not keeping the connected flag, I'm receiving the messages direcly in arduino loop funcition, first receiving the order and then the data.

What I found weird is that if interceptty is running all works normal. It seems like some configuration of the serial port interfere in the communication, and that service applies it when running.

@araffin
Copy link
Owner

araffin commented Jul 20, 2020

as a sanity check, can you send/receive something using Arduino IDE?

@danimasa
Copy link
Author

Yes, if I send anything the Serial Monitor returns my error NotFound order (I couldn't manage to send data not encoded in ASCII using the Serial Monitor to see if it responds correctly send my data).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants