[Interest] Is there a way to simulate serial port data?

Murphy, Sean smurphy at walbro.com
Tue Mar 28 01:58:52 CEST 2017


> What about writing a “virtual serial port” ?
> 
> QSerialPort is a QIODevice, so one thing you can do is to replace it with a
> custom QIODevice where you can write what you from e.g. a “console
> widget” to evaluate what you want from your application.

So you're suggesting when I want to debug my class I change this:
  class mySerialPort : public QSerialPort {};
to
  class mySerialPort : public virtualSerialPort {};
and recompile (where virtualSerialPort inherits from a QIODevice that I customize to do what I need to do)?

Basically the features I need are:
1. I need to be able to inject a QByteArray into the class and have that emit the readyRead() signal
2. The readyRead() signal is connected to my parse() slot
3. in parse(), I need myClass::readAll() to come back with that same QByteArray that I injected in step #1

It looks like maybe QBuffer (which I didn’t know existed) might be close to what I need... Ideally I was hoping to do it in a way that I didn't have to change any of the code of my serial port class, just to make sure I'm not introducing an error during this process...

Sean


More information about the Interest mailing list