Serial Port Emulation. Learn how to use
Virtual Port Emulator

Olga Weis

The method of testing and diagnosing software using virtual devices today has become widely accepted by developers of the software for communication systems. A virtual device simulates behavior of a real one at the software level, allowing a programmer to test and debug an application at the development stage.

Contents

  1. A powerful tool for serial port emulation
  2. Basic principles
  3. Using VSPD with programming languages

A powerful tool for serial ports emulation


The method of serial port emulation is widely applied in the development of the most complex communication systems, including devices with RS232 and RS485 interfaces. Currently, there is a wide range of software tools that allow creating multiple virtual serial ports in operating systems (prevalently Windows OS). With the help of additional virtual COM ports, developers can test data exchange between RS232 and RS485 interfaces. When it comes to advanced functionality and ease of use, Virtual Serial Port Driver (VSPD) developed by Eltima Software seems to be the most powerful program available today. The solution is fully compatible with various versions of Windows OS. Above that, the serial port emulator for Windows 10 is digitally signed with WHQL which guarantees its performance and stability.

Let’s now take a closer look at the basic principles of serial port emulation


1. A major advantage of virtual serial interfaces is that they can be used for testing and debugging software when there is not a physical COM port available in the system.

For instance, to fully debug a serial communication program, at least two physical serial ports are required. Since most modern PCs are equipped with a single COM port, a programmer might need two computers or an additional PCI expansion card with a serial port to debug an application. Alternatively, a developer can resort to help of an efficient serial port emulator, Virtual Serial Port Driver, that is able to create several virtual serial ports on the same machine. It’s also worth mentioning that the development of communication applications isn’t the only area where the concept of virtual ports is widely used. Virtual serial port emulator 64 bit is considered particularly helpful in testing applications of many other kinds.

2. Thanks to a serial port simulator it’s possible to exchange data between two or more applications without using the complex software technology of interprocess communication and resource sharing. That way, to provide data exchange, a programmer relies on virtual COM ports rather than physical ones, so the speed of data transfer between applications is determined by the parameters of the system (the processor type, the amount of available physical memory, etc.) and not by the characteristics of a serial port. As a rule, the speed of data transfer via virtual COM ports is higher compared to data transmission via real serial ports.

3. The software connects virtual serial ports with a virtual null-modem cable, so that the COM ports can be used to communicate data between different applications over RS232 interface. Configured for this purpose, virtual ports do not use the default settings of the data transfer speed.

Using VSPD with programming languages


The virtual serial ports emulator supports standard functions for working with files and devices (CreatePair, DeletePair, SetStrictBaudrate and others). Here are the main programming languages and examples of using the software functions with them:

★ VSPD with C/C++


To use virtual port emulator functionality in C and C++, it’s necessary to dynamically load the DLL file, select the required function(s), and call them. Here’s an example of how you can do this in Visual C++:

typedef bool (stdcall *CreatePairFn)(char *Port1, char *Port2);
typedef bool (stdcall *DeletePairFn)(char *Port);
typedef bool (stdcall *DeleteAllFn)(void);
typedef bool (stdcall *SetStrictBaudrateFn) (char *Port, bool StrictBaudrate);
typedef bool (stdcall *SetBreakFn) (char *Port, bool bBreak);
typedef bool (stdcall *QueryBusFn) (void* InBuffer, long sizeInBuffer, void* OutBuffer, long sizeOutBuffer);
typedef bool (stdcall *SetWiringFn) (char *Port, void *Buffer, long sizeBuffer);
typedef bool (stdcall *SetAccessListFn) (char *Port, void *Buffer, long sizeBuffer);
 
typedef bool (stdcall *CreatePairExFn)(char *Port1, char *Port2, char * UserSession);
typedef bool (stdcall *CreatePairWFn)(WCHAR *Port1, WCHAR *Port2);
typedef bool (stdcall *CreatePairExWFn)(WCHAR *Port1, WCHAR *Port2, WCHAR * UserSession);
typedef bool (stdcall *DeletePairWFn)(WCHAR *Port);
typedef bool (stdcall *SetStrictBaudrateWFn) (WCHAR *Port, bool StrictBaudrate);
typedef bool (stdcall *SetBreakWFn) (WCHAR *Port, bool bBreak);
typedef bool (stdcall *SetWiringWFn) (WCHAR *Port, void *Buffer, long sizeBuffer);
typedef bool (stdcall *SetAccessListWFn) (WCHAR *Port, void *Buffer, long sizeBuffer);
typedef bool (stdcall *DeletePairExFn)(char *Port, char * UserSession);
typedef bool (stdcall *DeletePairExWFn)(WCHAR *Port, WCHAR * UserSession);
 
typedef bool (stdcall *GetUserSessionFn)(char *Session, int &iSize);
typedef bool (stdcall *GetUserSessionWFn)(WCHAR *Session, int &iSize);
 
typedef bool (stdcall *SetStrictBaudrateExWFn) (WCHAR *Port, WCHAR * UserSession, bool StrictBaudrate);
typedef bool (stdcall *SetStrictBaudrateExFn) (char *Port, char * UserSession, bool StrictBaudrate);
typedef bool (stdcall *SetBreakExWFn) (WCHAR *Port, WCHAR * UserSession, bool bBreak);
typedef bool (stdcall *SetBreakExFn) (char *Port, char * UserSession, bool bBreak);
typedef bool (stdcall *SetAccessListExWFn) (WCHAR *Port, WCHAR * WCHAR, void *Buffer, long sizeBuffer);
typedef bool (stdcall *SetAccessListExFn) (char *Port, char * WCHAR, void *Buffer, long sizeBuffer);

bool CreateVSPair(char *Port1, char *Port2) {
OSVERSIONINFO VersionInfo;
HINSTANCE libInst;
libInst = LoadLibrary(VSPDCTL.DLL);
if (!libInst)
   return false; /* Couldn't load library */
/* Substitute the typedefs above for functions other than CreatePairFn */
CreatePairFn CreatePair=(CreatePairFn)GetProcAddress(libInst, CreatePair);
if (CreatePair==0) return false; /* Couldn`t find function */
returnvalue=CreatePair(Port1, Port2); /* For example, Port1 = COM5 and Port2 = COM6 */
FreeLibrary(libInst);
return returnvalue;
};

★ VSPD with Visual Basic


VSPD functions installation is much easier for Visual Basic users. All you need to do is paste the following lines into the source file of Visual Basic:

Declare Function CreatePair Lib "VSPDCTL.DLL" (ByVal Port1$, ByVal Port2$) As Boolean
Declare Function DeletePair Lib "VSPDCTL.DLL" (ByVal Port$) As Boolean
Declare Function DeleteAll Lib "VSPDCTL.DLL" () As Boolean
Declare Function SetStrictBaudrateName Lib "VSPDCTL.DLL" (ByVal Port$, ByVal StrictBaudrate As Boolean) As Boolean
Declare Function SetStrictBaudrateHandle Lib "VSPDCTL.DLL" (ByVal Handle As Long, ByVal StrictBaudrate As Boolean) As Boolean
Declare Function CreatePair Lib "VSPDCTL.DLL" (ByVal Port1$, ByVal Port2$) As Boolean
Declare Function DeletePair Lib "VSPDCTL.DLL" (ByVal Port$) As Boolean
Declare Function DeleteAll Lib "VSPDCTL.DLL" () As Boolean
Declare Function SetStrictBaudrate Lib "VSPDCTL.DLL" (ByVal Port$, ByVal StrictBaudrate As Boolean) As Boolean
Declare Function SetBreak Lib "VSPDCTL.DLL" (ByVal Port$, ByVal bBreak As Boolean) As Boolean
Declare Function QueryBus Lib "VSPDCTL.DLL" (ByVal InBuffer As String, sizeInBuffer As Long, ByVal OutBuffer As String, sizeOutBuffer As Long) As Boolean
Declare Function SetWiring Lib "VSPDCTL.DLL" (ByVal Port1$, ByVal Buffer As String, sizeBuffer As Long) As Boolean

Put VSPDCTL.DLL in your program`s directory. Now the function can be called directly.

★ VSPD with Delphi


Here are the function declarations for Delphi:

Function CreatePair(Port1, Port2 : PChar) : Boolean; stdcall; external "VSPDCTL.DLL";
Function DeletePair(Port : PChar) : Boolean; stdcall; external "VSPDCTL.DLL";
Function DeleteAll : Boolean; stdcall; external "VSPDCTL.DLL";
Function SetStrictBaudrateName(Port: PChar, StrictBaudrate: Boolean) : Boolean; stdcall; external "VSPDCTL.DLL";
Function SetStrictBaudrateHandle(hPort: THandle, StrictBaudrate: Boolean) : Boolean; stdcall; external "VSPDCTL.DLL";
Function CreatePair(Port1, Port2 : PChar) : Boolean; stdcall; external "VSPDCTL.DLL";
Function DeletePair(Port : PChar) : Boolean; stdcall; external "VSPDCTL.DLL";
Function DeleteAll : Boolean; stdcall; external "VSPDCTL.DLL";
Function SetStrictBaudrate(Port: PChar, StrictBaudrate: Boolean) : Boolean; stdcall; external "VSPDCTL.DLL";
Function SetBreak (Port: PChar, bBreak: Boolean) : Boolean; stdcall; external "VSPDCTL.DLL";
Function QueryBus (InBuffer: Pointer, sizeInBuffer: Integer, OutBuffer: Pointer, sizeOutBuffer: Integer) : Boolean; stdcall; external "VSPDCTL.DLL";
Function SetWiring (Port: PChar Buffer: Pointer, sizeBuffer: Integer) : Boolean; stdcall; external "VSPDCTL.DLL";

Delphi can load ArmAccess either dynamically or statically. Here is a sample code for dynamic loading:

Function CreatePairFn(PortName1, PortName2 : String) : Boolean;
Type TCreatePair = function(Port1, Port2 : PChar) : Boolean; stdcall;
Var Handle : THandle;
CreatePair : TCreatePair;
Begin
 CreatePairFn := False;
 Handle := LoadLibrary("VSPDCTL.DLL");
 If (Handle <> 0) Then
  Begin
   @CreatePair:=GetProcAddress(Handle, "CreatePair");
   If (CreatePair <> Nil) Then
    CreatePairFn := CreatePair(PChar(PortName1), PChar(PortName2));
    FreeLibrary(Handle);
  End;
End;
/ / / Serial Port Emulation. Learn how to use Virtual Port Emulator

Virtual Serial Port Driver

Requires: Available on Windows , 5.46MB size
Version 9.0.567 (5th Aug, 2017) Release notes
Category: Serial Port Software