Re: [Interest] Is there a way to simulate serial port data?
You can emit readyRead signal explicitly where you are using that class. mySerialPort msp; emit msp.readyRead(YourByteArray); because signal is defined as public. But this may not be a good way for testing On Wed, Mar 29, 2017 at 4:32 PM, Murphy, Sean wrote: > > I have to ask, why is it such a sin to have a stand alone program with a > > null modem cable and mini-tester as a testing tool. I have been working > > with serial ports off and on since the days of DOS 3.x and have always > > tested in this manner. The first piece of code one writes on a project > > which needs external inputs is the test tool to generate 1-N pre-defined > > inputs. There "should" be one laying around at the shop which was > > originally used to validate the product. > > There's nothing wrong with having a standalone program at all from a > technical standpoint. The question arose because of the bug showing up a > little more often recently, and a work deadline to release a version soon > - so > I was looking for a quick method to verify that my fix for the issue works. > I have a log of the data that produced the problem. I thought if I had a > way to playback that log without changing any of my serial port / parsing > code, that would be the quickest way to test the fix, without risking > generating > new bugs, by either having to modify my existing code, or having to write a > separate sender program. > > And I can guarantee there wasn't a tool laying around the shop, but as of > yesterday, there's now one in development! > Sean > > > ___ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
> I have to ask, why is it such a sin to have a stand alone program with a > null modem cable and mini-tester as a testing tool. I have been working > with serial ports off and on since the days of DOS 3.x and have always > tested in this manner. The first piece of code one writes on a project > which needs external inputs is the test tool to generate 1-N pre-defined > inputs. There "should" be one laying around at the shop which was > originally used to validate the product. There's nothing wrong with having a standalone program at all from a technical standpoint. The question arose because of the bug showing up a little more often recently, and a work deadline to release a version soon - so I was looking for a quick method to verify that my fix for the issue works. I have a log of the data that produced the problem. I thought if I had a way to playback that log without changing any of my serial port / parsing code, that would be the quickest way to test the fix, without risking generating new bugs, by either having to modify my existing code, or having to write a separate sender program. And I can guarantee there wasn't a tool laying around the shop, but as of yesterday, there's now one in development! Sean ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
You can also simulate via external software like https://docklight.de/ or create serial port pairs (search for virtual serial port) Le 28-03-17 à 13:42, Murphy, Sean a écrit : 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 -- *Stéphane Fabry*, R&D Manager & Software architect +32 (0)4 367 07 92 *X-RIS* | /X-Ray Imaging Solutions/ www.xris.eu/contact.html ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
Hi, On Tuesday 28 March 2017 13:23:01 Roland Hughes wrote: > I have to ask, why is it such a sin to have a stand alone program with a > null modem cable and mini-tester as a testing tool. I have been working > with serial ports off and on since the days of DOS 3.x and have always > tested in this manner. The first piece of code one writes on a project > which needs external inputs is the test tool to generate 1-N pre-defined > inputs. There "should" be one laying around at the shop which was > originally used to validate the product. This is a great method to develop or diagnose software. When it comes to testing... not exactly a sin, but short sighted: it's rather hard to set up an automated test system with specific hardware attached to each and every test node. > If you are dealing with a bug that only bites you ever so many years, I > will leave you with this thought. Especially those should be added to regression tests - otherwise you'll spend the same amount of time diagnosing it the next time. Konrad signature.asc Description: This is a digitally signed message part. ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
I have to ask, why is it such a sin to have a stand alone program with a null modem cable and mini-tester as a testing tool. I have been working with serial ports off and on since the days of DOS 3.x and have always tested in this manner. The first piece of code one writes on a project which needs external inputs is the test tool to generate 1-N pre-defined inputs. There "should" be one laying around at the shop which was originally used to validate the product. If you are dealing with a bug that only bites you ever so many years, I will leave you with this thought. Having written a lot of scale software early in my career it was never the packet which had the problem that actually caused the problem, it was always a data packet 1-N in front of that packet. This happened because scale manufacturers would use bounding characters for differing packet types and they dutifully calculated a checksum or CRC for the packet. Inevitably that byte would collide with a value chosen for one of the bounding characters and it would be a seemingly random problem usually resulting from a truck being much lighter or heavier than any value they used to bench test their error checking byte with. No idea what your serial project is, but that was always the problem we ran into in the field, especially when someone brought in a shiny new scale vendor or model. If your system can be dynamically configured in the field, you should add a feature to keep track of the last 10 packets and when the code recognizes/traps the error (you obviously have some idea of what and where it manifests since you know it is a bug) dump the hex value of the last 10 packets to a log. Won't fix your problem today or quickly, but it will actually identify what is causing the problem. Or perhaps you have already done that and I'm just rambling... -- Roland Hughes, President Logikal Solutions (630)-205-1593 http://www.theminimumyouneedtoknow.com http://www.infiniteexposure.net http://www.johnsmith-book.com http://www.logikalblog.com http://www.interestingauthors.com/blog http://lesedi.us/ ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
> 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 ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
On Tue, March 28, 2017 00:54, Henry Skoglund wrote: > Hi, I faced a simular situation last summer, and I used this: > http://com0com.sourceforge.net/ > > Rgrds Henry > P.S. I think it only works on Windows, though. Correct. On Linux/Unix/MacOS you can use a simple pseudo TTY: write a small program that allocates one or two new PTYs and handles the backend side of it - your Qt app only needs to open the frontend TTY and can handle it like a serial port. There are also some tools that support this: Kernel module equiv. of com0com: https://sourceforge.net/projects/tty0tty/ Using on-board user space tools: https://justcheckingonall.wordpress.com/2009/06/09/howto-vsp-socat/ Konrad ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
On 28 March 2017 at 12:58, Murphy, Sean wrote: >> 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... 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(); A parser is not a serial port (do not use derivation), a parser uses a serial port (use data member). Look for example at QXmlStreamReader, it can be used with any QIODevice, including QBuffer: http://doc.qt.io/qt-5/qxmlstreamreader.html#setDevice My 2 cents; > > Sean > ___ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
> 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 ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
> On 28 Mar 2017, at 00:48, Murphy, Sean wrote: > > I've got a class that inherits from QSerialPort. The bulk of the code in the > class is parsing that I'm doing in a slot that is connected to QSerialPort's > readyRead() signal. I want to inject known data into this class as if it's > actually coming across the serial port to validate my parsing code, is there > any way to do that? Ideally I'd be able to write data in and have it trigger > the readyRead() signal, but I'm not seeing any way to do that. > > I know I could write a separate application that writes out one serial port, > and then I could cable that back to my other serial port, but I was just > looking for a way to do it all in code. > > Sean > > ___ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest Hi, 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. Cheers Samuel signature.asc Description: Message signed with OpenPGP ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Is there a way to simulate serial port data?
Hi, I faced a simular situation last summer, and I used this: http://com0com.sourceforge.net/ Rgrds Henry P.S. I think it only works on Windows, though. On 2017-03-28 00:48, Murphy, Sean wrote: I've got a class that inherits from QSerialPort. The bulk of the code in the class is parsing that I'm doing in a slot that is connected to QSerialPort's readyRead() signal. I want to inject known data into this class as if it's actually coming across the serial port to validate my parsing code, is there any way to do that? Ideally I'd be able to write data in and have it trigger the readyRead() signal, but I'm not seeing any way to do that. I know I could write a separate application that writes out one serial port, and then I could cable that back to my other serial port, but I was just looking for a way to do it all in code. Sean ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
[Interest] Is there a way to simulate serial port data?
I've got a class that inherits from QSerialPort. The bulk of the code in the class is parsing that I'm doing in a slot that is connected to QSerialPort's readyRead() signal. I want to inject known data into this class as if it's actually coming across the serial port to validate my parsing code, is there any way to do that? Ideally I'd be able to write data in and have it trigger the readyRead() signal, but I'm not seeing any way to do that. I know I could write a separate application that writes out one serial port, and then I could cable that back to my other serial port, but I was just looking for a way to do it all in code. Sean ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest