How to read data from a serial port and publish it on a topic in C++
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
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.
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.
@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 ?
@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.
But you did say:
So the only thing that exists is a protocol spec?
it doesn't need to be open-source. A simple C/C++ or Python library would already help quite a bit.
@gvdhoorn : I searched on internet but found nothing related to this device...
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.
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.