Announcement

Collapse
No announcement yet.

Serial Port Emulator?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serial Port Emulator?

    I've started working on my first serial port app. Is there a way to emulate a serial port so that my own application can be tested?

    I guess the bigger question I'm asking, is how do folks test their serial apps? If the designed-for serial data is not available on the serial port of the development PC, how can the new app be evaluated?

    On first guess, I assume the test program can simply send something to the serial port. Once sent, I can test my receive code. Are there any complicating factors?
    Last edited by Gary Beene; 11 Sep 2009, 08:09 AM.

  • #2
    Gary, the easiest way to test your code is to have a cross-over cable and send from one serial port (or virtual COM) to another, and have a terminal on one just to see what came in, and respond to your app.
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      I have been working with that type of stuff for 20 years, and the best solution I found was connect to an old machine running a PB-DOS Compiler. This way I can write or modify a code emulating the serial device that will work with the application I am developing.

      Regards,

      Comment


      • #4
        I had some stuff (not serial communications) I had to test across multiple computers, so I bought a laptop. Well, actually, YOU* bought it. Works good.

        MCM
        * You DO pay taxes, right?
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Yes, a notebook is handy, and normally have a small foot print. Actually I am using a very old NCR 386 laptop. To emulate a serial device though, is better to use a machine having a native serial port, not a USB to Serial Converter, since that requires Windows, and Windows will prevent you having control of the serial stream. For the same reason is necessary to run PB on MS-DOS or equivalent, not a Windows dosbox.

          Regards,

          Comment


          • #6
            In that neither my PC nor laptop have anything but USB (no native, old style serial port), I guess I'll be looking into using Virtual COM port software.

            Comment


            • #7
              >>I guess I'll be looking into using Virtual COM port software..

              Here's a good place to start:


              Some other links that may prove useful..

              Monitor Serial port activity with PortMon (Microsoft, formerly Sysinternals):
              Monitor serial and parallel port activity with this advanced monitoring tool.

              (filter set to exclude IOCTL_SERIAL_GET_COMMSTATUS to avoid getting swamped!)

              Null modem and loopback wiring:


              MTTTY Terminal Program. (Alternative to HyperTerminal):
              Rgds, Dave

              Comment


              • #8
                Dave,
                Thanks for the links.

                I also found this, which I've downloaded and am about to try out.

                Virtual Serial Port Driver creates pairs of virtual COM ports. Virtual COM port pairs look and work like real hardware ones, fully emulating serial port connections


                It creates 2 connected virtual com ports on a single PC. What goes out of one port goes into the other.

                It's a bit expensive, but if it works I'll search for others like it that might be a bit less expensive.

                MCM,
                Perhaps I can borrow back MY laptop?

                Comment


                • #9
                  >Perhaps I can borrow back MY laptop?

                  Um, no. WE are using it today.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    >>I guess I'll be looking into using Virtual COM port software..
                    I can save you some time since I have been working almost exclusively with serial ports and attached devices for the past 10yrs (including "Virtual COMMS" whether it be virtual by chip (USB Adapter) or virtual by computer (Pretend you are talking to a actual port, or share a port amongst many users) or what have you.)

                    Virtual COMMS by computer as you will find can be expensive, and most likely use a technique that I had planned on using myself (IF I can EVER find the time to implement it) and in reality you will find little if no code showing you how (or at least I haven't) but my best guess is that the "Grunt-Work" is being done by TCP/IP and then the end connection passes the info to and from the serial port itself (Since Serial Ports to the best of my knowledge can only be used by 1 owner at a time)

                    as far as emulation goes....how emulated is emulated? (Something as simple as COMMS.bas???? or are you looking towards more heavy-duty "Inside the Serial Port itself" sort of thing???

                    Either way, it can be done, its "just how deep into the rabbit hole you wanna go alice"
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      Virtual COMMS by computer as you will find can be expensive
                      Um, what does it cost to add a "real" serial port or two to a Windows computer? I seem to recall add-on serial cards were essentially dirt-cheap for MS-DOS boxes.

                      And would that not be a reasonable (read "tax-deductible") expense for someone who wants to develop an application using serial communications?

                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Wow! The Virtual Serial Point Driver I noted earlier seems to works very well. I spent several minutes with it and it's very convenient. It creates 2 ports, which are tied together so the output of one goes to the input of the other. Very easy to use. Plus it gives an easy, independent readout of traffic - separate from the PowerBASIC program I was testing.

                        To Cliff's comments - I don't know enough about serial ports to judge where the VSPD is lacking in features, but for my simple Comm Send and Comm Recv tests it appeared to work well.

                        But like Cliff said, the price is a factor - $100.

                        At that price, as MCM noted, two physical serial ports would probably be cheaper, but also requires shopping time and installation time.

                        Comment


                        • #13
                          MCM
                          Um, what does it cost to add a "real" serial port or two to a Windows computer? I seem to recall add-on serial cards were essentially dirt-cheap for MS-DOS boxes.
                          I would think dirt cheap too, seeing how real COMMS are not used much anymore (outside of manufacturing, or devices that are NOT modems)

                          What I meant was software that replicates virtual Comms without an attached device (USB adapters, Serial Port watchers, and etc)

                          $100 bucks for something I could make do with Comms.bas???? SHYYUUUUHHHH Right....like I am going to pay for something that basically could be done myself for simple testing.

                          If I knew nothing about serial ports then yeah, maybe its worth it to get a project running, but then again its $$$$ vs knowledge vs convenience

                          I think Gary's core question is how to "Dip your big toe" without falling into the pool

                          If that is the case then, the best bet is a couple of USB adapters and 2 terminals (1 to be replaced by your code, or just use the 2 copies of COMMS.bas) and a cross-over cable, and proceed from there

                          The only reason I say USB is cause it depends on what your computer has for slots for adding hardware, but the simple tests and more useful in the long run will be USB adapters.
                          I would recommend Hawking USB adapters depending on the OS and all the configurations possible with your system, but thats just a bias of (make the USB work 1st then worry about how to treat the RS232)

                          either way I would use PB COMMS.bas for each port for initial testing, and when stuck, ask us here why the COMMS does or does not do what you need (It will be a while before asking why it would not work (if ever) I assure you )
                          Engineer's Motto: If it aint broke take it apart and fix it

                          "If at 1st you don't succeed... call it version 1.0"

                          "Half of Programming is coding"....."The other 90% is DEBUGGING"

                          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                          Comment


                          • #14
                            Just in case anyone else wants to play with the virtual port trial I mentioned, here's the simple app I wrote to read/write between the two virtual ports (Com2 and Com4 in this case). There's nothing special in this, just saves you from coding it.

                            For my purposes, it was helpful to test out some code. But not so helpful that I'll purchase it at $100. I do plan to nose around and see what else is available for free.

                            Code:
                            'Compilable Example:
                            #Compile Exe
                            #Dim All
                            #Include "Win32API.inc"
                            Global hDlg as Dword, iPort2 As Long, iPort4 As Long, SndMsg$, RcvMsg$, sPort$
                            
                            Function PBMain() As Long
                               Dialog New Pixels, 0, "Test Code",300,300,200,280, %WS_OverlappedWindow To hDlg
                               Control Add Label, hDlg, 101, "COM2", 35,10,70,20
                               Control Add Label, hDlg, 102, "COM4", 120,10,70,20
                               Control Add Button, hDlg, 100,"Open", 10,30,70,20
                               Control Add Button, hDlg, 110,"Configure", 10,60,70,20
                               Control Add Button, hDlg, 120,"Get Config", 10,90,70,20
                               Control Add Button, hDlg, 130,"Send", 10,120,70,20
                               Control Add Button, hDlg, 140,"Receive", 10,150,70,20
                               Control Add Button, hDlg, 150,"Close", 10,180,70,20
                            
                               Control Add Button, hDlg, 200,"Open", 100,30,70,20
                               Control Add Button, hDlg, 210,"Configure", 100,60,70,20
                               Control Add Button, hDlg, 220,"Get Config", 100,90,70,20
                               Control Add Button, hDlg, 230,"Send", 100,120,70,20
                               Control Add Button, hDlg, 240,"Receive", 100,150,70,20
                               Control Add Button, hDlg, 250,"Close", 100,180,70,20
                            
                               Control Add TextBox, hDlg, 155,"<InMsg2>", 10,210,180,20
                               Control Add TextBox, hDlg, 156,"<InMsg4>", 10,240,180,20
                               Dialog Show Modal hDlg Call DlgProc
                            End Function
                            
                            CallBack Function DlgProc() As Long
                               Local Qty&, iResult&
                               Static iCount2&, iCount4&
                               Select Case Cb.Msg
                                  Case %WM_Command
                                     Select Case Cb.Ctl
                                        Case 100 : iPort2 = OpenPort("com2")
                                        Case 110 : SetConfiguration(iPort2, 14400,8,%False, 0, 4096,4096)
                                        Case 120 : MsgBox (GetConfiguration (iPort2))
                                        Case 130 : Control Get Text hDlg, 155 To SndMsg$
                                                   Incr iCount2&
                                                   Comm Send iPort2, "Msg2 " + Str$(iCount2&)  'Send
                                        Case 140 : Qty& = Comm(iPort2, RxQue)         'check que to see how many bytes are available
                                                   Comm Recv iPort2, Qty&, RcvMsg$   'get that many bytes
                                                   Control Set Text hDlg, 155, RcvMsg$
                                        Case 150 : Comm Close iPort2
                            
                                        Case 200 : iPort4 = OpenPort("com4")
                                        Case 210 : SetConfiguration(iPort4, 14400,8,%False, 0, 4096,4096)
                                        Case 220 : MsgBox (GetConfiguration (iPort4))
                                        Case 230 : Control Get Text hDlg, 155 To SndMsg$
                                                   Incr iCount4&
                                                   Comm Send iPort4, "Msg4 " + Str$(iCount4&)  'Send
                                        Case 240 : Qty& = Comm(iPort4, RxQue)         'check que to see how many bytes are available
                                                   Comm Recv iPort4, Qty&, RcvMsg$   'get that many bytes
                                                   Control Set Text hDlg, 156, RcvMsg$
                                        Case 250 : Comm Close iPort4 
                                     End Select
                               End Select
                            End Function
                            
                            Function OpenPort(cPort$) As Long
                                  Local iFree As Long
                                  iFree = FreeFile : Comm Open cPort$ As iFree
                                  If ErrClear Then Function = 0 Else Function = iFree
                            End Function
                            
                            Function SetConfiguration(sPort&, iBaud&, iByte&, iParity&, iStop&, iTxBuf&, iRxBuf&) As Long
                               Comm Set sPort&, Baud     = iBaud&
                               Comm Set sPort&, Byte     = iByte&
                               Comm Set sPort&, Parity   = iParity&
                               Comm Set sPort&, Stop     = iStop&
                               Comm Set sPort&, TxBuffer = iTxBuf&
                               Comm Set sPort&, RxBuffer = iRxBuf&
                            End Function
                            
                            Function GetConfiguration(sPort&) As String
                                  Local i&, j&, k&, L&
                                  i& = Comm(sPort&,Baud)
                                  j& = Comm(sPort&,Byte)
                                  k& = Comm(sPort&,Parity)
                                  L& = Comm(sPort&,Stop)
                                  Function = Str$(i&) + "," + Str$(j&) + "," + Str$(k&) + "," + Str$(L&)
                            End Function

                            Comment


                            • #15
                              Eltima makes a fine product that I have been tempted to buy a few times. It has a closer emulation of real comm ports than others I have found - just a bit pricey though ( I'd be keen to hear of any free products you find )

                              Eltima do emulate a pair physical serial ports well but at that price you can own a couple of USB to Serial adapters.. You'll need at least one (real port) anyway if you have a real world need for serial data comms.

                              GPS Gate is less expensive and offers other additional features that I often find useful. You can have multiple inputs (multiplexed) and outputs feeding several virtual com ports at the same time, as well as mixed Serial / TCP connections.

                              A lot of the stuff I do is related to NMEA (marine navigation equipment communications protocol) and GPS Gate's origins are in that sphere too so it's built-in NMEA data simulation gets a tick from me too.
                              Rgds, Dave

                              Comment


                              • #16
                                Virtual Machines

                                Hey guys,

                                Thought I'd throw in a suggestion even though this seems to be solved. I was in a similar situation a while back and ended up using VMware to emulate two machines WITH serial ports. VMware Server is FREE now so that may be an interesting path.
                                Start as you mean to go on.

                                Comment


                                • #17
                                  I "Googled" for "Buy serial card for Windows computer."

                                  Looks like you can get a one-port card for fifteen bucks with free shipping, and a two port card for thirty-five.

                                  And that's only what I picked off the first screen returned.
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Yep, I found about the same thing at a local Frye's. A very inexpensive way to go.

                                    Plus, as someone noted, you can't test the real hardware inputs without a physical port. Hardware always seems to throw in a surprise that a software emulation doesn't anticipate.

                                    Today is my birthday. Perhaps I'll tell my wife I'm in need of shopping trip!

                                    Comment


                                    • #19
                                      > Today is my birthday. Perhaps I'll tell my wife I'm in need of shopping trip!

                                      To make it a REAL present, she'll have to install it for you, too!

                                      [MORE WHINING]
                                      > you can't test the real hardware inputs without a physical port

                                      You bet. How on earth can anyone say they are developing a serial communications application and then not test it with .. yes, a SERIAL PORT ????!!!!
                                      [/MORE WHINING]
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Birthday

                                        Hey Gary,

                                        Happy birthday from Canada
                                        Old QB45 Programmer

                                        Comment

                                        Working...
                                        X