Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers. Note that due to large amounts of spam attempts, your first three posts will be manually moderated, so please be patient.
We have moved to a new forum at http://jevois.usc.edu, please check it out. The forum at jevois.org/qa will not allow new user registrations but is maintained alive for its useful past questions and answers.

Hard serial binary data

0 votes
I'm writing a module to calculate motion data from images.   I would like to send results over the hardware serial, but as binary data, not a text string.  I have quite a lot of data, which fits in a 115200 connection, but would not in text form.

I have tried to instantiate the jevois::Serial class, guessing as I go along, since there is not a single example that shows how to do this.  I created a member variable of this type in my module, and constructed it with the module instance:

m_Serial(instance,jevois::UserInterface::Type::Hard)

then, in my process, I use the write method to send a binary buffer.  This doesn't work, and my video output shows that an       std::exception was thrown with an error:    Serial: write error

Can anyone point to how the proper usage is, without using the text based  sendSerial method of the engine, or is that the only way, and the Serial class is not for use directly by modules?

Self comment:  Looking at the source code for the engine, I suppose I could hack an interface that exposes the Serial object and use that, but I would rather use a ready made approach, before hacking the engine code.
asked Aug 14, 2017 in Programmer Questions by Photon (320 points)
edited Aug 14, 2017 by Photon

1 Answer

0 votes

(sorry for the delay as we are just back from vacation)
 

You may need to first make sure that the Engine does not open the port, by disabling it there:

in JEVOIS:/config/params.cfg add this line:

serialdev=

The empty device name will tell JeVois to not open the hardware serial port. Then indeed you can create your own in your module, but you need to add it as a sub-component rather than just using a member var, so that your serial will be integrated to the component hierarchy and its parameters will be available to users, etc:

in your module's class, declare a shared_ptr member var:

std::shared_ptr<jevois::Serial> m_serial;

then in your module's constructor:

m_serial = addSubComponent<jevois::Serial>("myserial", jevois::UserInterface::Type::Hard);

m_serial->devname::set("/dev/ttyS0");

Then you should be ok with using m_serial->write() for raw data writes.

some more infor about components hierarchies in jevois is here:

http://jevois.org/doc/classjevois_1_1Component.html

answered Aug 18, 2017 by JeVois (46,580 points)
...