TGI has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how I can create a fake serial port under Windows?

I have a datalogging application that pulls information from a serial device. I'd like to be able to automate testing of the app. To this end, I desire to either hijack a real serial port or register an emulated port, and provide IO streams that emulate a sensor.

Anyone have any ideas? Extenisve Googling isn't getting me anywhere.


TGI says moo

2006-08-23 Retitled by holli, as per Monastery guidelines
Original title: 'How to emulate a serial port under Win32?'

  • Comment on (OT) How to emulate a serial port under Win32?

Replies are listed 'Best First'.
Re: (OT) How to emulate a serial port under Win32?
by rodion (Chaplain) on Aug 22, 2006 at 22:13 UTC
    To add to GrandFather's suggestion, take a look at Test::MockModule which, as the description says "lets you temporarily redefine subroutines in other packages for the purposes of unit testing." You can substitute you're own sub for the sub that's returning the the bytes to your program, without touching that module, and do it all from your ".t" testing routines, leaving your production code intact.

    The book O'Reilly book Perl Testing: A Developer's Notebook, co-authored by Chromatic (seen here on PM), provides some very good guidance on this and other testing techniques. It's an excellent resource, and very concise. Each chapter and section can be pretty much read on it's own, so you can pick out the parts you need quickly.

Re: (OT) How to emulate a serial port under Win32?
by traveler (Parson) on Aug 22, 2006 at 20:45 UTC
Re: (OT) How to emulate a serial port under Win32?
by GrandFather (Saint) on Aug 22, 2006 at 20:55 UTC

    Why not move the emulation up a level and completely bypass the IO? After all, the IO is generally less important to test than the communication protocol.


    DWIM is Perl's answer to Gödel

      In general, I think you are right. I do some testing this way, now. But I'd like to be able to additional testing that exercises my whole application.

      A perfect solution would be something that I could eventually use to create a small app that simulates one (or more) of our sensors that I could distribute to potential customers so they can try out our data logging client.

      If I can use the same technique for testing as for the demonstration tool, that would be a big win. That way I can become intimately familiar with the emulated comm port and be certain that I won't hose anyone's system.


      TGI says moo

Re: (OT) How to emulate a serial port under Win32?
by BrowserUk (Patriarch) on Aug 22, 2006 at 23:52 UTC

    A word of caution. If you do opt for a software emulation of the serial port as a part of your testing strategy, make sure it is only a part. Ensure that your system testing also incorporates testing with a real device. For reproducability, consider setting up your tests and capturing them with a Protocal Analyser and then replaying them for regression testing. I have a strong preference for standalone hardware PAs, but some modern device driver based software PAs are pretty good.

    Serial devices have a whole host of failure modes that cannot be easily mocked up. If your device will be any distance from the host PC, and especially if it will live in an electrically noisy environment, you need to test in these kind of environments.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: (OT) How to emulate a serial port under Win32?
by jdtoronto (Prior) on Aug 22, 2006 at 20:48 UTC
    One of my contractors uses this for testing software we have which talks to small dataloggers on USB ports.

    jdtoronto