[Interest] Is there a way to simulate serial port data?
Murphy, Sean
smurphy at walbro.com
Tue Mar 28 13:42:25 CEST 2017
> First of all your parsing class should only do the parsing, so it
> shouldn't derive from QSerialPort.
> instead it should take a QSerialPort pointer as a parameter, eg:
> QSerialPort port(...);
> port.open(...)
> Parser parser(&serialPort);
> Result result = parser.parse();
> or
> Parser parser;
> parser.setSerialPort(&port);
>
> This way, you could then derive QSerialPort into a VirtualSerialPort,
> and use it this way:
> VirtualSerialPort port(...);
> port.setData(byteArray);
> port.SetSomeConfigurationParameter(...);
> parser parser(&port);
> Result result = parser.parse();
I agrees, this seems like a much better approach in the long run.
The issue at the moment is that it's 3 year old code that really could use to be refactored, but the current schedule doesn't allow for that. Right now I'm chasing down a bug that has only affected us a dozen times or so over 3 years, so it's tough to justify ripping up all of the serial port stuff right now, but it needs to be done at some point. But for the short term, I was hoping I could find a way to simulate data coming in on the serial port so that I can concentrate on the existing bug, without modifying the existing codebase.
Sean
More information about the Interest
mailing list