Submit your email address to get a link for quick download on your desktop and get started!
Virtual serial ports are essential when legacy software programs need to connect to COM port devices that cannot be connected to the computer with the software due to a lack of physical serial ports. The device can also send serial data to the app over the Internet or LAN over TCP/IP connection no matter how remote they are from each other.
In this article, you’ll find a brief virtual serial port emulator tutorial that will tell you how to create virtual serial interfaces in your computer with the help of a simple but yet efficient virtual port driver software. And I hope that the information provided in this article will put you ahead of the more traditional forms of serial app testing and debugging.
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.
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).
The Windows operating system is a prime target for applications due to its tremendous popularity. Windows RS232 programming deals with the COM ports of the operating system through which all data flows in and out of the computer. Many languages can be used, but C is one of the main languages used for this type of programming. You will be called upon to use the WIN32 API and depending on your application may need to delve into the TAPI Windows telephony interface.
Linux is another very popular operating system with many variations in specific implementations. Your serial ports are named differently in Linux, with names such as /dev/ttys0 and /dev/ttyUSB0, so right away there are differences in how you approach Linux serial programming. C again is a popular language choice for serial programming and you will be interacting with devices that Linux treats as files. You will be using an API such as termios to communicate between your application and the serial ports.
The specialized nature of serial port programming may be outside the scope of your team’s expertise, and problems in communication between your application and its intended target devices can lead to a crippling delay in your development project. Problems such as unexpectedly corrupted text or connectivity issues can be hard to diagnose for programmers without extensive serial port experience.
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 Emulator 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.
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++:
You can also see a great example of how to program a virtual COM port using Visual Basic and Visual C ++ for communication between AVR and PC using Virtual Serial Port Driver.
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);
Code example:
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 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.
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;
Virtual Serial Port Driver demonstrates the depth of knowledge and technical ability of Eltima’s programmers. Take look at some of the features and functions the team has brought to these applications, and think of what they can do for your project.
This software application allows you to create virtual pairs of serial ports and transfer data over virtual null modems. Virtual ports appear to your system just as if they were physical ports, and the program allows for easy configuration of your virtual ports.
The specialists at Eltima Software can help with any of your Windows or Linux serial port programming needs. We are skilled in many programming languages and OS platforms and can work with you to seamlessly integrate your application and the external devices it needs to access. Eltima Port Virtualization Technology can be integrated to the projects of any size. If you need some problem procedures streamlined or want full scale project management and application development, Eltima Software has the skills you need to get your project up and running. Get in touch with them today and find out how they can help solve your serial programming issues and keep your project on schedule.