0

Trying to work on Raspberry Pi 3, Model B V1.2 with several serial ports with C++ code. Previously I should say that when I use only one ports everything works like a charm, so ports configuration is correct. Termios is used with appropriate speeds, stop bits and so on. Timings are configured by

tty.c_cc[VMIN]   =  0;              
tty.c_cc[VTIME]  =  5;                  

My program uses vector of pointers on my own serial port class. In the loop I ask every port from vector and if timing (0.5 s) is over, program continues. If only one serial port is pushed pack, everything is OK. When I add at least one more port, looks like that timings become broken and 0.5 seconds transform to something much more faster and no one byte could be read. I tested my program with several ports on PC with 4.15.0-46-generic #49-Ubuntu and there was not any problem, so I decided that the root of my issue is on Raspberry (or Raspbian). What can I do to find correct workaround?

Short version of my code:

for (tx_uart* port: uarts) {
    // Work with port while getting info
    while (frame_asked.at(port->getID())) {
         bool processed = false;
         // Read buffer while first zero byte
         while (!processed) {
             uint8_t buffer[MY_BUFFER_SIZE];
             size_t readed = port->readBytes(buffer, MY_BUFFER_SIZE);
             if (readed == 0) {
                 std::cout << "nothing" << std::endl;
                 continue;
                 }
         // Reading until whole pkg got
         }
    // Processing
    }
}

So problem is occured when I try to ready bytes in

size_t readed = port->readBytes(buffer, MY_BUFFER_SIZE);

all timing are skipping and always I get readed = 0.

Edit 1: I use serial ports with /dev/ttyUSB* and USB-RS232 convertors.

4
  • You have given too little information.
    – joan
    Mar 20, 2019 at 8:25
  • @joan I've added sample of my code. What additional info I could provide to make issue more clear?
    – Stanislav
    Mar 20, 2019 at 8:58
  • The Pi has only one usable UART. So you can only have one UART based serial link.
    – joan
    Mar 20, 2019 at 9:10
  • 1
    @joan That is info that I really forgot to add: I use serial port with /dev/ttyUSB* and USB-RS232 convertors.
    – Stanislav
    Mar 20, 2019 at 9:22

1 Answer 1

1

The issue was more hardware than software. I have connected four USB-RS232 converters and devices connected by this converters to main Raspberry. All devices were powered only through the Raspberry's USB-ports within the converters. So seems to be that there was not enough power to sustain the correct baudrate. Separate powering has solved my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.