Ask Your Question
0

How to read data from a serial port and publish it on a topic in C++

asked 2019-10-01 08:30:50 -0600

Juliette_ROS gravatar image

Language : C++

System : Ubuntu on Virtual Box

Hello,

I am working on a Battery Management System (BMS), and I need to collect data from it (battery voltage, temperature, etc...). The connection is made through a USB cable, thanks to a USB Serial converter because the data is in a "serial form".

I managed to connect the BMS to my virtual machine and I can see it in the list when I type lsusb in the terminal of Ubuntu :

BUS 001 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC

Now my problem is that I need to read the data from this BMS and I don't know how to do :

  • Should I create a publisher to publish this data on a topic ?
  • Should I download an extension made to deal with serial connection ?
  • How could I, at least, "ping" my BMS to see if it is well connected to my Virtual Machine ? Because I have the communication protocol, explaining that I should send a "$" and then receive data but I don't know how to communicate with the BMS, where should I write this "$" ?

I use ROS only for a week now so I am very unexperimented, if you have an answer to my question please detail it as much as possible !

Thank you

edit retag flag offensive close merge delete

Comments

1

Have you already checked whether there is some code that can interface with your BMS? A C/C++ or Python library perhaps? Is it completely custom, or could the mfg perhaps have some code?

It might even be that there already is a ROS node available for it.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-01 08:54:08 -0600 )edit
1

Have a look at this these are examples to interface your FTDI IC. Regarding ROS you can either constantly publish your data or set up a service which responds with the read data. It really depends on what exactly you want to make your code do.

LeoE gravatar imageLeoE ( 2019-10-01 09:01:03 -0600 )edit

@gvdhoorn : I searched on the internet but the BMS is sold by 123Electric and this company provides a software to use the BMS, so I don't think there is some open code anywhere... But maybe I don't searched on the right websites, do you know where I should do my researches ?

Juliette_ROS gravatar imageJuliette_ROS ( 2019-10-02 01:38:00 -0600 )edit

@LeoE These example are made for Windows I think so I can't use them on Ubuntu. Yes I have seen the difference between publisher and service, for my work I can use both, the other programs will adapt their behavior to mine.

Juliette_ROS gravatar imageJuliette_ROS ( 2019-10-02 02:40:23 -0600 )edit

the BMS is sold by 123Electric and this company provides a software to use the BMS, so I don't think there is some open code anywhere

But you did say:

Because I have the communication protocol, explaining that I should send a "$" and then receive data

So the only thing that exists is a protocol spec?

I don't think there is some open code anywhere

it doesn't need to be open-source. A simple C/C++ or Python library would already help quite a bit.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-02 05:38:58 -0600 )edit

@gvdhoorn : I searched on internet but found nothing related to this device...

Juliette_ROS gravatar imageJuliette_ROS ( 2019-10-03 01:53:01 -0600 )edit

Ok. Well. You could always ask the manufacturer. If you've already done that, it might be that writing something yourself is the way forward.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-03 01:58:52 -0600 )edit

Maybe you better use data transfer serial port and access via serial-over-ethernet.com? As far as I know, it can work without problems on Ubuntu, and there is functionality for creating a virtual com port.

blankTG gravatar imageblankTG ( 2019-10-17 04:33:05 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-01 12:50:15 -0600

duck-development gravatar image

For first test you can use the screen Programm to send the character $ you may need an neu line press enter. You need the boudrate

For example so:

screen /dev/ttyUSB0 9600

You may need to add you user to plugdev and dailout group.

Then you can use to Programm it. I would recomand to use python because it is mutch simpler for the serial port handling.

If you have to use cpp the you may use the Boost serial_port as boost is paart of ros https://www.boost.org/doc/libs/1_55_0...

edit flag offensive delete link more

Comments

Thanks for your answer !

  • What is the screen Programm ? Do I need to download it ?
  • What is plugdev and dailout group ?
  • I think I can use Python if needed

I am going to study Boost serial_port, to see if I can use it

Juliette_ROS gravatar imageJuliette_ROS ( 2019-10-02 02:46:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-10-01 08:30:50 -0600

Seen: 134 times

Last updated: Oct 01