Speed of USB_VCP with serial port in different programming language in Linux

Hi, hoping you kind guys give some advice to my question about the serial port use with openMV, here is the confusing thing:
I implemented the SUB_VCP example and then integrated into my code in OpenMV4, sending some data and images to PC Linux, everything is fine, the connection is done and data is exchanged correctly. But something strange happens, when I use the serial port lib in Cpp in linux, the data extrange speed is low, like 0.5Hz when receiving image; when using serial port in python to receive data, the speed can be up to 10Hz.

  1. settings of baudrate are the same in both cpp and python.
  2. the codes in openmv are the same in both tests
  3. the data is extranged correctly in both tests

problem is: the receiving speed of serial port in cpp seems match the baudrate setting, while the data speed of python implementation seems much higher the baudrate setting. in Python, it seems speed can reach 1MB/s

Please share some guides to me to figure out the following questions, great thanks:

  1. why is that happens?
  2. how can I speed up in cpp implementation?(like speed in python implementation)

eager to hear your advice, thanks.


  1. No clue. The application should not throttle the baud rate. However, the cpp app my allocate really small kernel buffers per a lower baud rate which then results in the kernel transferring data is smaller packets.

  2. Set the baud rate to a higher value. Do not use 921600 or 12 Mb/s as these cause the camera to enter debug mode which the IDE uses to communicate. So, try 11 Mb/s.

Thanks for reply.
Now I do some extra tests:

  1. in python, the baudrate param is not working, whatever the given baudrate is(115200 or 9600 or 1200), the actual data rate is always around 1000000 Byte/s. here is the serial port init code:

import sys, serial

sp = serial.Serial(port, baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,
xonxoff=False, rtscts=False, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=True)

I guess this is related how the USB VCP module works and other params in this code line, but I don’t know which params, and I want to figure out how to manage to adjust its baudrate.

so hopefully guys can give me some guide.

(similar phenomenon happens when using cutecom, a serial debugging tool)

USB VCP ports don’t have a baud rate. They just run at the bus speed of 12 Mb/s. 1MB/s makes sense in bandwidth.

ha, so the ‘baudrate=115200’ in python script cannot actual set the baud rate. That’s fine.

but still something strange remains unsolved:

  1. when using serial debugging tool, baudrate setting is not working in most case too, but the data rate is much lower than 12 Mb/s.
  2. when using serial port lib '<serial/serial.h> ’ in cpp, the baudrate setting has effect on actual data rate. In my cpp test, when transmits a image with size 76800Bytes :

baudrate=110, used time: 0.07s
baudrate=9600, used time: 1.01s
baudrate=460800, used time: 5.83s

cpp code is like this:

#include <serial/serial.h> 

serial::Serial ser;
serial::Timeout to = serial::Timeout::simpleTimeout(5000);

ser.read(buffer_img, value_size)

OK! :grinning: I think I figure out why the cpp implementation seems have weird result…
To finish this topics, I would like to share my storyline to you great guys:

  1. First of first, I want to send image and some logdata to PC in real time, so I test Example USB_VCP.py and it works fine and fast, as stated in previous post, it can reach 1MB/s.

  2. But my project is in cpp language, so I have to implement the USB_VCP.py into cpp.

  3. Here is the thing where I got wrong, I had consider USB_VCP is something like UART(which is not). Because in my previous thought, if something need to set baudrate and with ‘Serial’ name, it would be UART :sweat_smile:.

  4. So I keep coding as communication using UART in ROS, using ROS Serial package. It actually worked and I got what I want(mentioned in my first post above), but the data rate is confusing.

  5. In days I keep checking the configuration of Serial Port code, no result. I think it is because the ROS Serial package can not meet my needs.

  6. I rethink the whole thing and I found I shouldn’t have considered USB_VCP as UART, but USB. So treat it as a normal USB port may helps.

  7. then I found this post: Sending serial data out (via USB) with C++
    the cpp class in this post finally have the same function of USB_VCP.py
    which means: the transmit rate reach 1MB/s stably, and the boadrate setting is invalid.

I think openmv-RPC have some similar work to send data and images to PC, wait to see, but I doubt it have a friendly interface with cpp, too. :thinking: thanks you guys.

ROS can run python code. No reason to use CPP. Just wrap it in a ROS node.

well this is in part of my project code. though python is what i love to use and actually I did make it a python ros node, there are still some other reasons I have to make it into cpp. But anyway, thanks for your kind replies.