The problem of creating serial ports in C ++(Read 81 times)
The problem of creating serial ports in C ++ on: February 06, 2019, 12:31:40 PM
The problem of creating serial ports in C ++

vspdctl.dll  8.0.412.0
sample used - eltima.com/wiki/user-guides/vspd/c.html
soft CodeLite 12.00 - codelite.org

 program code:

*********************************
// Demo vspdctl.dll  8.0.412.0

#include <stdio.h>
#include <stdbool.h>
#include <windows.h>
#include <tchar.h>

typedef bool (_stdcall *MyCreatePairFn)(char *Port1, char *Port2);

bool MyCreateVSPair(char *Port1, char *Port2)
{
  OSVERSIONINFO VersionInfo;
 
  HINSTANCE  libInst = LoadLibrary("C:\\WINDOWS\\system32\\vspdctl.dll");
   if (!libInst)
  {
    printf(" load library vspdctl.dll - NO\n");
    return false; /* Couldn't load library */   
  }
    printf(" load library vspdctl.dll - YES\n");

    MyCreatePairFn  MyCreatePair = (MyCreatePairFn)GetProcAddress(libInst, "CreatePair");

   if (!MyCreatePair)   
 {
    printf(" load CreatePair - NO\n\n");
    return false; /* Couldn't load library */
   
 }
 else
 {
    printf(" load CreatePair - YES\n\n");
    bool returnvalue = MyCreatePair(Port1, Port2); /* For example, Port1 = COM5 and Port2 = COM6 */
    FreeLibrary(libInst);
    return returnvalue;
 }
};

int main(int argc, char **argv)
{
     printf(" Start\n\n");

   if  (MyCreateVSPair("COM2","COM3") )
     {
       printf("  Create - YES\n\n");
     }
     else
     {
       printf("  Create - NO\n\n");
     }
 
   printf(" Stop\n\n");
   return 0;
}
**********************************

terminal result

 Start

 load library vspdctl.dll - YES
 load CreatePair - YES

  Create - NO //ports not created

 Stop

**********************************


In a programme Configure Virtual Serial Port Driver ports created

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\VSBC8\Ports\COM2COM3]
"StrictBaudrate"=dword:00000000
"Port1"="COM2"
"Port2"="COM3"
"UserSession"=""



Re: The problem of creating serial ports in C ++ Reply #1 on: February 07, 2019, 06:51:40 PM
DELPHI XE 10.2.3
Demo Virtual Serial Port Driver 9.0

The problem of creating serial ports in DELPHI XE 10.2.3
Demo Virtual Serial Port Driver 9.0

 type
TCreatePair = Function (Port1, Port2 : PWideChar) : Boolean; stdcall;
TDeleteAll = Function  : Boolean; stdcall;

Function CreatePairFn(PortName1, PortName2 : String) : Boolean;
Var Handle : THandle;
CreatePair : TCreatePair;
Begin
 CreatePairFn := False;
 Handle := LoadLibrary('c:\Program Files\Eltima Software\Virtual Serial Port Driver 9.0\VSPDCTL.DLL');
  If (Handle = 0) Then   Form1.Memo1.Lines.Add('no VSPDCTL.DLL ');
  If (Handle <> 0) Then
  Begin
   Form1.Memo1.Lines.Add('yes VSPDCTL.DLL ');
   @CreatePair:=GetProcAddress(Handle,'CreatePair');

  if not (@CreatePair <> Nil) Then  Form1.Memo1.Lines.Add('no CreatePair ');
  if not (@CreatePair = nil) Then
 // if Assigned(CreatePair) Then
   Begin
    CreatePairFn := CreatePair(PWideChar(PortName1), PWideChar(PortName2));
     Form1.Memo1.Lines.Add('yes CreatePair ');
  End;
    FreeLibrary(Handle);
  End;
End;


 Function DeleteAllFn : Boolean;
Var Handle : THandle;
DeleteAll : TDeleteAll;
Begin
 DeleteAllFn := False;
 Handle := LoadLibrary('c:\Program Files\Eltima Software\Virtual Serial Port Driver 9.0\VSPDCTL.DLL');
  If (Handle = 0) Then  Form1.Memo1.Lines.Add('no VSPDCTL.DLL ');

  If (Handle <> 0) Then
  Begin
   Form1.Memo1.Lines.Add('yes VSPDCTL.DLL ');
   @DeleteAll:=GetProcAddress(Handle, 'DeleteAll');

   if not (@DeleteAll <> Nil) Then  Form1.Memo1.Lines.Add('no DeleteAll ');
  If (@DeleteAll <> Nil) Then
    Begin
    DeleteAllFn := DeleteAll;
    Form1.Memo1.Lines.Add('yes DeleteAll ');
    End;
    FreeLibrary(Handle);
  End;
End;

1) function CreatePairFn('COM2','COM3')  result  False
Similar problem С++ and Delphi  in function CreatePair parameters port name ('COM2','COM3')

2) In a programme Virtual Serial Port Driver 9.0  ports 'COM2','COM3' created
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSBC9\Ports\COM2COM3]
   "StrictBaudrate"=dword:00000000
   "Port1"="COM2"
   "Port2"="COM3"
   "UserSession"=""
   "COM-Name-Arbiter1"=dword:00000001
   "COM-Name-Arbiter2"=dword:00000001

3) function DeleteAllFn result True
function without parameters is executed positively



Re: The problem of creating serial ports in C ++ Reply #2 on: February 12, 2019, 03:52:13 PM
Hello,

Thank you for reaching us. First of all, I would recommend testing our example without a change since everything should be working correctly.

As well, as please review the following article for controlling vspdctl.dll directly:

"https://www.eltima.com/wiki/user-guides/vspd/control-directly.html" 

For more deep investigation please reach us at "mailto:support@eltima.com".

---
Best regards,
 
Borys Khokhlenko | Eltima Customer Support | http://www.eltima.com



 

Sitemap 1 2 3 4 5